Skip to content
Draft
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
6 changes: 6 additions & 0 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ export namespace Interpreters {
export const terminalEnvVarCollectionPrompt = l10n.t(
'{0} environment was successfully activated, even though {1} indicator may not be present in the terminal prompt. [Learn more](https://aka.ms/vscodePythonTerminalActivation).',
);
export const shellIntegrationEnvVarCollectionDescription = l10n.t(
'Enables `python.terminal.shellIntegration.enabled` by modifying `PYTHONSTARTUP` and `PYTHON_BASIC_REPL`',
);
export const shellIntegrationDisabledEnvVarCollectionDescription = l10n.t(
'Disables `python.terminal.shellIntegration.enabled` by unsetting `PYTHONSTARTUP` and `PYTHON_BASIC_REPL`',
);
export const terminalDeactivateProgress = l10n.t('Editing {0}...');
export const restartingTerminal = l10n.t('Restarting terminal and deactivating...');
export const terminalDeactivatePrompt = l10n.t(
Expand Down
11 changes: 9 additions & 2 deletions src/client/terminals/pythonStartup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { ExtensionContext, Uri } from 'vscode';
import { ExtensionContext, MarkdownString, Uri } from 'vscode';
import * as path from 'path';
import { copy, createDirectory, getConfiguration, onDidChangeConfiguration } from '../common/vscodeApis/workspaceApis';
import { EXTENSION_ROOT_DIR } from '../constants';
import { Interpreters } from '../common/utils/localize';

async function applyPythonStartupSetting(context: ExtensionContext): Promise<void> {
const config = getConfiguration('python');
Expand All @@ -21,11 +22,17 @@ async function applyPythonStartupSetting(context: ExtensionContext): Promise<voi
const sourcePath = path.join(EXTENSION_ROOT_DIR, 'python_files', 'pythonrc.py');
await copy(Uri.file(sourcePath), destPath, { overwrite: true });
context.environmentVariableCollection.replace('PYTHONSTARTUP', destPath.fsPath);
// When shell integration is enabled, we disable PyREPL from cpython.
// When shell integration is enabled, we disable PyREPL from cpython.
context.environmentVariableCollection.replace('PYTHON_BASIC_REPL', '1');
context.environmentVariableCollection.description = new MarkdownString(
Interpreters.shellIntegrationEnvVarCollectionDescription,
);
Comment on lines 24 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also used here:

const envVarCollection = this.getEnvironmentVariableCollection({ workspaceFolder });
const pathVarName = getSearchPathEnvVarNames()[0];
envVarCollection.replace(
'PATH',
`${path.dirname(interpreter.path)}${path.delimiter}${process.env[pathVarName]}`,
{ applyAtShellIntegration: true, applyAtProcessCreation: true },
);
return;

There's meant to only be a single description to cover everything, but the above also uses scoped and I'm not sure how that interacts here.

} else {
context.environmentVariableCollection.delete('PYTHONSTARTUP');
context.environmentVariableCollection.delete('PYTHON_BASIC_REPL');
context.environmentVariableCollection.description = new MarkdownString(
Copy link
Author

@anthonykim1 anthonykim1 Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tyriar Not sure if Im doing something wrong here.. maybe this is bug in env collection??

I noticed when we remove the contribution to environment variable, it doesnt consider description if I try to set them:

Image

Weird bc description showed up when replacing these variable.. just not when deleting these variables.

Interpreters.shellIntegrationDisabledEnvVarCollectionDescription,
);
}
}

Expand Down
Loading