@@ -2,21 +2,14 @@ import * as fsapi from 'fs-extra';
22import * as os from 'os' ;
33import * as path from 'path' ;
44import { l10n , LogOutputChannel , ProgressLocation , QuickPickItem , QuickPickItemKind , ThemeIcon , Uri } from 'vscode' ;
5- import {
6- EnvironmentManager ,
7- PythonCommandRunConfiguration ,
8- PythonEnvironment ,
9- PythonEnvironmentApi ,
10- PythonEnvironmentInfo ,
11- } from '../../api' ;
5+ import { EnvironmentManager , PythonEnvironment , PythonEnvironmentApi , PythonEnvironmentInfo } from '../../api' ;
126import { ENVS_EXTENSION_ID } from '../../common/constants' ;
137import { Common , VenvManagerStrings } from '../../common/localize' ;
148import { traceInfo } from '../../common/logging' ;
159import { getWorkspacePersistentState } from '../../common/persistentState' ;
1610import { pickEnvironmentFrom } from '../../common/pickers/environments' ;
1711import { EventNames } from '../../common/telemetry/constants' ;
1812import { sendTelemetryEvent } from '../../common/telemetry/sender' ;
19- import { isWindows } from '../../common/utils/platformUtils' ;
2013import {
2114 showErrorMessage ,
2215 showInputBox ,
@@ -26,14 +19,13 @@ import {
2619 withProgress ,
2720} from '../../common/window.apis' ;
2821import { getConfiguration } from '../../common/workspace.apis' ;
29- import { ShellConstants } from '../../features/common/shellConstants' ;
3022import {
3123 isNativeEnvInfo ,
3224 NativeEnvInfo ,
3325 NativePythonEnvironmentKind ,
3426 NativePythonFinder ,
3527} from '../common/nativePythonFinder' ;
36- import { pathForGitBash , shortVersion , sortEnvironments } from '../common/utils' ;
28+ import { getShellActivationCommands , shortVersion , sortEnvironments } from '../common/utils' ;
3729import { isUvInstalled , runPython , runUV } from './helpers' ;
3830import { getProjectInstallable , getWorkspacePackagesToInstall , PipPackages } from './pipUtils' ;
3931import { resolveSystemPythonEnvironmentPath } from './utils' ;
@@ -122,79 +114,7 @@ async function getPythonInfo(env: NativeEnvInfo): Promise<PythonEnvironmentInfo>
122114
123115 const binDir = path . dirname ( env . executable ) ;
124116
125- const shellActivation : Map < string , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
126- const shellDeactivation : Map < string , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
127-
128- if ( isWindows ( ) ) {
129- shellActivation . set ( 'unknown' , [ { executable : path . join ( binDir , `activate` ) } ] ) ;
130- shellDeactivation . set ( 'unknown' , [ { executable : path . join ( binDir , `deactivate` ) } ] ) ;
131- } else {
132- shellActivation . set ( 'unknown' , [ { executable : 'source' , args : [ path . join ( binDir , `activate` ) ] } ] ) ;
133- shellDeactivation . set ( 'unknown' , [ { executable : 'deactivate' } ] ) ;
134- }
135-
136- shellActivation . set ( ShellConstants . SH , [ { executable : 'source' , args : [ path . join ( binDir , `activate` ) ] } ] ) ;
137- shellDeactivation . set ( ShellConstants . SH , [ { executable : 'deactivate' } ] ) ;
138-
139- shellActivation . set ( ShellConstants . BASH , [ { executable : 'source' , args : [ path . join ( binDir , `activate` ) ] } ] ) ;
140- shellDeactivation . set ( ShellConstants . BASH , [ { executable : 'deactivate' } ] ) ;
141-
142- shellActivation . set ( ShellConstants . GITBASH , [
143- { executable : 'source' , args : [ pathForGitBash ( path . join ( binDir , `activate` ) ) ] } ,
144- ] ) ;
145- shellDeactivation . set ( ShellConstants . GITBASH , [ { executable : 'deactivate' } ] ) ;
146-
147- shellActivation . set ( ShellConstants . ZSH , [ { executable : 'source' , args : [ path . join ( binDir , `activate` ) ] } ] ) ;
148- shellDeactivation . set ( ShellConstants . ZSH , [ { executable : 'deactivate' } ] ) ;
149-
150- shellActivation . set ( ShellConstants . KSH , [ { executable : '.' , args : [ path . join ( binDir , `activate` ) ] } ] ) ;
151- shellDeactivation . set ( ShellConstants . KSH , [ { executable : 'deactivate' } ] ) ;
152-
153- if ( await fsapi . pathExists ( path . join ( binDir , 'Activate.ps1' ) ) ) {
154- shellActivation . set ( ShellConstants . PWSH , [ { executable : '&' , args : [ path . join ( binDir , `Activate.ps1` ) ] } ] ) ;
155- shellDeactivation . set ( ShellConstants . PWSH , [ { executable : 'deactivate' } ] ) ;
156- } else if ( await fsapi . pathExists ( path . join ( binDir , 'activate.ps1' ) ) ) {
157- shellActivation . set ( ShellConstants . PWSH , [ { executable : '&' , args : [ path . join ( binDir , `activate.ps1` ) ] } ] ) ;
158- shellDeactivation . set ( ShellConstants . PWSH , [ { executable : 'deactivate' } ] ) ;
159- }
160-
161- if ( await fsapi . pathExists ( path . join ( binDir , 'activate.bat' ) ) ) {
162- shellActivation . set ( ShellConstants . CMD , [ { executable : path . join ( binDir , `activate.bat` ) } ] ) ;
163- shellDeactivation . set ( ShellConstants . CMD , [ { executable : path . join ( binDir , `deactivate.bat` ) } ] ) ;
164- }
165-
166- if ( await fsapi . pathExists ( path . join ( binDir , 'activate.csh' ) ) ) {
167- shellActivation . set ( ShellConstants . CSH , [
168- { executable : 'source' , args : [ path . join ( binDir , `activate.csh` ) ] } ,
169- ] ) ;
170- shellDeactivation . set ( ShellConstants . CSH , [ { executable : 'deactivate' } ] ) ;
171-
172- shellActivation . set ( ShellConstants . FISH , [
173- { executable : 'source' , args : [ path . join ( binDir , `activate.csh` ) ] } ,
174- ] ) ;
175- shellDeactivation . set ( ShellConstants . FISH , [ { executable : 'deactivate' } ] ) ;
176- }
177-
178- if ( await fsapi . pathExists ( path . join ( binDir , 'activate.fish' ) ) ) {
179- shellActivation . set ( ShellConstants . FISH , [
180- { executable : 'source' , args : [ path . join ( binDir , `activate.fish` ) ] } ,
181- ] ) ;
182- shellDeactivation . set ( ShellConstants . FISH , [ { executable : 'deactivate' } ] ) ;
183- }
184-
185- if ( await fsapi . pathExists ( path . join ( binDir , 'activate.xsh' ) ) ) {
186- shellActivation . set ( ShellConstants . XONSH , [
187- { executable : 'source' , args : [ path . join ( binDir , `activate.xsh` ) ] } ,
188- ] ) ;
189- shellDeactivation . set ( ShellConstants . XONSH , [ { executable : 'deactivate' } ] ) ;
190- }
191-
192- if ( await fsapi . pathExists ( path . join ( binDir , 'activate.nu' ) ) ) {
193- shellActivation . set ( ShellConstants . NU , [
194- { executable : 'overlay' , args : [ 'use' , path . join ( binDir , 'activate.nu' ) ] } ,
195- ] ) ;
196- shellDeactivation . set ( ShellConstants . NU , [ { executable : 'overlay' , args : [ 'hide' , 'activate' ] } ] ) ;
197- }
117+ const { shellActivation, shellDeactivation } = await getShellActivationCommands ( binDir ) ;
198118
199119 return {
200120 name : name ,
0 commit comments