@@ -22,6 +22,7 @@ import {
2222import { CondaStrings } from '../../common/localize' ;
2323import { traceError } from '../../common/logging' ;
2424import { createDeferred , Deferred } from '../../common/utils/deferred' ;
25+ import { normalizePath } from '../../common/utils/pathUtils' ;
2526import { showErrorMessage , withProgress } from '../../common/window.apis' ;
2627import { NativePythonFinder } from '../common/nativePythonFinder' ;
2728import { CondaSourcingStatus } from './condaSourcingUtils' ;
@@ -261,13 +262,13 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
261262 async get ( scope : GetEnvironmentScope ) : Promise < PythonEnvironment | undefined > {
262263 await this . initialize ( ) ;
263264 if ( scope instanceof Uri ) {
264- let env = this . fsPathToEnv . get ( scope . fsPath ) ;
265+ let env = this . fsPathToEnv . get ( normalizePath ( scope . fsPath ) ) ;
265266 if ( env ) {
266267 return env ;
267268 }
268269 const project = this . api . getPythonProject ( scope ) ;
269270 if ( project ) {
270- env = this . fsPathToEnv . get ( project . uri . fsPath ) ;
271+ env = this . fsPathToEnv . get ( normalizePath ( project . uri . fsPath ) ) ;
271272 if ( env ) {
272273 return env ;
273274 }
@@ -288,10 +289,11 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
288289 const folder = this . api . getPythonProject ( scope ) ;
289290 const fsPath = folder ?. uri ?. fsPath ?? scope . fsPath ;
290291 if ( fsPath ) {
292+ const normalizedFsPath = normalizePath ( fsPath ) ;
291293 if ( checkedEnv ) {
292- this . fsPathToEnv . set ( fsPath , checkedEnv ) ;
294+ this . fsPathToEnv . set ( normalizedFsPath , checkedEnv ) ;
293295 } else {
294- this . fsPathToEnv . delete ( fsPath ) ;
296+ this . fsPathToEnv . delete ( normalizedFsPath ) ;
295297 }
296298 await setCondaForWorkspace ( fsPath , checkedEnv ?. environmentPath . fsPath ) ;
297299 }
@@ -307,11 +309,12 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
307309
308310 const before : Map < string , PythonEnvironment | undefined > = new Map ( ) ;
309311 projects . forEach ( ( p ) => {
310- before . set ( p . uri . fsPath , this . fsPathToEnv . get ( p . uri . fsPath ) ) ;
312+ const normalizedPath = normalizePath ( p . uri . fsPath ) ;
313+ before . set ( p . uri . fsPath , this . fsPathToEnv . get ( normalizedPath ) ) ;
311314 if ( checkedEnv ) {
312- this . fsPathToEnv . set ( p . uri . fsPath , checkedEnv ) ;
315+ this . fsPathToEnv . set ( normalizedPath , checkedEnv ) ;
313316 } else {
314- this . fsPathToEnv . delete ( p . uri . fsPath ) ;
317+ this . fsPathToEnv . delete ( normalizedPath ) ;
315318 }
316319 } ) ;
317320
@@ -405,7 +408,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
405408 } ) ;
406409
407410 // Try to find workspace environments
408- const paths = this . api . getPythonProjects ( ) . map ( ( p ) => p . uri . fsPath ) ;
411+ const paths = this . api . getPythonProjects ( ) . map ( ( p ) => normalizePath ( p . uri . fsPath ) ) ;
409412 for ( const p of paths ) {
410413 const env = await getCondaForWorkspace ( p ) ;
411414
@@ -436,7 +439,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
436439 // is a subfolder of one of the environments
437440 const found = pathSorted . find ( ( e ) => {
438441 const t = this . api . getPythonProject ( e . environmentPath ) ?. uri . fsPath ;
439- return t && path . normalize ( t ) === p ;
442+ return t && normalizePath ( t ) === p ;
440443 } ) ;
441444 if ( found ) {
442445 this . fsPathToEnv . set ( p , found ) ;
@@ -448,15 +451,15 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
448451
449452 private fromEnvMap ( uri : Uri ) : PythonEnvironment | undefined {
450453 // Find environment directly using the URI mapping
451- const env = this . fsPathToEnv . get ( uri . fsPath ) ;
454+ const env = this . fsPathToEnv . get ( normalizePath ( uri . fsPath ) ) ;
452455 if ( env ) {
453456 return env ;
454457 }
455458
456459 // Find environment using the Python project for the Uri
457460 const project = this . api . getPythonProject ( uri ) ;
458461 if ( project ) {
459- return this . fsPathToEnv . get ( project . uri . fsPath ) ;
462+ return this . fsPathToEnv . get ( normalizePath ( project . uri . fsPath ) ) ;
460463 }
461464
462465 return undefined ;
@@ -470,10 +473,14 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
470473 }
471474
472475 private findEnvironmentByPath ( fsPath : string ) : PythonEnvironment | undefined {
473- const normalized = path . normalize ( fsPath ) ;
476+ const normalized = normalizePath ( fsPath ) ;
474477 return this . collection . find ( ( e ) => {
475- const n = path . normalize ( e . environmentPath . fsPath ) ;
476- return n === normalized || path . dirname ( n ) === normalized || path . dirname ( path . dirname ( n ) ) === normalized ;
478+ const n = normalizePath ( e . environmentPath . fsPath ) ;
479+ return (
480+ n === normalized ||
481+ normalizePath ( path . dirname ( e . environmentPath . fsPath ) ) === normalized ||
482+ normalizePath ( path . dirname ( path . dirname ( e . environmentPath . fsPath ) ) ) === normalized
483+ ) ;
477484 } ) ;
478485 }
479486
0 commit comments