@@ -139,14 +139,21 @@ async function resolveGloballyInstalledEnv(env: BasicEnvInfo): Promise<PythonEnv
139139 const { executablePath } = env ;
140140 let version ;
141141 try {
142- version = parseVersionFromExecutable ( executablePath ) ;
142+ version = env . version ?? parseVersionFromExecutable ( executablePath ) ;
143143 } catch {
144144 version = UNKNOWN_PYTHON_VERSION ;
145145 }
146146 const envInfo = buildEnvInfo ( {
147147 kind : env . kind ,
148+ name : env . name ,
149+ display : env . displayName ,
150+ sysPrefix : env . envPath ,
151+ location : env . envPath ,
152+ searchLocation : env . searchLocation ,
148153 version,
149154 executable : executablePath ,
155+ pythonRunCommand : env . pythonRunCommand ,
156+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
150157 } ) ;
151158 return envInfo ;
152159}
@@ -155,17 +162,59 @@ async function resolveSimpleEnv(env: BasicEnvInfo): Promise<PythonEnvInfo> {
155162 const { executablePath, kind } = env ;
156163 const envInfo = buildEnvInfo ( {
157164 kind,
158- version : await getPythonVersionFromPath ( executablePath ) ,
165+ version : env . version ?? ( await getPythonVersionFromPath ( executablePath ) ) ,
159166 executable : executablePath ,
167+ sysPrefix : env . envPath ,
168+ location : env . envPath ,
169+ display : env . displayName ,
170+ searchLocation : env . searchLocation ,
171+ pythonRunCommand : env . pythonRunCommand ,
172+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
173+ name : env . name ,
160174 type : PythonEnvType . Virtual ,
161175 } ) ;
162- const location = getEnvironmentDirFromPath ( executablePath ) ;
176+ const location = env . envPath ?? getEnvironmentDirFromPath ( executablePath ) ;
163177 envInfo . location = location ;
164178 envInfo . name = path . basename ( location ) ;
165179 return envInfo ;
166180}
167181
168182async function resolveCondaEnv ( env : BasicEnvInfo ) : Promise < PythonEnvInfo > {
183+ if ( env . identifiedUsingNativeLocator ) {
184+ // New approach using native locator.
185+ const executable = env . executablePath ;
186+ const envPath = env . envPath ?? getEnvironmentDirFromPath ( executable ) ;
187+ // TODO: Hacky, `executable` is never undefined in the typedef,
188+ // However, in reality with native locator this can be undefined.
189+ const version = env . version ?? ( executable ? await getPythonVersionFromPath ( executable ) : undefined ) ;
190+ const info = buildEnvInfo ( {
191+ executable,
192+ kind : PythonEnvKind . Conda ,
193+ org : AnacondaCompanyName ,
194+ location : envPath ,
195+ sysPrefix : envPath ,
196+ display : env . displayName ,
197+ pythonRunCommand : env . pythonRunCommand ,
198+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
199+ searchLocation : env . searchLocation ,
200+ source : [ ] ,
201+ version,
202+ type : PythonEnvType . Conda ,
203+ name : env . name ,
204+ } ) ;
205+
206+ if ( env . envPath && executable && path . basename ( executable ) === executable ) {
207+ // For environments without python, set ID using the predicted executable path after python is installed.
208+ // Another alternative could've been to set ID of all conda environments to the environment path, as that
209+ // remains constant even after python installation.
210+ const predictedExecutable = getCondaInterpreterPath ( env . envPath ) ;
211+ info . id = getEnvID ( predictedExecutable , env . envPath ) ;
212+ }
213+ return info ;
214+ }
215+
216+ // Old approach (without native locator).
217+ // In this approach we need to find conda.
169218 const { executablePath } = env ;
170219 const conda = await Conda . getConda ( ) ;
171220 if ( conda === undefined ) {
@@ -210,18 +259,26 @@ async function resolveCondaEnv(env: BasicEnvInfo): Promise<PythonEnvInfo> {
210259
211260async function resolvePyenvEnv ( env : BasicEnvInfo ) : Promise < PythonEnvInfo > {
212261 const { executablePath } = env ;
213- const location = getEnvironmentDirFromPath ( executablePath ) ;
262+ const location = env . envPath ?? getEnvironmentDirFromPath ( executablePath ) ;
214263 const name = path . basename ( location ) ;
215264
216265 // The sub-directory name sometimes can contain distro and python versions.
217266 // here we attempt to extract the texts out of the name.
218267 const versionStrings = parsePyenvVersion ( name ) ;
219268
220269 const envInfo = buildEnvInfo ( {
221- kind : PythonEnvKind . Pyenv ,
270+ // If using native resolver, then we can get the kind from the native resolver.
271+ // E.g. pyenv can have conda environments as well.
272+ kind : env . identifiedUsingNativeLocator && env . kind ? env . kind : PythonEnvKind . Pyenv ,
222273 executable : executablePath ,
223274 source : [ ] ,
224275 location,
276+ searchLocation : env . searchLocation ,
277+ sysPrefix : env . envPath ,
278+ display : env . displayName ,
279+ name : env . name ,
280+ pythonRunCommand : env . pythonRunCommand ,
281+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
225282 // Pyenv environments can fall in to these three categories:
226283 // 1. Global Installs : These are environments that are created when you install
227284 // a supported python distribution using `pyenv install <distro>` command.
@@ -240,14 +297,17 @@ async function resolvePyenvEnv(env: BasicEnvInfo): Promise<PythonEnvInfo> {
240297 //
241298 // Here we look for near by files, or config files to see if we can get python version info
242299 // without running python itself.
243- version : await getPythonVersionFromPath ( executablePath , versionStrings ?. pythonVer ) ,
300+ version : env . version ?? ( await getPythonVersionFromPath ( executablePath , versionStrings ?. pythonVer ) ) ,
244301 org : versionStrings && versionStrings . distro ? versionStrings . distro : '' ,
245302 } ) ;
246303
247- if ( await isBaseCondaPyenvEnvironment ( executablePath ) ) {
248- envInfo . name = 'base' ;
249- } else {
250- envInfo . name = name ;
304+ // Do this only for the old approach, when not using native locators.
305+ if ( ! env . identifiedUsingNativeLocator ) {
306+ if ( await isBaseCondaPyenvEnvironment ( executablePath ) ) {
307+ envInfo . name = 'base' ;
308+ } else {
309+ envInfo . name = name ;
310+ }
251311 }
252312 return envInfo ;
253313}
@@ -256,6 +316,14 @@ async function resolveActiveStateEnv(env: BasicEnvInfo): Promise<PythonEnvInfo>
256316 const info = buildEnvInfo ( {
257317 kind : env . kind ,
258318 executable : env . executablePath ,
319+ display : env . displayName ,
320+ version : env . version ,
321+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
322+ location : env . envPath ,
323+ name : env . name ,
324+ pythonRunCommand : env . pythonRunCommand ,
325+ searchLocation : env . searchLocation ,
326+ sysPrefix : env . envPath ,
259327 } ) ;
260328 const projects = await ActiveState . getState ( ) . then ( ( v ) => v ?. getProjects ( ) ) ;
261329 if ( projects ) {
@@ -285,8 +353,15 @@ async function resolveMicrosoftStoreEnv(env: BasicEnvInfo): Promise<PythonEnvInf
285353 return buildEnvInfo ( {
286354 kind : PythonEnvKind . MicrosoftStore ,
287355 executable : executablePath ,
288- version : parsePythonVersionFromPath ( executablePath ) ,
356+ version : env . version ?? parsePythonVersionFromPath ( executablePath ) ,
289357 org : 'Microsoft' ,
358+ display : env . displayName ,
359+ location : env . envPath ,
360+ sysPrefix : env . envPath ,
361+ searchLocation : env . searchLocation ,
362+ name : env . name ,
363+ pythonRunCommand : env . pythonRunCommand ,
364+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
290365 arch : Architecture . x64 ,
291366 source : [ PythonEnvSource . PathEnvVar ] ,
292367 } ) ;
0 commit comments