@@ -22,7 +22,7 @@ import {
22
22
NativePythonFinder ,
23
23
} from '../common/nativePythonFinder' ;
24
24
import { getWorkspacePersistentState } from '../../common/persistentState' ;
25
- import { shortVersion , sortEnvironments } from '../common/utils' ;
25
+ import { isWindows , shortVersion , sortEnvironments } from '../common/utils' ;
26
26
import { findFiles , getConfiguration } from '../../common/workspace.apis' ;
27
27
import { pickEnvironmentFrom } from '../../common/pickers/environments' ;
28
28
import {
@@ -113,7 +113,7 @@ function getName(binPath: string): string {
113
113
return path . basename ( dir1 ) ;
114
114
}
115
115
116
- function getPythonInfo ( env : NativeEnvInfo ) : PythonEnvironmentInfo {
116
+ async function getPythonInfo ( env : NativeEnvInfo ) : Promise < PythonEnvironmentInfo > {
117
117
if ( env . executable && env . version && env . prefix ) {
118
118
const venvName = env . name ?? getName ( env . executable ) ;
119
119
const sv = shortVersion ( env . version ) ;
@@ -122,18 +122,50 @@ function getPythonInfo(env: NativeEnvInfo): PythonEnvironmentInfo {
122
122
const binDir = path . dirname ( env . executable ) ;
123
123
124
124
const shellActivation : Map < TerminalShellType , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
125
+ const shellDeactivation : Map < TerminalShellType , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
126
+
127
+ // Commands for bash
125
128
shellActivation . set ( TerminalShellType . bash , [ { executable : 'source' , args : [ path . join ( binDir , 'activate' ) ] } ] ) ;
129
+ shellDeactivation . set ( TerminalShellType . bash , [ { executable : 'deactivate' } ] ) ;
130
+
131
+ // Commands for csh
132
+ shellActivation . set ( TerminalShellType . cshell , [
133
+ { executable : 'source' , args : [ path . join ( binDir , 'activate' ) ] } ,
134
+ ] ) ;
135
+ shellDeactivation . set ( TerminalShellType . cshell , [ { executable : 'deactivate' } ] ) ;
136
+
137
+ // Commands for zsh
138
+ shellActivation . set ( TerminalShellType . zsh , [ { executable : 'source' , args : [ path . join ( binDir , 'activate' ) ] } ] ) ;
139
+ shellDeactivation . set ( TerminalShellType . zsh , [ { executable : 'deactivate' } ] ) ;
140
+
141
+ // Commands for powershell
126
142
shellActivation . set ( TerminalShellType . powershell , [
127
143
{ executable : '&' , args : [ path . join ( binDir , 'Activate.ps1' ) ] } ,
128
144
] ) ;
129
- shellActivation . set ( TerminalShellType . commandPrompt , [ { executable : path . join ( binDir , 'activate.bat' ) } ] ) ;
130
- shellActivation . set ( TerminalShellType . unknown , [ { executable : path . join ( binDir , 'activate' ) } ] ) ;
131
-
132
- const shellDeactivation = new Map < TerminalShellType , PythonCommandRunConfiguration [ ] > ( ) ;
133
- shellDeactivation . set ( TerminalShellType . bash , [ { executable : 'deactivate' } ] ) ;
134
145
shellDeactivation . set ( TerminalShellType . powershell , [ { executable : 'deactivate' } ] ) ;
146
+
147
+ // Commands for command prompt
148
+ shellActivation . set ( TerminalShellType . commandPrompt , [ { executable : path . join ( binDir , 'activate.bat' ) } ] ) ;
135
149
shellDeactivation . set ( TerminalShellType . commandPrompt , [ { executable : path . join ( binDir , 'deactivate.bat' ) } ] ) ;
136
- shellActivation . set ( TerminalShellType . unknown , [ { executable : 'deactivate' } ] ) ;
150
+
151
+ // Commands for fish
152
+ if ( await fsapi . pathExists ( path . join ( binDir , 'activate.fish' ) ) ) {
153
+ shellActivation . set ( TerminalShellType . fish , [
154
+ { executable : 'source' , args : [ path . join ( binDir , 'activate.fish' ) ] } ,
155
+ ] ) ;
156
+ shellDeactivation . set ( TerminalShellType . fish , [ { executable : 'deactivate' } ] ) ;
157
+ }
158
+
159
+ // Commands for unknown cases
160
+ if ( isWindows ( ) ) {
161
+ shellActivation . set ( TerminalShellType . unknown , [ { executable : path . join ( binDir , 'activate' ) } ] ) ;
162
+ shellDeactivation . set ( TerminalShellType . unknown , [ { executable : 'deactivate' } ] ) ;
163
+ } else {
164
+ shellActivation . set ( TerminalShellType . unknown , [
165
+ { executable : 'source' , args : [ path . join ( binDir , 'activate' ) ] } ,
166
+ ] ) ;
167
+ shellDeactivation . set ( TerminalShellType . unknown , [ { executable : 'deactivate' } ] ) ;
168
+ }
137
169
138
170
return {
139
171
name : name ,
@@ -176,16 +208,16 @@ export async function findVirtualEnvironments(
176
208
. map ( ( e ) => e as NativeEnvInfo )
177
209
. filter ( ( e ) => e . kind === NativePythonEnvironmentKind . venv ) ;
178
210
179
- envs . forEach ( ( e ) => {
211
+ for ( const e of envs ) {
180
212
if ( ! ( e . prefix && e . executable && e . version ) ) {
181
213
log . warn ( `Invalid conda environment: ${ JSON . stringify ( e ) } ` ) ;
182
- return ;
214
+ continue ;
183
215
}
184
216
185
- const env = api . createPythonEnvironmentItem ( getPythonInfo ( e ) , manager ) ;
217
+ const env = api . createPythonEnvironmentItem ( await getPythonInfo ( e ) , manager ) ;
186
218
collection . push ( env ) ;
187
219
log . info ( `Found venv environment: ${ env . name } ` ) ;
188
- } ) ;
220
+ }
189
221
return collection ;
190
222
}
191
223
@@ -351,7 +383,7 @@ export async function createPythonVenv(
351
383
}
352
384
353
385
const resolved = await nativeFinder . resolve ( pythonPath ) ;
354
- const env = api . createPythonEnvironmentItem ( getPythonInfo ( resolved ) , manager ) ;
386
+ const env = api . createPythonEnvironmentItem ( await getPythonInfo ( resolved ) , manager ) ;
355
387
if ( packages ?. length > 0 ) {
356
388
await api . installPackages ( env , packages , { upgrade : false } ) ;
357
389
}
@@ -500,7 +532,7 @@ export async function resolveVenvPythonEnvironmentPath(
500
532
const resolved = await nativeFinder . resolve ( fsPath ) ;
501
533
502
534
if ( resolved . kind === NativePythonEnvironmentKind . venv ) {
503
- const envInfo = getPythonInfo ( resolved ) ;
535
+ const envInfo = await getPythonInfo ( resolved ) ;
504
536
return api . createPythonEnvironmentItem ( envInfo , manager ) ;
505
537
}
506
538
0 commit comments