4
4
import * as path from 'path' ;
5
5
import { Uri } from 'vscode' ;
6
6
import { uniq } from 'lodash' ;
7
- import { PythonEnvInfo , PythonEnvKind , PythonEnvSource , UNKNOWN_PYTHON_VERSION , virtualEnvKinds } from '../../info' ;
7
+ import {
8
+ PythonEnvInfo ,
9
+ PythonEnvKind ,
10
+ PythonEnvSource ,
11
+ PythonEnvType ,
12
+ UNKNOWN_PYTHON_VERSION ,
13
+ virtualEnvKinds ,
14
+ } from '../../info' ;
8
15
import {
9
16
buildEnvInfo ,
10
17
comparePythonVersionSpecificity ,
@@ -26,6 +33,7 @@ import { getRegistryInterpreters, getRegistryInterpretersSync } from '../../../c
26
33
import { BasicEnvInfo } from '../../locator' ;
27
34
import { parseVersionFromExecutable } from '../../info/executable' ;
28
35
import { traceError , traceWarn } from '../../../../logging' ;
36
+ import { isVirtualEnvironment } from '../../../common/environmentManagers/simplevirtualenvs' ;
29
37
30
38
function getResolvers ( ) : Map < PythonEnvKind , ( env : BasicEnvInfo , useCache ?: boolean ) => Promise < PythonEnvInfo > > {
31
39
const resolvers = new Map < PythonEnvKind , ( _ : BasicEnvInfo , useCache ?: boolean ) => Promise < PythonEnvInfo > > ( ) ;
@@ -62,9 +70,26 @@ export async function resolveBasicEnv(env: BasicEnvInfo, useCache = false): Prom
62
70
const { ctime, mtime } = await getFileInfo ( resolvedEnv . executable . filename ) ;
63
71
resolvedEnv . executable . ctime = ctime ;
64
72
resolvedEnv . executable . mtime = mtime ;
73
+ const type = await getEnvType ( resolvedEnv ) ;
74
+ if ( type ) {
75
+ resolvedEnv . type = type ;
76
+ }
65
77
return resolvedEnv ;
66
78
}
67
79
80
+ async function getEnvType ( env : PythonEnvInfo ) {
81
+ if ( env . type ) {
82
+ return env . type ;
83
+ }
84
+ if ( await isVirtualEnvironment ( env . executable . filename ) ) {
85
+ return PythonEnvType . Virtual ;
86
+ }
87
+ if ( await isCondaEnvironment ( env . executable . filename ) ) {
88
+ return PythonEnvType . Conda ;
89
+ }
90
+ return undefined ;
91
+ }
92
+
68
93
function getSearchLocation ( env : PythonEnvInfo ) : Uri | undefined {
69
94
const folders = getWorkspaceFolders ( ) ;
70
95
const isRootedEnv = folders . some ( ( f ) => isParentPath ( env . executable . filename , f ) || isParentPath ( env . location , f ) ) ;
@@ -131,6 +156,7 @@ async function resolveSimpleEnv(env: BasicEnvInfo): Promise<PythonEnvInfo> {
131
156
kind,
132
157
version : await getPythonVersionFromPath ( executablePath ) ,
133
158
executable : executablePath ,
159
+ type : PythonEnvType . Virtual ,
134
160
} ) ;
135
161
const location = getEnvironmentDirFromPath ( executablePath ) ;
136
162
envInfo . location = location ;
@@ -161,6 +187,7 @@ async function resolveCondaEnv(env: BasicEnvInfo, useCache?: boolean): Promise<P
161
187
location : prefix ,
162
188
source : [ ] ,
163
189
version : executable ? await getPythonVersionFromPath ( executable ) : undefined ,
190
+ type : PythonEnvType . Conda ,
164
191
} ) ;
165
192
if ( name ) {
166
193
info . name = name ;
@@ -175,7 +202,9 @@ async function resolveCondaEnv(env: BasicEnvInfo, useCache?: boolean): Promise<P
175
202
) ;
176
203
// Environment could still be valid, resolve as a simple env.
177
204
env . kind = PythonEnvKind . Unknown ;
178
- return resolveSimpleEnv ( env ) ;
205
+ const envInfo = await resolveSimpleEnv ( env ) ;
206
+ envInfo . type = PythonEnvType . Conda ;
207
+ return envInfo ;
179
208
}
180
209
181
210
async function resolvePyenvEnv ( env : BasicEnvInfo ) : Promise < PythonEnvInfo > {
0 commit comments