@@ -25,24 +25,21 @@ async function getPipRequirementsFiles(
2525 return files ;
2626}
2727
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 ) ;
3937 }
40- } catch ( err ) {
41- traceError ( 'Failed to parse `pyproject.toml`:' , err ) ;
4238 }
43- return extras ;
39+ } catch ( err ) {
40+ traceError ( 'Failed to parse `pyproject.toml`:' , err ) ;
4441 }
45- return undefined ;
42+ return extras ;
4643}
4744
4845async function pickTomlExtras ( extras : string [ ] , token ?: CancellationToken ) : Promise < string [ ] | undefined > {
@@ -109,9 +106,18 @@ export async function pickPackagesToInstall(
109106) : Promise < IPackageInstallSelection | undefined > {
110107 const tomlPath = path . join ( workspaceFolder . uri . fsPath , 'pyproject.toml' ) ;
111108 traceVerbose ( `Looking for toml pyproject.toml with optional dependencies at: ${ tomlPath } ` ) ;
112- const extras = await getTomlOptionalDeps ( tomlPath ) ;
113109
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+ }
115121 traceVerbose ( 'Found toml with optional dependencies.' ) ;
116122 const installList = await pickTomlExtras ( extras , token ) ;
117123 if ( installList ) {
0 commit comments