Skip to content

Commit ed61d79

Browse files
authored
Add startup activation (#196)
Fixes #201 Fixes #200 Fixes #227 Fixes #231
1 parent 024e9b3 commit ed61d79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3052
-403
lines changed

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"request": "launch",
1212
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
1313
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
14-
"preLaunchTask": "${defaultBuildTask}"
14+
"preLaunchTask": "npm: watch"
1515
},
1616
{
1717
"name": "Unit Tests",
@@ -30,7 +30,7 @@
3030
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
3131
"skipFiles": ["<node_internals>/**"],
3232
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
33-
"preLaunchTask": "tasks: watch-tests"
33+
"preLaunchTask": "npm: watch-tests"
3434
},
3535
{
3636
"name": "Extension Tests",
@@ -41,7 +41,7 @@
4141
"--extensionTestsPath=${workspaceFolder}/out/test/"
4242
],
4343
"outFiles": ["${workspaceFolder}/out/**/*.js", "${workspaceFolder}/dist/**/*.js"],
44-
"preLaunchTask": "tasks: watch-tests"
44+
"preLaunchTask": "${defaultBuildTask}"
4545
}
4646
]
4747
}

.vscode/settings.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
"typescript.tsc.autoDetect": "off",
1313
"editor.formatOnSave": true,
1414
"[typescript]": {
15-
"editor.defaultFormatter": "esbenp.prettier-vscode"
15+
"editor.defaultFormatter": "esbenp.prettier-vscode",
16+
"editor.codeActionsOnSave": {
17+
"source.organizeImports": "explicit"
18+
}
1619
},
1720
"[python]": {
1821
"editor.defaultFormatter": "charliermarsh.ruff",
19-
"diffEditor.ignoreTrimWhitespace": false
22+
"diffEditor.ignoreTrimWhitespace": false,
23+
"editor.codeActionsOnSave": {
24+
"source.organizeImports": "explicit"
25+
}
2026
},
2127
"prettier.tabWidth": 4,
2228
"python-envs.defaultEnvManager": "ms-python.python:venv",

.vscode/tasks.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
"presentation": {
2626
"reveal": "never",
2727
"group": "watchers"
28-
},
29-
"group": "build"
28+
}
3029
},
3130
{
32-
"label": "tasks: watch-tests",
31+
"label": "tasks: build",
3332
"dependsOn": ["npm: watch", "npm: watch-tests"],
34-
"problemMatcher": []
33+
"problemMatcher": [],
34+
"presentation": {
35+
"reveal": "never",
36+
"group": "watchers"
37+
}
3538
},
3639
{
3740
"type": "npm",

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@
8686
"onExP",
8787
"preview"
8888
]
89+
},
90+
"python-envs.terminal.autoActivationType": {
91+
"type": "string",
92+
"markdownDescription": "%python-envs.terminal.autoActivationType.description%",
93+
"default": "command",
94+
"enum": [
95+
"command",
96+
"shellStartup",
97+
"off"
98+
],
99+
"markdownEnumDescriptions": [
100+
"%python-envs.terminal.autoActivationType.command%",
101+
"%python-envs.terminal.autoActivationType.shellStartup%",
102+
"%python-envs.terminal.autoActivationType.off%"
103+
],
104+
"scope": "machine"
89105
}
90106
}
91107
},
@@ -228,6 +244,12 @@
228244
"title": "%python-envs.copyProjectPath.title%",
229245
"category": "Python Envs",
230246
"icon": "$(copy)"
247+
},
248+
{
249+
"command": "python-envs.terminal.revertStartupScriptChanges",
250+
"title": "%python-envs.terminal.revertStartupScriptChanges.title%",
251+
"category": "Python Envs",
252+
"icon": "$(discard)"
231253
}
232254
],
233255
"menus": {

package.nls.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
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": "The type of activation to use when activating an environment in the terminal",
10+
"python-envs.terminal.autoActivationType.command": "Activation by executing a command in the terminal.",
11+
"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.",
12+
"python-envs.terminal.autoActivationType.off": "No automatic activation of environments.",
13+
"python-envs.terminal.revertStartupScriptChanges.title": "Revert Shell Startup Script Changes",
914
"python-envs.setEnvManager.title": "Set Environment Manager",
1015
"python-envs.setPkgManager.title": "Set Package Manager",
1116
"python-envs.addPythonProject.title": "Add Python Project",

src/common/command.api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { commands } from 'vscode';
3+
import { Disposable } from 'vscode-jsonrpc';
4+
5+
export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
6+
return commands.registerCommand(command, callback, thisArg);
7+
}
38

