@@ -19,7 +19,7 @@ import {
19
19
NativePythonFinder ,
20
20
} from '../common/nativePythonFinder' ;
21
21
import { getWorkspacePersistentState } from '../../common/persistentState' ;
22
- import { shortVersion , sortEnvironments } from '../common/utils' ;
22
+ import { isWindows , shortVersion , sortEnvironments } from '../common/utils' ;
23
23
import { getConfiguration } from '../../common/workspace.apis' ;
24
24
import { pickEnvironmentFrom } from '../../common/pickers/environments' ;
25
25
import {
@@ -110,7 +110,7 @@ function getName(binPath: string): string {
110
110
return path . basename ( dir1 ) ;
111
111
}
112
112
113
- function getPythonInfo ( env : NativeEnvInfo ) : PythonEnvironmentInfo {
113
+ async function getPythonInfo ( env : NativeEnvInfo ) : Promise < PythonEnvironmentInfo > {
114
114
if ( env . executable && env . version && env . prefix ) {
115
115
const venvName = env . name ?? getName ( env . executable ) ;
116
116
const sv = shortVersion ( env . version ) ;
@@ -119,18 +119,50 @@ function getPythonInfo(env: NativeEnvInfo): PythonEnvironmentInfo {
119
119
const binDir = path . dirname ( env . executable ) ;
120
120
121
121
const shellActivation : Map < TerminalShellType , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
122
+ const shellDeactivation : Map < TerminalShellType , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
123
+
124
+ // Commands for bash
122
125
shellActivation . set ( TerminalShellType . bash , [ { executable : 'source' , args : [ path . join ( binDir , 'activate' ) ] } ] ) ;
126
+ shellDeactivation . set ( TerminalShellType . bash , [ { executable : 'deactivate' } ] ) ;
127
+
128
+ // Commands for csh
129
+ shellActivation . set ( TerminalShellType . cshell , [
130
+ { executable : 'source' , args : [ path . join ( binDir , 'activate' ) ] } ,
131
+ ] ) ;
132
+ shellDeactivation . set ( TerminalShellType . cshell , [ { executable : 'deactivate' } ] ) ;
133
+
134
+ // Commands for zsh
135
+ shellActivation . set ( TerminalShellType . zsh , [ { executable : 'source' , args : [ path . join ( binDir , 'activate' ) ] } ] ) ;
136
+ shellDeactivation . set ( TerminalShellType . zsh , [ { executable : 'deactivate' } ] ) ;
137
+
138
+ // Commands for powershell
123
139
shellActivation . set ( TerminalShellType . powershell , [
124
140
{ executable : '&' , args : [ path . join ( binDir , 'Activate.ps1' ) ] } ,
125
141
] ) ;
126
- shellActivation . set ( TerminalShellType . commandPrompt , [ { executable : path . join ( binDir , 'activate.bat' ) } ] ) ;
127
- shellActivation . set ( TerminalShellType . unknown , [ { executable : path . join ( binDir , 'activate' ) } ] ) ;
128
-
129
- const shellDeactivation = new Map < TerminalShellType , PythonCommandRunConfiguration [ ] > ( ) ;
130
- shellDeactivation . set ( TerminalShellType . bash , [ { executable : 'deactivate' } ] ) ;
131
142
shellDeactivation . set ( TerminalShellType . powershell , [ { executable : 'deactivate' } ] ) ;
143
+
144
+ // Commands for command prompt
145
+ shellActivation . set ( TerminalShellType . commandPrompt , [ { executable : path . join ( binDir , 'activate.bat' ) } ] ) ;
132
146
shellDeactivation . set ( TerminalShellType . commandPrompt , [ { executable : path . join ( binDir , 'deactivate.bat' ) } ] ) ;
133
- shellActivation . set ( TerminalShellType . unknown , [ { executable : 'deactivate' } ] ) ;
147
+
148
+ // Commands for fish
149
+ if ( await fsapi . pathExists ( path . join ( binDir , 'activate.fish' ) ) ) {
150
+ shellActivation . set ( TerminalShellType . fish , [
151
+ { executable : 'source' , args : [ path . join ( binDir , 'activate.fish' ) ] } ,
152
+ ] ) ;
153
+ shellDeactivation . set ( TerminalShellType . fish , [ { executable : 'deactivate' } ] ) ;
154
+ }
155
+
156
+ // Commands for unknown cases
157
+ if ( isWindows ( ) ) {
158
+ shellActivation . set ( TerminalShellType . unknown , [ { executable : path . join ( binDir , 'activate' ) } ] ) ;
159
+ shellDeactivation . set ( TerminalShellType . unknown , [ { executable : 'deactivate' } ] ) ;
160
+ } else {
161
+ shellActivation . set ( TerminalShellType . unknown , [
162
+ { executable : 'source' , args : [ path . join ( binDir , 'activate' ) ] } ,
163
+ ] ) ;
164
+ shellDeactivation . set ( TerminalShellType . unknown , [ { executable : 'deactivate' } ] ) ;
165
+ }
134
166
135
167
return {
136
168
name : name ,
@@ -173,16 +205,16 @@ export async function findVirtualEnvironments(
173
205
. map ( ( e ) => e as NativeEnvInfo )
174
206
. filter ( ( e ) => e . kind === NativePythonEnvironmentKind . venv ) ;
175
207
176
- envs . forEach ( ( e ) => {
208
+ for ( const e of envs ) {
177
209
if ( ! ( e . prefix && e . executable && e . version ) ) {
178
210
log . warn ( `Invalid conda environment: ${ JSON . stringify ( e ) } ` ) ;
179
- return ;
211
+ continue ;
180
212
}
181
213
182
- const env = api . createPythonEnvironmentItem ( getPythonInfo ( e ) , manager ) ;
214
+ const env = api . createPythonEnvironmentItem ( await getPythonInfo ( e ) , manager ) ;
183
215
collection . push ( env ) ;
184
216
log . info ( `Found venv environment: ${ env . name } ` ) ;
185
- } ) ;
217
+ }
186
218
return collection ;
187
219
}
188
220
@@ -339,7 +371,7 @@ export async function createPythonVenv(
339
371
}
340
372
341
373
const resolved = await nativeFinder . resolve ( pythonPath ) ;
342
- const env = api . createPythonEnvironmentItem ( getPythonInfo ( resolved ) , manager ) ;
374
+ const env = api . createPythonEnvironmentItem ( await getPythonInfo ( resolved ) , manager ) ;
343
375
if ( packages && packages ?. length > 0 ) {
344
376
await api . installPackages ( env , packages , { upgrade : false } ) ;
345
377
}
@@ -397,7 +429,7 @@ export async function resolveVenvPythonEnvironmentPath(
397
429
const resolved = await nativeFinder . resolve ( fsPath ) ;
398
430
399
431
if ( resolved . kind === NativePythonEnvironmentKind . venv ) {
400
- const envInfo = getPythonInfo ( resolved ) ;
432
+ const envInfo = await getPythonInfo ( resolved ) ;
401
433
return api . createPythonEnvironmentItem ( envInfo , manager ) ;
402
434
}
403
435
0 commit comments