Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d7b1c18
feat: add setting `python-envs.terminal.autoActivationType`
karthiknadig Feb 4, 2025
83f4d71
feat: use the autoActivationType setting in terminal manager
karthiknadig Feb 8, 2025
bc99ff5
chore: rename 'startup' to 'shellStartup'
karthiknadig Feb 11, 2025
af803a7
chore: refactor move some utility functions to common location
karthiknadig Feb 11, 2025
cd334fb
chore: add `registerCommand` function helper
karthiknadig Feb 11, 2025
d96e256
feat: add powershell startup script update and remove helpers
karthiknadig Feb 11, 2025
c4bb298
feat: startup activation scaffolding
karthiknadig Feb 11, 2025
bf17486
feat: initial powershell startup provider
karthiknadig Feb 14, 2025
a410fd3
feat: add activation using shell startup
karthiknadig Feb 21, 2025
16a5b09
fix: tests
karthiknadig Feb 21, 2025
f603950
fix: powershell script update by querying `$profile`
karthiknadig Feb 26, 2025
ce3fe82
chore: refactor
karthiknadig Feb 27, 2025
6b250af
feat: add support for sh/bash/zsh startup
karthiknadig Mar 4, 2025
b9cfe9b
feat: add git-bash support
karthiknadig Mar 12, 2025
48a0b54
fix: shell type API
karthiknadig Mar 18, 2025
2888586
feat: Add fish and some fixes
karthiknadig Mar 20, 2025
83c44bd
feat: add `nu` shell support
karthiknadig Mar 20, 2025
19bb19e
feat: add support for `cmd` activate
karthiknadig Mar 20, 2025
888e5a5
chore: merge with main + API changes from main
karthiknadig Mar 20, 2025
ab99fff
fix: some improvement to cmd and reg edits
karthiknadig Mar 21, 2025
65a78dd
fix: cmd paths when registering
karthiknadig Mar 21, 2025
f3b5686
chore: fix launch.json config
karthiknadig Mar 21, 2025
78cf1b3
fix: bugs seen with a test run
karthiknadig Mar 21, 2025
798a7b6
fix: tweak startup script generation
karthiknadig Mar 24, 2025
1859eac
fix: only show shells that need startup update
karthiknadig Mar 24, 2025
6eddf61
fix: address some bug see with shell profile setup
karthiknadig Mar 24, 2025
7cba907
fix: powershell startup on posix
karthiknadig Mar 24, 2025
13f1c33
fix: naming of bash, gitbash, zsh and nu
karthiknadig Mar 24, 2025
121ab17
fix: nu shell profile path
karthiknadig Mar 25, 2025
2fc7584
fix: `nu` shell config detection and activation code
karthiknadig Mar 27, 2025
2b3521f
fix: add REG KEY to logs
karthiknadig Mar 28, 2025
d6c537a
fix: name for `Nushell`
karthiknadig Mar 28, 2025
e0be153
fix: update name of `Fish`
karthiknadig Mar 28, 2025
aa4bec7
fix: ensure logs for bash contain the specific shell name
karthiknadig Mar 28, 2025
f9596a6
chore: Remove `nu` shell support as it does not have `eval`
karthiknadig Apr 1, 2025
7d09952
fix: `cmd` bricked after shell startup
karthiknadig Apr 2, 2025
9d12855
chore: refactor midway
karthiknadig Apr 3, 2025
1dc64c3
fix: rebase with main
karthiknadig Apr 11, 2025
0224673
chore: refactor terminal shell code
karthiknadig Apr 11, 2025
f38f3c2
feat: add code to check, edit and restore shell scripts
karthiknadig Apr 11, 2025
c88460c
chore: use ShellConstants for shell name
karthiknadig Apr 11, 2025
ce2b6e5
chore: more refactoring
karthiknadig Apr 11, 2025
bded662
chore: more refactoring
karthiknadig Apr 11, 2025
d7c575a
fix: use 'command' activation strategy when 'shellStartup' activation…
karthiknadig Apr 11, 2025
0ea9bb9
fix: ensure everything compiles
karthiknadig Apr 11, 2025
94a6d3e
fix: shell detector tests
karthiknadig Apr 11, 2025
9839a78
fix: add more tests for edit utils
karthiknadig Apr 11, 2025
e9a31cb
Fix: Line endings when editing profiles
karthiknadig Apr 11, 2025
a5909ce
fix: after rebase
karthiknadig Apr 16, 2025
3f3d1ea
fix: remove promise for env variables
karthiknadig Apr 16, 2025
b0fe045
fix: add shell type to setup providers
karthiknadig Apr 16, 2025
cb3600e
fix: conda partial
karthiknadig Apr 16, 2025
d0f6e50
fix: improve no-python conda handling
karthiknadig Apr 17, 2025
757c808
fix: add markers to extract shell profile path
karthiknadig Apr 21, 2025
4d87451
fix: after rebase
karthiknadig Apr 23, 2025
5e91c4a
feat: add script version info
karthiknadig Apr 23, 2025
f6a5940
fix: remove notification after reverting shell startup scripts.
karthiknadig Apr 23, 2025
d41f45d
fix: add a info message indicating code is reverted
karthiknadig Apr 23, 2025
f4b60b6
chore: refactoring startup script update
karthiknadig Apr 23, 2025
74feffc
fix: improve shell startup profile update handling
karthiknadig Apr 24, 2025
f922863
fix: handle terminal on change to shell startup
karthiknadig Apr 24, 2025
8fa3a9e
fix: powershell special case
karthiknadig Apr 24, 2025
d902fb0
fix: cases when there are no shells reported
karthiknadig Apr 24, 2025
f95281b
fix: improve shell setup handling
karthiknadig Apr 24, 2025
24cc560
fix: some bugs with terminal shell activation
karthiknadig Apr 24, 2025
599a67f
chore: remove unused files
karthiknadig Apr 24, 2025
14f674c
chore: inputs from some ux tests
karthiknadig Apr 24, 2025
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: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"request": "launch",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
"preLaunchTask": "npm: watch"
},
{
"name": "Unit Tests",
Expand All @@ -30,7 +30,7 @@
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"skipFiles": ["<node_internals>/**"],
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
"preLaunchTask": "tasks: watch-tests"
"preLaunchTask": "npm: watch-tests"
},
{
"name": "Extension Tests",
Expand All @@ -41,7 +41,7 @@
"--extensionTestsPath=${workspaceFolder}/out/test/"
],
"outFiles": ["${workspaceFolder}/out/**/*.js", "${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "tasks: watch-tests"
"preLaunchTask": "${defaultBuildTask}"
}
]
}
10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
"typescript.tsc.autoDetect": "off",
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"diffEditor.ignoreTrimWhitespace": false
"diffEditor.ignoreTrimWhitespace": false,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"prettier.tabWidth": 4,
"python-envs.defaultEnvManager": "ms-python.python:venv",
Expand Down
11 changes: 7 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": "build"
}
},
{
"label": "tasks: watch-tests",
"label": "tasks: build",
"dependsOn": ["npm: watch", "npm: watch-tests"],
"problemMatcher": []
"problemMatcher": [],
"presentation": {
"reveal": "never",
"group": "watchers"
}
},
{
"type": "npm",
Expand Down
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@
"onExP",
"preview"
]
},
"python-envs.terminal.autoActivationType": {
"type": "string",
"markdownDescription": "%python-envs.terminal.autoActivationType.description%",
"default": "command",
"enum": [
"command",
"shellStartup",
"off"
],
"markdownEnumDescriptions": [
"%python-envs.terminal.autoActivationType.command%",
"%python-envs.terminal.autoActivationType.shellStartup%",
"%python-envs.terminal.autoActivationType.off%"
],
"scope": "machine"
}
}
},
Expand Down Expand Up @@ -228,6 +244,12 @@
"title": "%python-envs.copyProjectPath.title%",
"category": "Python Envs",
"icon": "$(copy)"
},
{
"command": "python-envs.terminal.revertStartupScriptChanges",
"title": "%python-envs.terminal.revertStartupScriptChanges.title%",
"category": "Python Envs",
"icon": "$(discard)"
}
],
"menus": {
Expand Down
5 changes: 5 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"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": "The type of activation to use when activating an environment in the terminal",
"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.",
"python-envs.terminal.revertStartupScriptChanges.title": "Revert Shell Startup Script Changes",
"python-envs.setEnvManager.title": "Set Environment Manager",
"python-envs.setPkgManager.title": "Set Package Manager",
"python-envs.addPythonProject.title": "Add Python Project",
Expand Down
5 changes: 5 additions & 0 deletions src/common/command.api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { commands } from 'vscode';
import { Disposable } from 'vscode-jsonrpc';

export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
return commands.registerCommand(command, callback, thisArg);
}

