Skip to content

Commit fb33024

Browse files
authored
Merge branch 'main' into add-doc-strings
2 parents d588d4d + dbc5656 commit fb33024

13 files changed

Lines changed: 433 additions & 30 deletions

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"url": "https://github.com/microsoft/vscode-python-environments/issues"
3737
},
3838
"main": "./dist/extension.js",
39+
"l10n": "./l10n",
3940
"icon": "icon.png",
4041
"contributes": {
4142
"configuration": {

package.nls.json

Lines changed: 2 additions & 2 deletions
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.",
@@ -36,5 +36,5 @@
3636
"python-envs.terminal.deactivate.title": "Deactivate Environment in Current Terminal",
3737
"python-envs.uninstallPackage.title": "Uninstall Package",
3838
"python-envs.revealProjectInExplorer.title": "Reveal Project in Explorer",
39-
"python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal"
39+
"python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal..."
4040
}

src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ export interface DidChangeEnvironmentVariablesEventArgs {
12231223
/**
12241224
* The type of change that occurred.
12251225
*/
1226-
changeTye: FileChangeType;
1226+
changeType: FileChangeType;
12271227
}
12281228

12291229
export interface PythonEnvironmentVariablesApi {

src/extension.ts

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { EventNames } from './common/telemetry/constants';
99
import { sendManagerSelectionTelemetry } from './common/telemetry/helpers';
1010
import { sendTelemetryEvent } from './common/telemetry/sender';
1111
import { createDeferred } from './common/utils/deferred';
12+
import { isWindows } from './common/utils/platformUtils';
1213
import {
1314
activeTerminal,
1415
createLogOutputChannel,
@@ -57,8 +58,9 @@ import {
5758
import { ShellStartupActivationVariablesManagerImpl } from './features/terminal/shellStartupActivationVariablesManager';
5859
import { cleanupStartupScripts } from './features/terminal/shellStartupSetupHandlers';
5960
import { TerminalActivationImpl } from './features/terminal/terminalActivationState';
61+
import { TerminalEnvVarInjector } from './features/terminal/terminalEnvVarInjector';
6062
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
61-
import { getEnvironmentForTerminal } from './features/terminal/utils';
63+
import { getAutoActivationType, getEnvironmentForTerminal } from './features/terminal/utils';
6264
import { EnvManagerView } from './features/views/envManagersView';
6365
import { ProjectView } from './features/views/projectView';
6466
import { PythonStatusBarImpl } from './features/views/pythonStatusBar';
@@ -144,10 +146,15 @@ async function collectEnvironmentInfo(
144146

145147
// Current settings (non-sensitive)
146148
const config = workspace.getConfiguration('python-envs');
149+
const pyConfig = workspace.getConfiguration('python');
147150
info.push('\nExtension Settings:');
148151
info.push(` Default Environment Manager: ${config.get('defaultEnvManager')}`);
149152
info.push(` Default Package Manager: ${config.get('defaultPackageManager')}`);
150-
info.push(` Terminal Auto Activation: ${config.get('terminal.autoActivationType')}`);
153+
const pyenvAct = config.get('terminal.autoActivationType', undefined);
154+
const pythonAct = pyConfig.get('terminal.activateEnvironment', undefined);
155+
info.push(
156+
`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`,
157+
);
151158
} catch (err) {
152159
info.push(`\nError collecting environment information: ${err}`);
153160
}
@@ -234,6 +241,10 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
234241
api,
235242
);
236243

244+
// Initialize terminal environment variable injection
245+
const terminalEnvVarInjector = new TerminalEnvVarInjector(context.environmentVariableCollection, envVarManager);
246+
context.subscriptions.push(terminalEnvVarInjector);
247+
237248
context.subscriptions.push(
238249
shellStartupVarsMgr,
239250
registerCompletionProvider(envManagers),
@@ -437,12 +448,63 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
437448
commands.registerCommand('python-envs.runPetInTerminal', async () => {
438449
try {
439450
const petPath = await getNativePythonToolsPath();
451+
452+
// Show quick pick menu for PET operation selection
453+
const selectedOption = await window.showQuickPick(
454+
[
455+
{
456+
label: 'Find All Environments',
457+
description: 'Finds all environments and reports them to the standard output',
458+
detail: 'Runs: pet find --verbose',
459+
},
460+
{
461+
label: 'Resolve Environment...',
462+
description: 'Resolves & reports the details of the environment to the standard output',
463+
detail: 'Runs: pet resolve <path>',
464+
},
465+
],
466+
{
467+
placeHolder: 'Select a Python Environment Tool (PET) operation',
468+
ignoreFocusOut: true,
469+
},
470+
);
471+
472+
if (!selectedOption) {
473+
return; // User cancelled
474+
}
475+
440476
const terminal = createTerminal({
441477
name: 'Python Environment Tool (PET)',
442478
});
443479
terminal.show();
444-
terminal.sendText(`"${petPath}"`, true);
445-
traceInfo(`Running PET in terminal: ${petPath}`);
480+
481+
if (selectedOption.label === 'Find All Environments') {
482+
// Run pet find --verbose
483+
terminal.sendText(`"${petPath}" find --verbose`, true);
484+
traceInfo(`Running PET find command: ${petPath} find --verbose`);
485+
} else if (selectedOption.label === 'Resolve Environment...') {
486+
// Show input box for path
487+
const placeholder = isWindows() ? 'C:\\path\\to\\python\\executable' : '/path/to/python/executable';
488+
const inputPath = await window.showInputBox({
489+
prompt: 'Enter the path to the Python executable to resolve',
490+
placeHolder: placeholder,
491+
ignoreFocusOut: true,
492+
validateInput: (value) => {
493+
if (!value || value.trim().length === 0) {
494+
return 'Please enter a valid path';
495+
}
496+
return null;
497+
},
498+
});
499+
500+
if (!inputPath) {
501+
return; // User cancelled
502+
}
503+
504+
// Run pet resolve with the provided path
505+
terminal.sendText(`"${petPath}" resolve "${inputPath.trim()}"`, true);
506+
traceInfo(`Running PET resolve command: ${petPath} resolve "${inputPath.trim()}"`);
507+
}
446508
} catch (error) {
447509
traceError('Error running PET in terminal', error);
448510
window.showErrorMessage(`Failed to run Python Environment Tool: ${error}`);

src/features/execution/envVariableManager.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as path from 'path';
21
import * as fsapi from 'fs-extra';
3-
import { Uri, Event, EventEmitter, FileChangeType } from 'vscode';
4-
import { DidChangeEnvironmentVariablesEventArgs, PythonEnvironmentVariablesApi } from '../../api';
2+
import * as path from 'path';
3+
import { Event, EventEmitter, FileChangeType, Uri } from 'vscode';
54
import { Disposable } from 'vscode-jsonrpc';
5+
import { DidChangeEnvironmentVariablesEventArgs, PythonEnvironmentVariablesApi } from '../../api';
6+
import { resolveVariables } from '../../common/utils/internalVariables';
67
import { createFileSystemWatcher, getConfiguration } from '../../common/workspace.apis';
78
import { PythonProjectManager } from '../../internal.api';
89
import { mergeEnvVariables, parseEnvFile } from './envVarUtils';
9-
import { resolveVariables } from '../../common/utils/internalVariables';
1010

1111
export interface EnvVarManager extends PythonEnvironmentVariablesApi, Disposable {}
1212

@@ -25,13 +25,13 @@ export class PythonEnvVariableManager implements EnvVarManager {
2525
this._onDidChangeEnvironmentVariables,
2626
this.watcher,
2727
this.watcher.onDidCreate((e) =>
28-
this._onDidChangeEnvironmentVariables.fire({ uri: e, changeTye: FileChangeType.Created }),
28+
this._onDidChangeEnvironmentVariables.fire({ uri: e, changeType: FileChangeType.Created }),
2929
),
3030
this.watcher.onDidChange((e) =>
31-
this._onDidChangeEnvironmentVariables.fire({ uri: e, changeTye: FileChangeType.Changed }),
31+
this._onDidChangeEnvironmentVariables.fire({ uri: e, changeType: FileChangeType.Changed }),
3232
),
3333
this.watcher.onDidDelete((e) =>
34-
this._onDidChangeEnvironmentVariables.fire({ uri: e, changeTye: FileChangeType.Deleted }),
34+
this._onDidChangeEnvironmentVariables.fire({ uri: e, changeType: FileChangeType.Deleted }),
3535
),
3636
);
3737
}
@@ -48,7 +48,7 @@ export class PythonEnvVariableManager implements EnvVarManager {
4848

4949
const config = getConfiguration('python', project?.uri ?? uri);
5050
let envFilePath = config.get<string>('envFile');
51-
envFilePath = envFilePath ? path.normalize(resolveVariables(envFilePath)) : undefined;
51+
envFilePath = envFilePath ? path.normalize(resolveVariables(envFilePath, uri)) : undefined;
5252

5353
if (envFilePath && (await fsapi.pathExists(envFilePath))) {
5454
const other = await parseEnvFile(Uri.file(envFilePath));

0 commit comments

Comments
 (0)