@@ -17,14 +17,15 @@ import {
1717 IInterpreterDisplay , IInterpreterHelper , IInterpreterLocatorService ,
1818 IInterpreterService , INTERPRETER_LOCATOR_SERVICE ,
1919 InterpreterType , PythonInterpreter } from './contracts' ;
20+ import { InterpeterHashProviderFactory } from './locators/services/hashProviderFactory' ;
21+ import { IInterpreterHashProviderFactory } from './locators/types' ;
2022import { IVirtualEnvironmentManager } from './virtualEnvs/types' ;
2123
2224const EXPITY_DURATION = 24 * 60 * 60 * 1000 ;
2325
2426@injectable ( )
2527export class InterpreterService implements Disposable , IInterpreterService {
2628 private readonly locator : IInterpreterLocatorService ;
27- private readonly fs : IFileSystem ;
2829 private readonly persistentStateFactory : IPersistentStateFactory ;
2930 private readonly configService : IConfigurationService ;
3031 private readonly didChangeInterpreterEmitter = new EventEmitter < void > ( ) ;
@@ -33,9 +34,9 @@ export class InterpreterService implements Disposable, IInterpreterService {
3334 private readonly updatedInterpreters = new Set < string > ( ) ;
3435 private pythonPathSetting : string = '' ;
3536
36- constructor ( @inject ( IServiceContainer ) private serviceContainer : IServiceContainer ) {
37+ constructor ( @inject ( IServiceContainer ) private serviceContainer : IServiceContainer ,
38+ @inject ( InterpeterHashProviderFactory ) private readonly hashProviderFactory : IInterpreterHashProviderFactory ) {
3739 this . locator = serviceContainer . get < IInterpreterLocatorService > ( IInterpreterLocatorService , INTERPRETER_LOCATOR_SERVICE ) ;
38- this . fs = this . serviceContainer . get < IFileSystem > ( IFileSystem ) ;
3940 this . persistentStateFactory = this . serviceContainer . get < IPersistentStateFactory > ( IPersistentStateFactory ) ;
4041 this . configService = this . serviceContainer . get < IConfigurationService > ( IConfigurationService ) ;
4142 }
@@ -175,7 +176,7 @@ export class InterpreterService implements Disposable, IInterpreterService {
175176 if ( ! info . cachedEntry && info . path && this . inMemoryCacheOfDisplayNames . has ( info . path ) ) {
176177 return this . inMemoryCacheOfDisplayNames . get ( info . path ) ! ;
177178 }
178- const fileHash = ( info . path ? await this . fs . getFileHash ( info . path ) . catch ( ( ) => '' ) : '' ) || '' ;
179+ const fileHash = ( info . path ? await this . getInterepreterFileHash ( info . path ) . catch ( ( ) => '' ) : '' ) || '' ;
179180 // Do not include dipslay name into hash as that changes.
180181 const interpreterHash = `${ fileHash } -${ md5 ( JSON . stringify ( { ...info , displayName : '' } ) ) } ` ;
181182 const store = this . persistentStateFactory . createGlobalPersistentState < { hash : string ; displayName : string } > ( `${ info . path } .interpreter.displayName.v7` , undefined , EXPITY_DURATION ) ;
@@ -195,13 +196,17 @@ export class InterpreterService implements Disposable, IInterpreterService {
195196 return displayName ;
196197 }
197198 public async getInterpreterCache ( pythonPath : string ) : Promise < IPersistentState < { fileHash : string ; info ?: PythonInterpreter } > > {
198- const fileHash = ( pythonPath ? await this . fs . getFileHash ( pythonPath ) . catch ( ( ) => '' ) : '' ) || '' ;
199+ const fileHash = ( pythonPath ? await this . getInterepreterFileHash ( pythonPath ) . catch ( ( ) => '' ) : '' ) || '' ;
199200 const store = this . persistentStateFactory . createGlobalPersistentState < { fileHash : string ; info ?: PythonInterpreter } > ( `${ pythonPath } .interpreter.Details.v7` , undefined , EXPITY_DURATION ) ;
200201 if ( ! store . value || store . value . fileHash !== fileHash ) {
201202 await store . updateValue ( { fileHash } ) ;
202203 }
203204 return store ;
204205 }
206+ protected async getInterepreterFileHash ( pythonPath : string ) : Promise < string > {
207+ return this . hashProviderFactory . create ( { pythonPath} )
208+ . then ( provider => provider . getInterpreterHash ( pythonPath ) ) ;
209+ }
205210 protected async updateCachedInterpreterInformation ( info : PythonInterpreter , resource : Resource ) : Promise < void > {
206211 const key = JSON . stringify ( info ) ;
207212 if ( this . updatedInterpreters . has ( key ) ) {
0 commit comments