@@ -31,7 +31,6 @@ import {
3131} from '../../common/window.apis' ;
3232import { showErrorMessage } from '../../common/errors/utils' ;
3333import { Common , VenvManagerStrings } from '../../common/localize' ;
34- import unsafeEntries from '../../common/utils/unsafeEntries' ;
3534import { isUvInstalled , runUV , runPython } from './helpers' ;
3635import { getWorkspacePackagesToInstall } from './pipUtils' ;
3736
@@ -111,72 +110,125 @@ function getName(binPath: string): string {
111110 return path . basename ( dir1 ) ;
112111}
113112
113+ function pathForGitBash ( binPath : string ) : string {
114+ return isWindows ( ) ? binPath . replace ( / \\ / g, '/' ) : binPath ;
115+ }
116+
114117async function getPythonInfo ( env : NativeEnvInfo ) : Promise < PythonEnvironmentInfo > {
115118 if ( env . executable && env . version && env . prefix ) {
116119 const venvName = env . name ?? getName ( env . executable ) ;
117120 const sv = shortVersion ( env . version ) ;
118121 const name = `${ venvName } (${ sv } )` ;
119122
120123 const binDir = path . dirname ( env . executable ) ;
121-
122- interface VenvManager {
123- activate : PythonCommandRunConfiguration ,
124- deactivate : PythonCommandRunConfiguration ,
124+
125+ interface VenvCommand {
126+ activate : PythonCommandRunConfiguration ;
127+ deactivate : PythonCommandRunConfiguration ;
125128 /// true if created by the builtin `venv` module and not just the `virtualenv` package.
126- supportsStdlib : boolean ,
129+ supportsStdlib : boolean ;
130+ checkPath ?: string ;
127131 }
128-
129- /** Venv activation/deactivation using a command */
130- const cmdMgr = ( suffix = '' ) : VenvManager => ( {
131- activate : { executable : path . join ( binDir , `activate${ suffix } ` ) } ,
132- deactivate : { executable : path . join ( binDir , `deactivate${ suffix } ` ) } ,
133- supportsStdlib : [ '' , '.bat' ] . includes ( suffix ) ,
134- } ) ;
135- /** Venv activation/deactivation for a POSIXy shell */
136- const sourceMgr = ( suffix = '' , executable = 'source' ) : VenvManager => ( {
137- activate : { executable, args : [ path . join ( binDir , `activate${ suffix } ` ) ] } ,
138- deactivate : { executable : 'deactivate' } ,
139- supportsStdlib : [ '' , '.ps1' ] . includes ( suffix ) ,
140- } ) ;
141- // satisfies `Record` to make sure all shells are covered
142- const venvManagers : Record < TerminalShellType , VenvManager > = {
132+
133+ const venvManagers : Record < TerminalShellType , VenvCommand > = {
143134 // Shells supported by the builtin `venv` module
144- [ TerminalShellType . bash ] : sourceMgr ( ) ,
145- [ TerminalShellType . gitbash ] : sourceMgr ( ) ,
146- [ TerminalShellType . zsh ] : sourceMgr ( ) ,
147- [ TerminalShellType . wsl ] : sourceMgr ( ) ,
148- [ TerminalShellType . ksh ] : sourceMgr ( '' , '.' ) ,
149- [ TerminalShellType . powershell ] : sourceMgr ( '.ps1' , '&' ) ,
150- [ TerminalShellType . powershellCore ] : sourceMgr ( '.ps1' , '&' ) ,
151- [ TerminalShellType . commandPrompt ] : cmdMgr ( '.bat' ) ,
135+ [ TerminalShellType . bash ] : {
136+ activate : { executable : 'source' , args : [ path . join ( binDir , `activate` ) ] } ,
137+ deactivate : { executable : 'deactivate' } ,
138+ supportsStdlib : true ,
139+ } ,
140+ [ TerminalShellType . gitbash ] : {
141+ activate : { executable : 'source' , args : [ pathForGitBash ( path . join ( binDir , `activate` ) ) ] } ,
142+ deactivate : { executable : 'deactivate' } ,
143+ supportsStdlib : true ,
144+ } ,
145+ [ TerminalShellType . zsh ] : {
146+ activate : { executable : 'source' , args : [ path . join ( binDir , `activate` ) ] } ,
147+ deactivate : { executable : 'deactivate' } ,
148+ supportsStdlib : true ,
149+ } ,
150+ [ TerminalShellType . wsl ] : {
151+ activate : { executable : 'source' , args : [ path . join ( binDir , `activate` ) ] } ,
152+ deactivate : { executable : 'deactivate' } ,
153+ supportsStdlib : true ,
154+ } ,
155+ [ TerminalShellType . ksh ] : {
156+ activate : { executable : '.' , args : [ path . join ( binDir , `activate` ) ] } ,
157+ deactivate : { executable : 'deactivate' } ,
158+ supportsStdlib : true ,
159+ } ,
160+ [ TerminalShellType . powershell ] : {
161+ activate : { executable : '&' , args : [ path . join ( binDir , `activate.ps1` ) ] } ,
162+ deactivate : { executable : 'deactivate' } ,
163+ supportsStdlib : true ,
164+ } ,
165+ [ TerminalShellType . powershellCore ] : {
166+ activate : { executable : '&' , args : [ path . join ( binDir , `activate.ps1` ) ] } ,
167+ deactivate : { executable : 'deactivate' } ,
168+ supportsStdlib : true ,
169+ } ,
170+ [ TerminalShellType . commandPrompt ] : {
171+ activate : { executable : path . join ( binDir , `activate.bat` ) } ,
172+ deactivate : { executable : path . join ( binDir , `deactivate.bat` ) } ,
173+ supportsStdlib : true ,
174+ } ,
152175 // Shells supported by the `virtualenv` package
153- [ TerminalShellType . cshell ] : sourceMgr ( '.csh' ) ,
154- [ TerminalShellType . tcshell ] : sourceMgr ( '.csh' ) ,
155- [ TerminalShellType . fish ] : sourceMgr ( '.fish' ) ,
156- [ TerminalShellType . xonsh ] : sourceMgr ( '.xsh' ) ,
176+ [ TerminalShellType . cshell ] : {
177+ activate : { executable : 'source' , args : [ path . join ( binDir , `activate.csh` ) ] } ,
178+ deactivate : { executable : 'deactivate' } ,
179+ supportsStdlib : false ,
180+ checkPath : path . join ( binDir , `activate.csh` ) ,
181+ } ,
182+ [ TerminalShellType . tcshell ] : {
183+ activate : { executable : 'source' , args : [ path . join ( binDir , `activate.csh` ) ] } ,
184+ deactivate : { executable : 'deactivate' } ,
185+ supportsStdlib : false ,
186+ checkPath : path . join ( binDir , `activate.csh` ) ,
187+ } ,
188+ [ TerminalShellType . fish ] : {
189+ activate : { executable : 'source' , args : [ path . join ( binDir , `activate.fish` ) ] } ,
190+ deactivate : { executable : 'deactivate' } ,
191+ supportsStdlib : false ,
192+ checkPath : path . join ( binDir , `activate.fish` ) ,
193+ } ,
194+ [ TerminalShellType . xonsh ] : {
195+ activate : { executable : 'source' , args : [ path . join ( binDir , `activate.xsh` ) ] } ,
196+ deactivate : { executable : 'deactivate' } ,
197+ supportsStdlib : false ,
198+ checkPath : path . join ( binDir , `activate.xsh` ) ,
199+ } ,
157200 [ TerminalShellType . nushell ] : {
158201 activate : { executable : 'overlay' , args : [ 'use' , path . join ( binDir , 'activate.nu' ) ] } ,
159202 deactivate : { executable : 'overlay' , args : [ 'hide' , 'activate' ] } ,
160203 supportsStdlib : false ,
204+ checkPath : path . join ( binDir , `activate.nu` ) ,
161205 } ,
162206 // Fallback
163- [ TerminalShellType . unknown ] : isWindows ( ) ? cmdMgr ( ) : sourceMgr ( ) ,
164- } ;
207+ [ TerminalShellType . unknown ] : isWindows ( )
208+ ? {
209+ activate : { executable : path . join ( binDir , `activate` ) } ,
210+ deactivate : { executable : path . join ( binDir , `deactivate` ) } ,
211+ supportsStdlib : true ,
212+ }
213+ : {
214+ activate : { executable : 'source' , args : [ path . join ( binDir , `activate` ) ] } ,
215+ deactivate : { executable : 'deactivate' } ,
216+ supportsStdlib : true ,
217+ } ,
218+ } satisfies Record < TerminalShellType , VenvCommand > ;
165219
166220 const shellActivation : Map < TerminalShellType , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
167221 const shellDeactivation : Map < TerminalShellType , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
168222
169- await Promise . all ( unsafeEntries ( venvManagers ) . map ( async ( [ shell , mgr ] ) => {
170- if (
171- ! mgr . supportsStdlib &&
172- mgr . activate . args &&
173- ! await fsapi . pathExists ( mgr . activate . args [ mgr . activate . args . length - 1 ] )
174- ) {
175- return ;
176- }
177- shellActivation . set ( shell , [ mgr . activate ] ) ;
178- shellDeactivation . set ( shell , [ mgr . deactivate ] ) ;
179- } ) ) ;
223+ await Promise . all (
224+ ( Object . entries ( venvManagers ) as [ TerminalShellType , VenvCommand ] [ ] ) . map ( async ( [ shell , mgr ] ) => {
225+ if ( ! mgr . supportsStdlib && mgr . checkPath && ! ( await fsapi . pathExists ( mgr . checkPath ) ) ) {
226+ return ;
227+ }
228+ shellActivation . set ( shell , [ mgr . activate ] ) ;
229+ shellDeactivation . set ( shell , [ mgr . deactivate ] ) ;
230+ } ) ,
231+ ) ;
180232
181233 return {
182234 name : name ,
0 commit comments