Skip to content

Commit 69a1020

Browse files
committed
set autoActivationType based on both settings
1 parent dbfbd8c commit 69a1020

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"python-envs.pythonProjects.envManager.description": "The environment manager for creating and managing environments for this project.",
77
"python-envs.pythonProjects.packageManager.description": "The package manager for managing packages in environments for this project.",
88
"python-envs.terminal.showActivateButton.description": "Whether to show the 'Activate' button in the terminal menu",
9-
"python-envs.terminal.autoActivationType.description": "Specifies how the extension can activate an environment in a terminal.\n\nUtilizing Shell Startup requires changes to the shell script file and is only enabled for the following shells: zsh, fsh, pwsh, bash, cmd. When set to `command`, any shell can be activated.\n\nThis setting applies only when terminals are created, so you will need to restart your terminals for it to take effect.\n\nTo revert changes made during shellStartup, run `Python Envs: Revert Shell Startup Script Changes`.",
9+
"python-envs.terminal.autoActivationType.description": "Specifies how the extension can activate an environment in a terminal.\n\nUtilizing Shell Startup requires changes to the shell script file and is only enabled for the following shells: zsh, fsh, pwsh, bash, cmd. When set to `command`, any shell can be activated.\n\nThis setting takes precedence over the legacy `python.terminal.activateEnvironment` setting. If this setting is not explicitly set and `python.terminal.activateEnvironment` is set to false, this setting will automatically be set to `off` to preserve your preference.\n\nThis setting applies only when terminals are created, so you will need to restart your terminals for it to take effect.\n\nTo revert changes made during shellStartup, run `Python Envs: Revert Shell Startup Script Changes`.",
1010
"python-envs.terminal.autoActivationType.command": "Activation by executing a command in the terminal.",
1111
"python-envs.terminal.autoActivationType.shellStartup": "Activation by modifying the terminal shell startup script. To use this feature we will need to modify your shell startup scripts.",
1212
"python-envs.terminal.autoActivationType.off": "No automatic activation of environments.",

src/extension.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import { ShellStartupActivationVariablesManagerImpl } from './features/terminal/
5858
import { cleanupStartupScripts } from './features/terminal/shellStartupSetupHandlers';
5959
import { TerminalActivationImpl } from './features/terminal/terminalActivationState';
6060
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
61-
import { getEnvironmentForTerminal } from './features/terminal/utils';
61+
import { getAutoActivationType, getEnvironmentForTerminal } from './features/terminal/utils';
6262
import { EnvManagerView } from './features/views/envManagersView';
6363
import { ProjectView } from './features/views/projectView';
6464
import { PythonStatusBarImpl } from './features/views/pythonStatusBar';
@@ -144,10 +144,15 @@ async function collectEnvironmentInfo(
144144

145145
// Current settings (non-sensitive)
146146
const config = workspace.getConfiguration('python-envs');
147+
const pyConfig = workspace.getConfiguration('python');
147148
info.push('\nExtension Settings:');
148149
info.push(` Default Environment Manager: ${config.get('defaultEnvManager')}`);
149150
info.push(` Default Package Manager: ${config.get('defaultPackageManager')}`);
150-
info.push(` Terminal Auto Activation: ${config.get('terminal.autoActivationType')}`);
151+
const pyenvAct = config.get('terminal.autoActivationType', undefined);
152+
const pythonAct = pyConfig.get('terminal.activateEnvironment', undefined);
153+
info.push(
154+
`Auto-activation is "${getAutoActivationType()}". Activation based on first 'py-env.terminal.autoActivationType' setting which is '${pyenvAct}' and 'python.terminal.activateEnvironment' if the first is undefined which is '${pythonAct}'.\n`,
155+
);
151156
} catch (err) {
152157
info.push(`\nError collecting environment information: ${err}`);
153158
}

src/features/terminal/utils.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,42 @@ export const ACT_TYPE_SHELL = 'shellStartup';
9494
export const ACT_TYPE_COMMAND = 'command';
9595
export const ACT_TYPE_OFF = 'off';
9696
export type AutoActivationType = 'off' | 'command' | 'shellStartup';
97+
/**
98+
* Determines the auto-activation type for Python environments in terminals.
99+
*
100+
* The following types are supported:
101+
* - 'shellStartup': Environment is activated via shell startup scripts
102+
* - 'command': Environment is activated via explicit command
103+
* - 'off': Auto-activation is disabled
104+
*
105+
* Priority order:
106+
* 1. python-envs.terminal.autoActivationType setting
107+
* 2. python.terminal.activateEnvironment setting (if false updates python-envs.terminal.autoActivationType)
108+
* 3. Default to 'command' if no setting is found
109+
*
110+
* @returns {AutoActivationType} The determined auto-activation type
111+
*/
97112
export function getAutoActivationType(): AutoActivationType {
98-
// 'startup' auto-activation means terminal is activated via shell startup scripts.
99-
// 'command' auto-activation means terminal is activated via a command.
100-
// 'off' means no auto-activation.
101-
const config = getConfiguration('python-envs');
102-
return config.get<AutoActivationType>('terminal.autoActivationType', 'command');
113+
const pyEnvsConfig = getConfiguration('python-envs');
114+
115+
const pyEnvsActivationType = pyEnvsConfig.get<AutoActivationType | undefined>(
116+
'terminal.autoActivationType',
117+
undefined,
118+
);
119+
if (pyEnvsActivationType !== undefined) {
120+
return pyEnvsActivationType;
121+
}
122+
123+
const pythonConfig = getConfiguration('python');
124+
const pythonActivateSetting = pythonConfig.get<boolean | undefined>('terminal.activateEnvironment', undefined);
125+
if (pythonActivateSetting !== undefined) {
126+
if (pythonActivateSetting === false) {
127+
pyEnvsConfig.set('terminal.autoActivationType', ACT_TYPE_OFF);
128+
}
129+
return pythonActivateSetting ? ACT_TYPE_COMMAND : ACT_TYPE_OFF;
130+
}
131+
132+
return ACT_TYPE_COMMAND;
103133
}
104134

105135
export async function setAutoActivationType(value: AutoActivationType): Promise<void> {

0 commit comments

Comments
 (0)