@@ -25,24 +25,21 @@ async function getPipRequirementsFiles(
25
25
return files ;
26
26
}
27
27
28
- async function getTomlOptionalDeps ( tomlPath : string ) : Promise < string [ ] | undefined > {
29
- if ( await fs . pathExists ( tomlPath ) ) {
30
- const content = await fs . readFile ( tomlPath , 'utf-8' ) ;
31
- const extras : string [ ] = [ ] ;
32
- try {
33
- const toml = tomljs . parse ( content ) ;
34
- if ( toml . project && ( toml . project as Record < string , Array < string > > ) [ 'optional-dependencies' ] ) {
35
- const deps = ( toml . project as Record < string , Record < string , Array < string > > > ) [ 'optional-dependencies' ] ;
36
- for ( const key of Object . keys ( deps ) ) {
37
- extras . push ( key ) ;
38
- }
28
+ async function getTomlOptionalDeps ( tomlPath : string ) : Promise < string [ ] > {
29
+ const content = await fs . readFile ( tomlPath , 'utf-8' ) ;
30
+ const extras : string [ ] = [ ] ;
31
+ try {
32
+ const toml = tomljs . parse ( content ) ;
33
+ if ( toml . project && ( toml . project as Record < string , Array < string > > ) [ 'optional-dependencies' ] ) {
34
+ const deps = ( toml . project as Record < string , Record < string , Array < string > > > ) [ 'optional-dependencies' ] ;
35
+ for ( const key of Object . keys ( deps ) ) {
36
+ extras . push ( key ) ;
39
37
}
40
- } catch ( err ) {
41
- traceError ( 'Failed to parse `pyproject.toml`:' , err ) ;
42
38
}
43
- return extras ;
39
+ } catch ( err ) {
40
+ traceError ( 'Failed to parse `pyproject.toml`:' , err ) ;
44
41
}
45
- return undefined ;
42
+ return extras ;
46
43
}
47
44
48
45
async function pickTomlExtras ( extras : string [ ] , token ?: CancellationToken ) : Promise < string [ ] | undefined > {
@@ -109,9 +106,18 @@ export async function pickPackagesToInstall(
109
106
) : Promise < IPackageInstallSelection | undefined > {
110
107
const tomlPath = path . join ( workspaceFolder . uri . fsPath , 'pyproject.toml' ) ;
111
108
traceVerbose ( `Looking for toml pyproject.toml with optional dependencies at: ${ tomlPath } ` ) ;
112
- const extras = await getTomlOptionalDeps ( tomlPath ) ;
113
109
114
- if ( extras && extras . length > 0 ) {
110
+ let extras : string [ ] = [ ] ;
111
+ let tomlExists = false ;
112
+ if ( await fs . pathExists ( tomlPath ) ) {
113
+ tomlExists = true ;
114
+ extras = await getTomlOptionalDeps ( tomlPath ) ;
115
+ }
116
+
117
+ if ( tomlExists ) {
118
+ if ( extras . length === 0 ) {
119
+ return { installType : 'toml' , installList : [ ] , source : tomlPath } ;
120
+ }
115
121
traceVerbose ( 'Found toml with optional dependencies.' ) ;
116
122
const installList = await pickTomlExtras ( extras , token ) ;
117
123
if ( installList ) {
0 commit comments