Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"python-envs.pythonProjects.envManager.description": "The environment manager for creating and managing environments for this project.",
"python-envs.pythonProjects.packageManager.description": "The package manager for managing packages in environments for this project.",
"python-envs.terminal.showActivateButton.description": "Whether to show the 'Activate' button in the terminal menu",
"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`.",
"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`.",
"python-envs.terminal.autoActivationType.command": "Activation by executing a command in the terminal.",
"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.",
"python-envs.terminal.autoActivationType.off": "No automatic activation of environments.",
Expand Down
9 changes: 7 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { ShellStartupActivationVariablesManagerImpl } from './features/terminal/
import { cleanupStartupScripts } from './features/terminal/shellStartupSetupHandlers';
import { TerminalActivationImpl } from './features/terminal/terminalActivationState';
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
import { getEnvironmentForTerminal } from './features/terminal/utils';
import { getAutoActivationType, getEnvironmentForTerminal } from './features/terminal/utils';
import { EnvManagerView } from './features/views/envManagersView';
import { ProjectView } from './features/views/projectView';
import { PythonStatusBarImpl } from './features/views/pythonStatusBar';
Expand Down Expand Up @@ -144,10 +144,15 @@ async function collectEnvironmentInfo(

// Current settings (non-sensitive)
const config = workspace.getConfiguration('python-envs');
const pyConfig = workspace.getConfiguration('python');
info.push('\nExtension Settings:');
info.push(` Default Environment Manager: ${config.get('defaultEnvManager')}`);
info.push(` Default Package Manager: ${config.get('defaultPackageManager')}`);
info.push(` Terminal Auto Activation: ${config.get('terminal.autoActivationType')}`);
const pyenvAct = config.get('terminal.autoActivationType', undefined);
const pythonAct = pyConfig.get('terminal.activateEnvironment', undefined);
info.push(
`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`,
);
} catch (err) {
info.push(`\nError collecting environment information: ${err}`);
}
Expand Down
40 changes: 35 additions & 5 deletions src/features/terminal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,42 @@ export const ACT_TYPE_SHELL = 'shellStartup';
export const ACT_TYPE_COMMAND = 'command';
export const ACT_TYPE_OFF = 'off';
export type AutoActivationType = 'off' | 'command' | 'shellStartup';
/**
* Determines the auto-activation type for Python environments in terminals.
*
* The following types are supported:
* - 'shellStartup': Environment is activated via shell startup scripts
* - 'command': Environment is activated via explicit command
* - 'off': Auto-activation is disabled
*
* Priority order:
* 1. python-envs.terminal.autoActivationType setting
* 2. python.terminal.activateEnvironment setting (if false updates python-envs.terminal.autoActivationType)
* 3. Default to 'command' if no setting is found
*
* @returns {AutoActivationType} The determined auto-activation type
*/
export function getAutoActivationType(): AutoActivationType {
// 'startup' auto-activation means terminal is activated via shell startup scripts.
// 'command' auto-activation means terminal is activated via a command.
// 'off' means no auto-activation.
const config = getConfiguration('python-envs');
return config.get<AutoActivationType>('terminal.autoActivationType', 'command');
const pyEnvsConfig = getConfiguration('python-envs');

const pyEnvsActivationType = pyEnvsConfig.get<AutoActivationType | undefined>(
'terminal.autoActivationType',
undefined,
);
if (pyEnvsActivationType !== undefined) {
return pyEnvsActivationType;
}

const pythonConfig = getConfiguration('python');
const pythonActivateSetting = pythonConfig.get<boolean | undefined>('terminal.activateEnvironment', undefined);
if (pythonActivateSetting !== undefined) {
if (pythonActivateSetting === false) {
pyEnvsConfig.set('terminal.autoActivationType', ACT_TYPE_OFF);
}
return pythonActivateSetting ? ACT_TYPE_COMMAND : ACT_TYPE_OFF;
}

return ACT_TYPE_COMMAND;
}

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