1+ import * as path from 'path' ;
12import { EventEmitter , MarkdownString , ProgressLocation , Uri } from 'vscode' ;
23import {
34 DidChangeEnvironmentEventArgs ,
@@ -49,7 +50,10 @@ export class PipenvManager implements EnvironmentManager {
4950
5051 private _initialized : Deferred < void > | undefined ;
5152
52- constructor ( public readonly nativeFinder : NativePythonFinder , public readonly api : PythonEnvironmentApi ) {
53+ constructor (
54+ public readonly nativeFinder : NativePythonFinder ,
55+ public readonly api : PythonEnvironmentApi ,
56+ ) {
5357 this . name = 'pipenv' ;
5458 this . displayName = 'Pipenv' ;
5559 this . preferredPackageManagerId = 'ms-python.python:pip' ;
@@ -93,7 +97,14 @@ export class PipenvManager implements EnvironmentManager {
9397 for ( const project of projects ) {
9498 const envPath = await getPipenvForWorkspace ( project . uri . fsPath ) ;
9599 if ( envPath ) {
96- const env = this . findEnvironmentByPath ( envPath ) ;
100+ let env = this . findEnvironmentByPath ( envPath ) ;
101+ // If not found in collection, try to resolve the path
102+ if ( ! env ) {
103+ env = await resolvePipenvPath ( envPath , this . nativeFinder , this . api , this ) ;
104+ if ( env ) {
105+ this . collection . push ( env ) ;
106+ }
107+ }
97108 if ( env ) {
98109 this . fsPathToEnv . set ( project . uri . fsPath , env ) ;
99110 }
@@ -104,13 +115,23 @@ export class PipenvManager implements EnvironmentManager {
104115 const globalEnvPath = await getPipenvForGlobal ( ) ;
105116 if ( globalEnvPath ) {
106117 this . globalEnv = this . findEnvironmentByPath ( globalEnvPath ) ;
118+ // If not found in collection, try to resolve the path
119+ if ( ! this . globalEnv ) {
120+ this . globalEnv = await resolvePipenvPath ( globalEnvPath , this . nativeFinder , this . api , this ) ;
121+ if ( this . globalEnv ) {
122+ this . collection . push ( this . globalEnv ) ;
123+ }
124+ }
107125 }
108126 }
109127
110128 private findEnvironmentByPath ( fsPath : string ) : PythonEnvironment | undefined {
111- return this . collection . find (
112- ( env ) => env . environmentPath . fsPath === fsPath || env . execInfo ?. run . executable === fsPath ,
113- ) ;
129+ const normalized = path . normalize ( fsPath ) ;
130+ return this . collection . find ( ( env ) => {
131+ const envPath = path . normalize ( env . environmentPath . fsPath ) ;
132+ const execPath = env . execInfo ?. run . executable ? path . normalize ( env . execInfo . run . executable ) : undefined ;
133+ return envPath === normalized || execPath === normalized ;
134+ } ) ;
114135 }
115136
116137 async refresh ( scope : RefreshEnvironmentsScope ) : Promise < void > {
0 commit comments