@@ -38,6 +38,8 @@ import { createDeferred, Deferred } from '../../common/utils/deferred';
3838import { withProgress } from '../../common/window.apis' ;
3939import { CondaStrings } from '../../common/localize' ;
4040import { showErrorMessage } from '../../common/errors/utils' ;
41+ import { isWindows } from '../common/utils' ;
42+ import { normalizePath } from '../../common/utils/pathUtils' ;
4143
4244export class CondaEnvManager implements EnvironmentManager , Disposable {
4345 private collection : PythonEnvironment [ ] = [ ] ;
@@ -74,6 +76,16 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
7476 this . disposablesMap . forEach ( ( d ) => d . dispose ( ) ) ;
7577 }
7678
79+ private setFsPathToEnv ( fsPath : string , environment : PythonEnvironment ) : void {
80+ this . fsPathToEnv . set ( isWindows ( ) ? normalizePath ( fsPath ) : fsPath , environment ) ;
81+ }
82+ private getFsPathToEnv ( fsPath : string ) : PythonEnvironment | undefined {
83+ return this . fsPathToEnv . get ( isWindows ( ) ? normalizePath ( fsPath ) : fsPath ) ;
84+ }
85+ private deleteFsPathToEnv ( fsPath : string ) : void {
86+ this . fsPathToEnv . delete ( isWindows ( ) ? normalizePath ( fsPath ) : fsPath ) ;
87+ }
88+
7789 private _initialized : Deferred < void > | undefined ;
7890 async initialize ( ) : Promise < void > {
7991 if ( this . _initialized ) {
@@ -174,7 +186,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
174186 this . collection = this . collection . filter ( ( env ) => env . envId . id !== result ?. envId . id ) ;
175187 Array . from ( this . fsPathToEnv . entries ( ) )
176188 . filter ( ( [ , env ] ) => env . envId . id === result ?. envId . id )
177- . forEach ( ( [ uri ] ) => this . fsPathToEnv . delete ( uri ) ) ;
189+ . forEach ( ( [ uri ] ) => this . deleteFsPathToEnv ( uri ) ) ;
178190 this . disposablesMap . delete ( result . envId . id ) ;
179191 }
180192 } ) ,
@@ -236,13 +248,13 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
236248 async get ( scope : GetEnvironmentScope ) : Promise < PythonEnvironment | undefined > {
237249 await this . initialize ( ) ;
238250 if ( scope instanceof Uri ) {
239- let env = this . fsPathToEnv . get ( scope . fsPath ) ;
251+ let env = this . getFsPathToEnv ( scope . fsPath ) ;
240252 if ( env ) {
241253 return env ;
242254 }
243255 const project = this . api . getPythonProject ( scope ) ;
244256 if ( project ) {
245- env = this . fsPathToEnv . get ( project . uri . fsPath ) ;
257+ env = this . getFsPathToEnv ( project . uri . fsPath ) ;
246258 if ( env ) {
247259 return env ;
248260 }
@@ -260,9 +272,9 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
260272 const fsPath = folder ?. uri ?. fsPath ?? scope . fsPath ;
261273 if ( fsPath ) {
262274 if ( environment ) {
263- this . fsPathToEnv . set ( fsPath , environment ) ;
275+ this . setFsPathToEnv ( fsPath , environment ) ;
264276 } else {
265- this . fsPathToEnv . delete ( fsPath ) ;
277+ this . deleteFsPathToEnv ( fsPath ) ;
266278 }
267279 await setCondaForWorkspace ( fsPath , environment ?. environmentPath . fsPath ) ;
268280 }
@@ -278,11 +290,11 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
278290
279291 const before : Map < string , PythonEnvironment | undefined > = new Map ( ) ;
280292 projects . forEach ( ( p ) => {
281- before . set ( p . uri . fsPath , this . fsPathToEnv . get ( p . uri . fsPath ) ) ;
293+ before . set ( p . uri . fsPath , this . getFsPathToEnv ( p . uri . fsPath ) ) ;
282294 if ( environment ) {
283- this . fsPathToEnv . set ( p . uri . fsPath , environment ) ;
295+ this . setFsPathToEnv ( p . uri . fsPath , environment ) ;
284296 } else {
285- this . fsPathToEnv . delete ( p . uri . fsPath ) ;
297+ this . deleteFsPathToEnv ( p . uri . fsPath ) ;
286298 }
287299 } ) ;
288300
@@ -371,14 +383,14 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
371383 const found = this . findEnvironmentByPath ( env ) ;
372384
373385 if ( found ) {
374- this . fsPathToEnv . set ( p , found ) ;
386+ this . setFsPathToEnv ( p , found ) ;
375387 } else {
376388 // If not found, resolve the conda path. Could be portable conda.
377389 const resolved = await resolveCondaPath ( env , this . nativeFinder , this . api , this . log , this ) ;
378390
379391 if ( resolved ) {
380392 // If resolved add it to the collection
381- this . fsPathToEnv . set ( p , resolved ) ;
393+ this . setFsPathToEnv ( p , resolved ) ;
382394 this . collection . push ( resolved ) ;
383395 } else {
384396 this . log . error ( `Failed to resolve conda environment: ${ env } ` ) ;
@@ -388,7 +400,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
388400 // If there is not an environment already assigned by user to this project
389401 // then see if there is one in the collection
390402 if ( pathSorted . length === 1 ) {
391- this . fsPathToEnv . set ( p , pathSorted [ 0 ] ) ;
403+ this . setFsPathToEnv ( p , pathSorted [ 0 ] ) ;
392404 } else {
393405 // If there is more than one environment then we need to check if the project
394406 // is a subfolder of one of the environments
@@ -397,7 +409,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
397409 return t && path . normalize ( t ) === p ;
398410 } ) ;
399411 if ( found ) {
400- this . fsPathToEnv . set ( p , found ) ;
412+ this . setFsPathToEnv ( p , found ) ;
401413 }
402414 }
403415 }
@@ -406,15 +418,15 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
406418
407419 private fromEnvMap ( uri : Uri ) : PythonEnvironment | undefined {
408420 // Find environment directly using the URI mapping
409- const env = this . fsPathToEnv . get ( uri . fsPath ) ;
421+ const env = this . getFsPathToEnv ( uri . fsPath ) ;
410422 if ( env ) {
411423 return env ;
412424 }
413425
414426 // Find environment using the Python project for the Uri
415427 const project = this . api . getPythonProject ( uri ) ;
416428 if ( project ) {
417- return this . fsPathToEnv . get ( project . uri . fsPath ) ;
429+ return this . getFsPathToEnv ( project . uri . fsPath ) ;
418430 }
419431
420432 return undefined ;
0 commit comments