@@ -9,17 +9,14 @@ import { ErrorUtils } from '../errors/errorUtils';
99import { ModuleNotInstalledError } from '../errors/moduleNotInstalledError' ;
1010import { IFileSystem } from '../platform/types' ;
1111import { IConfigurationService } from '../types' ;
12- import { EnvironmentVariables } from '../variables/types' ;
1312import { ExecutionResult , IProcessService , IPythonExecutionService , ObservableExecutionResult , SpawnOptions } from './types' ;
1413
1514@injectable ( )
1615export class PythonExecutionService implements IPythonExecutionService {
17- private readonly procService : IProcessService ;
1816 private readonly configService : IConfigurationService ;
1917 private readonly fileSystem : IFileSystem ;
2018
21- constructor ( private serviceContainer : IServiceContainer , private envVars : EnvironmentVariables | undefined , private resource ?: Uri ) {
22- this . procService = serviceContainer . get < IProcessService > ( IProcessService ) ;
19+ constructor ( private serviceContainer : IServiceContainer , private readonly procService : IProcessService , private resource ?: Uri ) {
2320 this . configService = serviceContainer . get < IConfigurationService > ( IConfigurationService ) ;
2421 this . fileSystem = serviceContainer . get < IFileSystem > ( IFileSystem ) ;
2522 }
@@ -34,40 +31,28 @@ export class PythonExecutionService implements IPythonExecutionService {
3431 if ( await this . fileSystem . fileExistsAsync ( this . pythonPath ) ) {
3532 return this . pythonPath ;
3633 }
37- return this . procService . exec ( this . pythonPath , [ '-c' , 'import sys;print(sys.executable)' ] , { env : this . envVars , throwOnStdErr : true } )
34+ return this . procService . exec ( this . pythonPath , [ '-c' , 'import sys;print(sys.executable)' ] , { throwOnStdErr : true } )
3835 . then ( output => output . stdout . trim ( ) ) ;
3936 }
4037 public async isModuleInstalled ( moduleName : string ) : Promise < boolean > {
41- return this . procService . exec ( this . pythonPath , [ '-c' , `import ${ moduleName } ` ] , { env : this . envVars , throwOnStdErr : true } )
38+ return this . procService . exec ( this . pythonPath , [ '-c' , `import ${ moduleName } ` ] , { throwOnStdErr : true } )
4239 . then ( ( ) => true ) . catch ( ( ) => false ) ;
4340 }
4441
4542 public execObservable ( args : string [ ] , options : SpawnOptions ) : ObservableExecutionResult < string > {
4643 const opts : SpawnOptions = { ...options } ;
47- if ( this . envVars ) {
48- opts . env = this . envVars ;
49- }
5044 return this . procService . execObservable ( this . pythonPath , args , opts ) ;
5145 }
5246 public execModuleObservable ( moduleName : string , args : string [ ] , options : SpawnOptions ) : ObservableExecutionResult < string > {
5347 const opts : SpawnOptions = { ...options } ;
54- if ( this . envVars ) {
55- opts . env = this . envVars ;
56- }
5748 return this . procService . execObservable ( this . pythonPath , [ '-m' , moduleName , ...args ] , opts ) ;
5849 }
5950 public async exec ( args : string [ ] , options : SpawnOptions ) : Promise < ExecutionResult < string > > {
6051 const opts : SpawnOptions = { ...options } ;
61- if ( this . envVars ) {
62- opts . env = this . envVars ;
63- }
6452 return this . procService . exec ( this . pythonPath , args , opts ) ;
6553 }
6654 public async execModule ( moduleName : string , args : string [ ] , options : SpawnOptions ) : Promise < ExecutionResult < string > > {
6755 const opts : SpawnOptions = { ...options } ;
68- if ( this . envVars ) {
69- opts . env = this . envVars ;
70- }
7156 const result = await this . procService . exec ( this . pythonPath , [ '-m' , moduleName , ...args ] , opts ) ;
7257
7358 // If a module is not installed we'll have something in stderr.
0 commit comments