49
export function executeCommand<T = unknown>(command: string, ...rest: any[]): Thenable<T> {
510
return commands.executeCommand(command, ...rest);

src/common/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export namespace Commands {
2+
export const viewLogs = 'python-envs.viewLogs';
3+
}

src/common/errors/utils.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as stackTrace from 'stack-trace';
2-
import { commands, LogOutputChannel, window } from 'vscode';
2+
import { commands, LogOutputChannel } from 'vscode';
33
import { Common } from '../localize';
4+
import { showErrorMessage, showWarningMessage } from '../window.apis';
45

56
export function parseStack(ex: Error) {
67
if (ex.stack && Array.isArray(ex.stack)) {
@@ -10,8 +11,8 @@ export function parseStack(ex: Error) {
1011
return stackTrace.parse.call(stackTrace, ex);
1112
}
1213

13-
export async function showErrorMessage(message: string, log?: LogOutputChannel) {
14-
const result = await window.showErrorMessage(message, Common.viewLogs);
14+
export async function showErrorMessageWithLogs(message: string, log?: LogOutputChannel) {
15+
const result = await showErrorMessage(message, Common.viewLogs);
1516
if (result === Common.viewLogs) {
1617
if (log) {
1718
log.show();
@@ -21,8 +22,8 @@ export async function showErrorMessage(message: string, log?: LogOutputChannel)
2122
}
2223
}
2324

24-
export async function showWarningMessage(message: string, log?: LogOutputChannel) {
25-
const result = await window.showWarningMessage(message, Common.viewLogs);
25+
export async function showWarningMessageWithLogs(message: string, log?: LogOutputChannel) {
26+
const result = await showWarningMessage(message, Common.viewLogs);
2627
if (result === Common.viewLogs) {
2728
if (log) {
2829
log.show();

src/common/localize.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { l10n } from 'vscode';
2+
import { Commands } from './commands';
23

34
export namespace Common {
45
export const recommended = l10n.t('Recommended');
@@ -11,7 +12,9 @@ export namespace Common {
1112
export const viewLogs = l10n.t('View Logs');
1213
export const yes = l10n.t('Yes');
1314
export const no = l10n.t('No');
15+
export const ok = l10n.t('Ok');
1416
export const quickCreate = l10n.t('Quick Create');
17+
export const installPython = l10n.t('Install Python');
1518
}
1619

1720
export namespace Interpreter {
@@ -138,6 +141,11 @@ export namespace CondaStrings {
138141

139142
export const quickCreateCondaNoEnvRoot = l10n.t('No conda environment root found');
140143
export const quickCreateCondaNoName = l10n.t('Could not generate a name for env');
144+
145+
export const condaMissingPython = l10n.t('No Python found in the selected conda environment');
146+
export const condaMissingPythonNoFix = l10n.t(
147+
'No Python found in the selected conda environment. Please select another environment or install Python manually.',
148+
);
141149
}
142150

143151
export namespace ProjectCreatorString {
@@ -156,3 +164,11 @@ export namespace EnvViewStrings {
156164
export const selectedGlobalTooltip = l10n.t('This environment is selected for non-workspace files');
157165
export const selectedWorkspaceTooltip = l10n.t('This environment is selected for workspace files');
158166
}
167+
168+
export namespace ShellStartupActivationStrings {
169+
export const envCollectionDescription = l10n.t('Environment variables for shell activation');
170+
export const revertedShellStartupScripts = l10n.t(
171+
'Removed shell startup profile code for Python environment activation. See [logs](command:{0})',
172+
Commands.viewLogs,
173+
);
174+
}

src/common/pickers/environments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { IconPath, PythonEnvironment, PythonProject } from '../../api';
33
import { InternalEnvironmentManager } from '../../internal.api';
44
import { Common, Interpreter, Pickers } from '../localize';
55
import { showQuickPickWithButtons, showQuickPick, showOpenDialog, withProgress } from '../window.apis';
6-
import { isWindows } from '../../managers/common/utils';
76
import { traceError } from '../logging';
87
import { pickEnvironmentManager } from './managers';
98
import { handlePythonPath } from '../utils/pythonPath';
9+
import { isWindows } from '../utils/platformUtils';
1010

1111
type QuickPickIcon =
1212
| Uri

0 commit comments

Comments
 (0)