@@ -36,10 +36,11 @@ import * as path from 'path';
3636import { NativePythonFinder } from '../common/nativePythonFinder' ;
3737import { PYTHON_EXTENSION_ID } from '../../common/constants' ;
3838import { createDeferred , Deferred } from '../../common/utils/deferred' ;
39- import { getLatest , shortVersion , sortEnvironments } from '../common/utils' ;
39+ import { getLatest , isWindows , shortVersion , sortEnvironments } from '../common/utils' ;
4040import { withProgress } from '../../common/window.apis' ;
4141import { VenvManagerStrings } from '../../common/localize' ;
4242import { showErrorMessage } from '../../common/errors/utils' ;
43+ import { normalizePath } from '../../common/utils/pathUtils' ;
4344
4445export class VenvManager implements EnvironmentManager {
4546 private collection : PythonEnvironment [ ] = [ ] ;
@@ -201,12 +202,21 @@ export class VenvManager implements EnvironmentManager {
201202 const changed : Uri [ ] = [ ] ;
202203 this . fsPathToEnv . forEach ( ( env , uri ) => {
203204 if ( env . environmentPath . fsPath === environment . environmentPath . fsPath ) {
204- this . fsPathToEnv . delete ( uri ) ;
205+ this . deleteFsPathToEnv ( uri ) ;
205206 changed . push ( Uri . file ( uri ) ) ;
206207 }
207208 } ) ;
208209 return changed ;
209210 }
211+ private setFsPathToEnv ( fsPath : string , environment : PythonEnvironment ) : void {
212+ this . fsPathToEnv . set ( isWindows ( ) ? normalizePath ( fsPath ) : fsPath , environment ) ;
213+ }
214+ private getFsPathToEnv ( fsPath : string ) : PythonEnvironment | undefined {
215+ return this . fsPathToEnv . get ( isWindows ( ) ? normalizePath ( fsPath ) : fsPath ) ;
216+ }
217+ private deleteFsPathToEnv ( fsPath : string ) : void {
218+ this . fsPathToEnv . delete ( isWindows ( ) ? normalizePath ( fsPath ) : fsPath ) ;
219+ }
210220
211221 async refresh ( scope : RefreshEnvironmentsScope ) : Promise < void > {
212222 return this . internalRefresh ( scope , true , VenvManagerStrings . venvRefreshing ) ;
@@ -262,7 +272,7 @@ export class VenvManager implements EnvironmentManager {
262272 return [ ] ;
263273 }
264274
265- const env = this . fsPathToEnv . get ( scope . fsPath ) ;
275+ const env = this . getFsPathToEnv ( scope . fsPath ) ;
266276 return env ? [ env ] : [ ] ;
267277 }
268278
@@ -279,7 +289,7 @@ export class VenvManager implements EnvironmentManager {
279289 return this . globalEnv ;
280290 }
281291
282- let env = this . fsPathToEnv . get ( project . uri . fsPath ) ;
292+ let env = this . getFsPathToEnv ( project . uri . fsPath ) ;
283293 if ( ! env ) {
284294 env = this . findEnvironmentByPath ( project . uri . fsPath ) ;
285295 }
@@ -305,11 +315,11 @@ export class VenvManager implements EnvironmentManager {
305315 return ;
306316 }
307317
308- const before = this . fsPathToEnv . get ( pw . uri . fsPath ) ;
318+ const before = this . getFsPathToEnv ( pw . uri . fsPath ) ;
309319 if ( environment ) {
310- this . fsPathToEnv . set ( pw . uri . fsPath , environment ) ;
320+ this . setFsPathToEnv ( pw . uri . fsPath , environment ) ;
311321 } else {
312- this . fsPathToEnv . delete ( pw . uri . fsPath ) ;
322+ this . deleteFsPathToEnv ( pw . uri . fsPath ) ;
313323 }
314324 await setVenvForWorkspace ( pw . uri . fsPath , environment ?. environmentPath . fsPath ) ;
315325
@@ -330,11 +340,11 @@ export class VenvManager implements EnvironmentManager {
330340
331341 const before : Map < string , PythonEnvironment | undefined > = new Map ( ) ;
332342 projects . forEach ( ( p ) => {
333- before . set ( p . uri . fsPath , this . fsPathToEnv . get ( p . uri . fsPath ) ) ;
343+ before . set ( p . uri . fsPath , this . getFsPathToEnv ( p . uri . fsPath ) ) ;
334344 if ( environment ) {
335- this . fsPathToEnv . set ( p . uri . fsPath , environment ) ;
345+ this . setFsPathToEnv ( p . uri . fsPath , environment ) ;
336346 } else {
337- this . fsPathToEnv . delete ( p . uri . fsPath ) ;
347+ this . deleteFsPathToEnv ( p . uri . fsPath ) ;
338348 }
339349 } ) ;
340350
@@ -464,10 +474,10 @@ export class VenvManager implements EnvironmentManager {
464474
465475 if ( env ) {
466476 const found = this . findEnvironmentByPath ( env , sorted ) ?? this . findEnvironmentByPath ( env , globals ) ;
467- const previous = this . fsPathToEnv . get ( p ) ;
477+ const previous = this . getFsPathToEnv ( p ) ;
468478 const pw = this . api . getPythonProject ( Uri . file ( p ) ) ;
469479 if ( found ) {
470- this . fsPathToEnv . set ( p , found ) ;
480+ this . setFsPathToEnv ( p , found ) ;
471481 if ( pw && previous ?. envId . id !== found . envId . id ) {
472482 events . push ( ( ) =>
473483 this . _onDidChangeEnvironment . fire ( { uri : pw . uri , old : undefined , new : found } ) ,
@@ -483,7 +493,7 @@ export class VenvManager implements EnvironmentManager {
483493 ) ;
484494 if ( resolved ) {
485495 // If resolved add it to the collection
486- this . fsPathToEnv . set ( p , resolved ) ;
496+ this . setFsPathToEnv ( p , resolved ) ;
487497 this . addEnvironment ( resolved , false ) ;
488498 if ( pw && previous ?. envId . id !== resolved . envId . id ) {
489499 events . push ( ( ) =>
@@ -497,7 +507,7 @@ export class VenvManager implements EnvironmentManager {
497507 } else {
498508 // There is NO selected venv, then try and choose the venv that is in the workspace.
499509 if ( sorted . length === 1 ) {
500- this . fsPathToEnv . set ( p , sorted [ 0 ] ) ;
510+ this . setFsPathToEnv ( p , sorted [ 0 ] ) ;
501511 } else {
502512 // These are sorted by version and by path length. The assumption is that the user would want to pick
503513 // latest version and the one that is closest to the workspace.
@@ -506,7 +516,7 @@ export class VenvManager implements EnvironmentManager {
506516 return t && path . normalize ( t ) === p ;
507517 } ) ;
508518 if ( found ) {
509- this . fsPathToEnv . set ( p , found ) ;
519+ this . setFsPathToEnv ( p , found ) ;
510520 }
511521 }
512522 }
0 commit comments