Skip to content

Commit 055a041

Browse files
committed
require python envs ext respecting terminal.activateEnvironment
1 parent dbfbd8c commit 055a041

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
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. To disable activation you must both set this setting to `off` and also set `python.terminal.activateEnvironment` to `false`.\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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,16 @@ 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');
152+
const pythonAct = pyConfig.get('terminal.activateEnvironment');
153+
const bothAct = pyenvAct && pythonAct ? 'true' : 'false';
154+
info.push(
155+
`Auto Activation set to ${bothAct} because py-env.terminal.autoActivationType is ${pyenvAct} and python.terminal.activateEnvironment is ${pythonAct}\n`,
156+
);
151157
} catch (err) {
152158
info.push(`\nError collecting environment information: ${err}`);
153159
}

src/features/terminal/terminalManager.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33
import { Disposable, EventEmitter, ProgressLocation, Terminal, TerminalOptions, Uri } from 'vscode';
44
import { PythonEnvironment, PythonEnvironmentApi, PythonProject, PythonTerminalCreateOptions } from '../../api';
55
import { ActivationStrings } from '../../common/localize';
6-
import { traceInfo, traceVerbose } from '../../common/logging';
6+
import { traceInfo, traceVerbose, traceWarn } from '../../common/logging';
77
import {
88
createTerminal,
99
onDidChangeWindowState,
@@ -235,7 +235,20 @@ export class TerminalManagerImpl implements TerminalManager {
235235
traceVerbose(`Environment ${environment.environmentPath.fsPath} is not activatable`);
236236
}
237237
} else if (actType === ACT_TYPE_OFF) {
238-
traceInfo(`"python-envs.terminal.autoActivationType" is set to "${actType}", skipping auto activation`);
238+
// Check both settings before skipping activation
239+
const pyEnvConfig = getConfiguration('python-envs');
240+
const pythonConfig = getConfiguration('python');
241+
const pyEnvAct = pyEnvConfig.get('terminal.autoActivationType');
242+
const pythonAct = pythonConfig.get('terminal.activateEnvironment');
243+
if (pythonAct === false) {
244+
traceInfo(
245+
`Auto activation skipped: "python-envs.terminal.autoActivationType" is "${pyEnvAct}" and "python.terminal.activateEnvironment" is "${pythonAct}".`,
246+
);
247+
} else {
248+
traceWarn(
249+
`Auto activation requires both settings to align: "python-envs.terminal.autoActivationType" and "python.terminal.activateEnvironment". If you don't want auto activation, ensure "python.terminal.activateEnvironment" is set to 'false'.`,
250+
);
251+
}
239252
} else if (actType === ACT_TYPE_SHELL) {
240253
traceInfo(
241254
`"python-envs.terminal.autoActivationType" is set to "${actType}", terminal should be activated by shell startup script`,

0 commit comments

Comments
 (0)