export function executeCommand<T = unknown>(command: string, ...rest: any[]): Thenable<T> {
return commands.executeCommand(command, ...rest);
Expand Down
3 changes: 3 additions & 0 deletions src/common/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export namespace Commands {
export const viewLogs = 'python-envs.viewLogs';
}
11 changes: 6 additions & 5 deletions src/common/errors/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as stackTrace from 'stack-trace';
import { commands, LogOutputChannel, window } from 'vscode';
import { commands, LogOutputChannel } from 'vscode';
import { Common } from '../localize';
import { showErrorMessage, showWarningMessage } from '../window.apis';

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

export async function showErrorMessage(message: string, log?: LogOutputChannel) {
const result = await window.showErrorMessage(message, Common.viewLogs);
export async function showErrorMessageWithLogs(message: string, log?: LogOutputChannel) {
const result = await showErrorMessage(message, Common.viewLogs);
if (result === Common.viewLogs) {
if (log) {
log.show();
Expand All @@ -21,8 +22,8 @@ export async function showErrorMessage(message: string, log?: LogOutputChannel)
}
}

export async function showWarningMessage(message: string, log?: LogOutputChannel) {
const result = await window.showWarningMessage(message, Common.viewLogs);
export async function showWarningMessageWithLogs(message: string, log?: LogOutputChannel) {
const result = await showWarningMessage(message, Common.viewLogs);
if (result === Common.viewLogs) {
if (log) {
log.show();
Expand Down
16 changes: 16 additions & 0 deletions src/common/localize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { l10n } from 'vscode';
import { Commands } from './commands';

export namespace Common {
export const recommended = l10n.t('Recommended');
Expand All @@ -11,7 +12,9 @@ export namespace Common {
export const viewLogs = l10n.t('View Logs');
export const yes = l10n.t('Yes');
export const no = l10n.t('No');
export const ok = l10n.t('Ok');
export const quickCreate = l10n.t('Quick Create');
export const installPython = l10n.t('Install Python');
}

export namespace Interpreter {
Expand Down Expand Up @@ -138,6 +141,11 @@ export namespace CondaStrings {

export const quickCreateCondaNoEnvRoot = l10n.t('No conda environment root found');
export const quickCreateCondaNoName = l10n.t('Could not generate a name for env');

export const condaMissingPython = l10n.t('No Python found in the selected conda environment');
export const condaMissingPythonNoFix = l10n.t(
'No Python found in the selected conda environment. Please select another environment or install Python manually.',
);
}

export namespace ProjectCreatorString {
Expand All @@ -156,3 +164,11 @@ export namespace EnvViewStrings {
export const selectedGlobalTooltip = l10n.t('This environment is selected for non-workspace files');
export const selectedWorkspaceTooltip = l10n.t('This environment is selected for workspace files');
}

export namespace ShellStartupActivationStrings {
export const envCollectionDescription = l10n.t('Environment variables for shell activation');
export const revertedShellStartupScripts = l10n.t(
'Removed shell startup profile code for Python environment activation. See [logs](command:{0})',
Commands.viewLogs,
);
}
2 changes: 1 addition & 1 deletion src/common/pickers/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { IconPath, PythonEnvironment, PythonProject } from '../../api';
import { InternalEnvironmentManager } from '../../internal.api';
import { Common, Interpreter, Pickers } from '../localize';
import { showQuickPickWithButtons, showQuickPick, showOpenDialog, withProgress } from '../window.apis';
import { isWindows } from '../../managers/common/utils';
import { traceError } from '../logging';
import { pickEnvironmentManager } from './managers';
import { handlePythonPath } from '../utils/pythonPath';
import { isWindows } from '../utils/platformUtils';

type QuickPickIcon =
| Uri
Expand Down
11 changes: 10 additions & 1 deletion src/common/utils/pathUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as os from 'os';
import * as path from 'path';
import { Uri } from 'vscode';
import { isWindows } from '../../managers/common/utils';
import { isWindows } from './platformUtils';

export function checkUri(scope?: Uri | Uri[] | string): Uri | Uri[] | string | undefined {
if (scope instanceof Uri) {
Expand Down Expand Up @@ -48,3 +49,11 @@ export function getResourceUri(resourcePath: string, root?: string): Uri | undef
return undefined;
}
}

export function untildify(path: string): string {
return path.replace(/^~($|\/|\\)/, `${os.homedir()}$1`);
}

export function getUserHomeDir(): string {
return os.homedir();
}
3 changes: 3 additions & 0 deletions src/common/utils/platformUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isWindows(): boolean {
return process.platform === 'win32';
}
2 changes: 1 addition & 1 deletion src/common/utils/pythonPath.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Uri, Progress, CancellationToken } from 'vscode';
import { PythonEnvironment } from '../../api';
import { InternalEnvironmentManager } from '../../internal.api';
import { showErrorMessage } from '../errors/utils';
import { traceVerbose, traceError } from '../logging';
import { PYTHON_EXTENSION_ID } from '../constants';
import { showErrorMessage } from '../window.apis';

const priorityOrder = [
`${PYTHON_EXTENSION_ID}:pyenv`,
Expand Down
39 changes: 39 additions & 0 deletions src/common/window.apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
TextEditor,
Uri,
window,
WindowState,
} from 'vscode';
import { createDeferred } from './utils/deferred';

Expand Down Expand Up @@ -286,6 +287,36 @@ export async function showInputBoxWithButtons(
}
}

export function showInformationMessage<T extends string>(message: string, ...items: T[]): Thenable<T | undefined>;
export function showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;
export function showInformationMessage<T extends string>(
message: string,
options: MessageOptions,
...items: T[]
): Thenable<T | undefined>;
export function showInformationMessage<T extends MessageItem>(
message: string,
options: MessageOptions,
...items: T[]
): Thenable<T | undefined> {
return window.showInformationMessage(message, options, ...items);
}

export function showErrorMessage<T extends string>(message: string, ...items: T[]): Thenable<T | undefined>;
export function showErrorMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;
export function showErrorMessage<T extends string>(
message: string,
options: MessageOptions,
...items: T[]
): Thenable<T | undefined>;
export function showErrorMessage<T extends MessageItem>(
message: string,
options: MessageOptions,
...items: T[]
): Thenable<T | undefined> {
return window.showErrorMessage(message, options, ...items);
}

export function showWarningMessage<T extends string>(message: string, ...items: T[]): Thenable<T | undefined>;
export function showWarningMessage<T extends string>(
message: string,
Expand Down Expand Up @@ -317,3 +348,11 @@ export function createLogOutputChannel(name: string): LogOutputChannel {
export function registerFileDecorationProvider(provider: FileDecorationProvider): Disposable {
return window.registerFileDecorationProvider(provider);
}

export function onDidChangeWindowState(
listener: (e: WindowState) => any,
thisArgs?: any,
disposables?: Disposable[],
): Disposable {
return window.onDidChangeWindowState(listener, thisArgs, disposables);
}
Loading