Skip to content

Commit 1c3c2eb

Browse files
committed
REF: Centralize manager ids
1 parent 86c5747 commit 1c3c2eb

43 files changed

Lines changed: 415 additions & 385 deletions

Some content is hidden

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

‎src/common/constants.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@ import * as path from 'path';
33
export const ENVS_EXTENSION_ID = 'ms-python.vscode-python-envs';
44
export const PYTHON_EXTENSION_ID = 'ms-python.python';
55
export const PYLANCE_EXTENSION_ID = 'ms-python.vscode-pylance';
6+
7+
// Manager IDs
68
export const CONDA_MANAGER_ID = `${PYTHON_EXTENSION_ID}:conda`;
79
export const INLINE_SCRIPT_MANAGER_ID = `${PYTHON_EXTENSION_ID}:inline-script`;
810
export const INLINE_SCRIPT_ENVS_KEY = `${ENVS_EXTENSION_ID}:inline-script:SCRIPT_ENVIRONMENTS`;
911
export const PYENV_MANAGER_ID = `${PYTHON_EXTENSION_ID}:pyenv`;
10-
export const JUPYTER_EXTENSION_ID = 'ms-toolsai.jupyter';
11-
export const EXTENSION_ROOT_DIR = path.dirname(__dirname);
12-
export const ISSUES_URL = 'https://github.com/microsoft/vscode-python-environments/issues';
12+
export const PIPENV_MANAGER_ID = `${PYTHON_EXTENSION_ID}:pipenv`;
13+
export const POETRY_MANAGER_ID = `${PYTHON_EXTENSION_ID}:poetry`;
14+
export const PIXI_MANAGER_ID = `${PYTHON_EXTENSION_ID}:pixi`;
15+
export const HATCH_MANAGER_ID = `${PYTHON_EXTENSION_ID}:hatch`;
1316

1417
export const DEFAULT_PACKAGE_MANAGER_ID = 'ms-python.python:pip';
1518
export const DEFAULT_ENV_MANAGER_ID = 'ms-python.python:venv';
1619
export const VENV_MANAGER_ID = 'ms-python.python:venv';
1720
export const SYSTEM_MANAGER_ID = 'ms-python.python:system';
1821

22+
export const JUPYTER_EXTENSION_ID = 'ms-toolsai.jupyter';
23+
export const EXTENSION_ROOT_DIR = path.dirname(__dirname);
24+
export const ISSUES_URL = 'https://github.com/microsoft/vscode-python-environments/issues';
25+
1926
export const KNOWN_FILES = [
2027
'requirements.txt',
2128
'requirements.in',

‎src/common/utils/pythonPath.ts‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
import { CancellationToken, Progress, Uri } from 'vscode';
22
import { PythonEnvironment } from '../../api';
33
import type { InternalEnvironmentManager } from '../../managers/common/registeredManagers';
4-
import { PYTHON_EXTENSION_ID } from '../constants';
4+
import {
5+
CONDA_MANAGER_ID,
6+
HATCH_MANAGER_ID,
7+
PIPENV_MANAGER_ID,
8+
PIXI_MANAGER_ID,
9+
POETRY_MANAGER_ID,
10+
PYENV_MANAGER_ID,
11+
PYTHON_EXTENSION_ID,
12+
SYSTEM_MANAGER_ID,
13+
VENV_MANAGER_ID,
14+
} from '../constants';
515
import { traceVerbose, traceWarn } from '../logging';
616

717
const priorityOrder = [
8-
`${PYTHON_EXTENSION_ID}:pyenv`,
9-
`${PYTHON_EXTENSION_ID}:pixi`,
10-
`${PYTHON_EXTENSION_ID}:conda`,
11-
`${PYTHON_EXTENSION_ID}:pipenv`,
12-
`${PYTHON_EXTENSION_ID}:poetry`,
18+
PYENV_MANAGER_ID,
19+
PIXI_MANAGER_ID,
20+
CONDA_MANAGER_ID,
21+
PIPENV_MANAGER_ID,
22+
POETRY_MANAGER_ID,
1323
`${PYTHON_EXTENSION_ID}:activestate`,
14-
`${PYTHON_EXTENSION_ID}:hatch`,
15-
`${PYTHON_EXTENSION_ID}:venv`,
16-
`${PYTHON_EXTENSION_ID}:system`,
24+
HATCH_MANAGER_ID,
25+
VENV_MANAGER_ID,
26+
SYSTEM_MANAGER_ID,
1727
];
1828
function sortManagersByPriority(managers: InternalEnvironmentManager[]): InternalEnvironmentManager[] {
1929
const systemId = priorityOrder[priorityOrder.length - 1];

‎src/features/creators/creationHelpers.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { traceError, traceVerbose } from '../../common/logging';
66
import { showQuickPickWithButtons } from '../../common/window.apis';
77
import type { EnvironmentManagers } from '../envManagers';
88
import type { InternalEnvironmentManager } from '../../managers/common/registeredManagers';
9+
import { VENV_MANAGER_ID } from '../../common/constants';
910

1011
/**
1112
* Prompts the user to choose whether to create a new virtual environment (venv) for a project, with a clearer return and early exit.
@@ -74,7 +75,7 @@ export async function promptForCopilotInstructions(): Promise<boolean | undefine
7475
export async function quickCreateNewVenv(envManagers: EnvironmentManagers, destFolder: string) {
7576
// get the environment manager for venv, should always exist
7677
const envManager: InternalEnvironmentManager | undefined = envManagers.managers.find(
77-
(m) => m.id === 'ms-python.python:venv',
78+
(m) => m.id === VENV_MANAGER_ID,
7879
);
7980
const destinationUri = Uri.parse(destFolder);
8081
if (envManager?.supportsQuickCreate) {

‎src/features/creators/newPackageProject.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
22
import * as path from 'path';
33
import { commands, l10n, MarkdownString, QuickInputButtons, Uri, window, workspace } from 'vscode';
44
import { PythonEnvironment, PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
5-
import { NEW_PROJECT_TEMPLATES_FOLDER } from '../../common/constants';
5+
import { NEW_PROJECT_TEMPLATES_FOLDER, VENV_MANAGER_ID } from '../../common/constants';
66
import { traceError } from '../../common/logging';
77
import { showInputBoxWithButtons } from '../../common/window.apis';
88
import type { EnvironmentManagers } from '../envManagers';
@@ -134,7 +134,7 @@ export class NewPackageProject implements PythonProjectCreator {
134134
} else {
135135
// get venv manager or any manager that supports quick creating environments
136136
const venvManager = this.envManagers.managers.find(
137-
(m) => m.id === 'ms-python.python:venv' || m.supportsQuickCreate,
137+
(m) => m.id === VENV_MANAGER_ID || m.supportsQuickCreate,
138138
);
139139
if (venvManager) {
140140
createdEnv = await venvManager.create(Uri.file(projectDestinationFolder), {

‎src/managers/builtin/inlineScript/envManager.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ import {
3535
SetEnvironmentScope,
3636
} from '../../../api';
3737
import { Capabilities, EnvironmentManagerCapability, supportedCapability, EnvironmentCapability } from '../../../capabilities';
38-
import {
39-
CONDA_MANAGER_ID,
40-
INLINE_SCRIPT_MANAGER_ID,
41-
PYENV_MANAGER_ID,
42-
SYSTEM_MANAGER_ID,
43-
} from '../../../common/constants';
38+
import { CONDA_MANAGER_ID, INLINE_SCRIPT_MANAGER_ID, PYENV_MANAGER_ID, SYSTEM_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID } from '../../../common/constants';
4439
import { getErrorMessage } from '../../../common/errors/utils';
4540
import { computeCacheKey, normalizeDependency } from '../../../common/inlineScript/cacheKey';
4641
import { InlineScriptEnvironmentModifiedError } from '../../../common/inlineScript/errors';
@@ -362,7 +357,7 @@ export class InlineScriptEnvManager implements EnvironmentManager, Disposable {
362357

363358
public readonly name = 'inline-script';
364359
public readonly displayName = l10n.t('Inline scripts');
365-
public readonly preferredPackageManagerId = 'ms-python.python:pip';
360+
public readonly preferredPackageManagerId = DEFAULT_PACKAGE_MANAGER_ID;
366361
public readonly description: string | undefined = undefined;
367362
public readonly tooltip: string | MarkdownString = new MarkdownString(
368363
l10n.t('Environments built from PEP 723 inline script metadata.'),

‎src/managers/builtin/sysPythonManager.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from './cache';
3636
import { getDefaultGlobalPython, refreshPythons, resolveSystemPythonEnvironmentPath } from './utils';
3737
import { installPythonWithUv, promptInstallPythonViaUv, selectPythonVersionToInstall } from './uvPythonInstaller';
38+
import { DEFAULT_PACKAGE_MANAGER_ID } from '../../common/constants';
3839

3940
export class SysPythonManager implements EnvironmentManager {
4041
readonly capabilities: Capabilities<EnvironmentManagerCapability> = {
@@ -73,7 +74,7 @@ export class SysPythonManager implements EnvironmentManager {
7374
) {
7475
this.name = 'system';
7576
this.displayName = 'Global';
76-
this.preferredPackageManagerId = 'ms-python.python:pip';
77+
this.preferredPackageManagerId = DEFAULT_PACKAGE_MANAGER_ID;
7778
this.description = undefined;
7879
this.tooltip = new MarkdownString(SysManagerStrings.sysManagerDescription, true);
7980
this.iconPath = new ThemeIcon('globe');

‎src/managers/builtin/venvManager.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
} from '../../api';
3232
import { Capabilities, EnvironmentManagerCapability, supportedCapability, EnvironmentCapability } from '../../capabilities';
3333
import { executeCommand } from '../../common/command.api';
34-
import { PYTHON_EXTENSION_ID } from '../../common/constants';
34+
import { DEFAULT_PACKAGE_MANAGER_ID, VENV_MANAGER_ID } from '../../common/constants';
3535
import { VenvManagerStrings } from '../../common/localize';
3636
import { traceError, traceWarn } from '../../common/logging';
3737
import { createDeferred, Deferred } from '../../common/utils/deferred';
@@ -111,7 +111,7 @@ export class VenvManager implements EnvironmentManager {
111111
// https://github.com/microsoft/vscode-python-environments/issues/167
112112
this.description = undefined;
113113
this.tooltip = new MarkdownString(VenvManagerStrings.venvManagerDescription, true);
114-
this.preferredPackageManagerId = 'ms-python.python:pip';
114+
this.preferredPackageManagerId = DEFAULT_PACKAGE_MANAGER_ID;
115115
this.iconPath = new ThemeIcon('python');
116116
}
117117

@@ -675,7 +675,7 @@ export class VenvManager implements EnvironmentManager {
675675
this.baseManager,
676676
);
677677
if (resolved) {
678-
if (resolved.envId.managerId === `${PYTHON_EXTENSION_ID}:venv`) {
678+
if (resolved.envId.managerId === VENV_MANAGER_ID) {
679679
// We should only return the resolved env if it is a venv.
680680
// Fall through an return undefined if it is not a venv
681681
this.addEnvironment(resolved, true);

‎src/managers/conda/condaEnvManager.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import {
7070
setCondaForWorkspace,
7171
setCondaForWorkspaces,
7272
} from './condaUtils';
73+
import { CONDA_MANAGER_ID } from '../../common/constants';
7374

7475
export class CondaEnvManager implements EnvironmentManager, Disposable {
7576
readonly capabilities: Capabilities<EnvironmentManagerCapability> = {
@@ -101,7 +102,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
101102
) {
102103
this.name = 'conda';
103104
this.displayName = 'Conda';
104-
this.preferredPackageManagerId = 'ms-python.python:conda';
105+
this.preferredPackageManagerId = CONDA_MANAGER_ID;
105106
this.tooltip = new MarkdownString(CondaStrings.condaManager, true);
106107
}
107108

@@ -250,7 +251,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
250251
result = 'tool_not_found';
251252
traceInfo('Conda not found, conda features will be inactive.');
252253
if (this.projectManager) {
253-
await notifyMissingManagerIfDefault('ms-python.python:conda', this.projectManager, this.api);
254+
await notifyMissingManagerIfDefault(CONDA_MANAGER_ID, this.projectManager, this.api);
254255
}
255256
} else if (condaTool) {
256257
// Conda was found — populate sourcing information for activation/shell support.

‎src/managers/pipenv/pipenvManager.ts‎

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ import {
1616
ResolveEnvironmentContext,
1717
SetEnvironmentScope,
1818
} from '../../api';
19-
import { Capabilities, EnvironmentManagerCapability, supportedCapability, EnvironmentCapability } from '../../capabilities';
19+
import {
20+
Capabilities,
21+
EnvironmentCapability,
22+
EnvironmentManagerCapability,
23+
supportedCapability,
24+
} from '../../capabilities';
25+
import { PIPENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID } from '../../common/constants';
2026
import { PipenvStrings } from '../../common/localize';
2127
import { traceError, traceInfo } from '../../common/logging';
2228
import { StopWatch } from '../../common/stopWatch';
@@ -28,14 +34,14 @@ import { normalizePath } from '../../common/utils/pathUtils';
2834
import { withProgress } from '../../common/window.apis';
2935
import { getConfiguration } from '../../common/workspace.apis';
3036
import type { PythonProjectManager } from '../../features/projectManager';
31-
import { getProjectFsPathForScope, tryFastPathGet } from '../common/fastPath';
32-
import { NativePythonEnvironmentKind, NativePythonFinder } from '../common/nativePythonFinder';
33-
import { notifyMissingManagerIfDefault } from '../common/utils';
3437
import {
3538
EnvironmentToolSupport,
3639
pythonToolSupport,
3740
resolveToolProjectEnvironment,
3841
} from '../../internal/pythonToolSupport';
42+
import { getProjectFsPathForScope, tryFastPathGet } from '../common/fastPath';
43+
import { NativePythonEnvironmentKind, NativePythonFinder } from '../common/nativePythonFinder';
44+
import { notifyMissingManagerIfDefault } from '../common/utils';
3945
import {
4046
clearPipenvCache,
4147
getPipenv,
@@ -91,7 +97,7 @@ export class PipenvManager implements EnvironmentManager, Disposable {
9197
) {
9298
this.name = 'pipenv';
9399
this.displayName = 'Pipenv';
94-
this.preferredPackageManagerId = 'ms-python.python:pip';
100+
this.preferredPackageManagerId = DEFAULT_PACKAGE_MANAGER_ID;
95101
this.tooltip = new MarkdownString(PipenvStrings.pipenvManager, true);
96102
}
97103

@@ -161,7 +167,7 @@ export class PipenvManager implements EnvironmentManager, Disposable {
161167
if (toolSource === 'none') {
162168
result = 'tool_not_found';
163169
if (this.projectManager) {
164-
await notifyMissingManagerIfDefault('ms-python.python:pipenv', this.projectManager, this.api);
170+
await notifyMissingManagerIfDefault(PIPENV_MANAGER_ID, this.projectManager, this.api);
165171
}
166172
}
167173
} catch (ex) {
@@ -369,18 +375,20 @@ export class PipenvManager implements EnvironmentManager, Disposable {
369375
}
370376

371377
async get(scope: GetEnvironmentScope, toolExecution = false): Promise<PythonEnvironment | undefined> {
372-
const fastResult = toolExecution ? undefined : await tryFastPathGet({
373-
initialized: this._initialized,
374-
setInitialized: (deferred) => {
375-
this._initialized = deferred;
376-
},
377-
scope,
378-
label: 'pipenv',
379-
getProjectFsPath: (s) => getProjectFsPathForScope(this.api, s),
380-
getPersistedPath: (fsPath) => getPipenvForWorkspace(fsPath),
381-
resolve: (p) => resolvePipenvPath(p, this.nativeFinder, this.api, this),
382-
startBackgroundInit: () => this.initializeDiscovery(),
383-
});
378+
const fastResult = toolExecution
379+
? undefined
380+
: await tryFastPathGet({
381+
initialized: this._initialized,
382+
setInitialized: (deferred) => {
383+
this._initialized = deferred;
384+
},
385+
scope,
386+
label: 'pipenv',
387+
getProjectFsPath: (s) => getProjectFsPathForScope(this.api, s),
388+
getPersistedPath: (fsPath) => getPipenvForWorkspace(fsPath),
389+
resolve: (p) => resolvePipenvPath(p, this.nativeFinder, this.api, this),
390+
startBackgroundInit: () => this.initializeDiscovery(),
391+
});
384392
if (fastResult) {
385393
return fastResult.env;
386394
}

‎src/managers/pipenv/pipenvUtils.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
PythonEnvironmentInfo,
1515
} from '../../api';
1616
import { execProcess } from '../../common/childProcess.apis';
17-
import { ENVS_EXTENSION_ID } from '../../common/constants';
17+
import { PIPENV_MANAGER_ID } from '../../common/constants';
1818
import { traceError, traceInfo, traceVerbose } from '../../common/logging';
1919
import { getWorkspacePersistentState } from '../../common/persistentState';
2020
import { untildify } from '../../common/utils/pathUtils';
@@ -28,9 +28,9 @@ import {
2828
} from '../common/nativePythonFinder';
2929
import { getShellActivationCommands, shortenVersionString } from '../common/utils';
3030

31-
export const PIPENV_PATH_KEY = `${ENVS_EXTENSION_ID}:pipenv:PIPENV_PATH`;
32-
export const PIPENV_WORKSPACE_KEY = `${ENVS_EXTENSION_ID}:pipenv:WORKSPACE_SELECTED`;
33-
export const PIPENV_GLOBAL_KEY = `${ENVS_EXTENSION_ID}:pipenv:GLOBAL_SELECTED`;
31+
export const PIPENV_PATH_KEY = `${PIPENV_MANAGER_ID}:PIPENV_PATH`;
32+
export const PIPENV_WORKSPACE_KEY = `${PIPENV_MANAGER_ID}:WORKSPACE_SELECTED`;
33+
export const PIPENV_GLOBAL_KEY = `${PIPENV_MANAGER_ID}:GLOBAL_SELECTED`;
3434

3535
let pipenvPath: string | undefined;
3636

0 commit comments

Comments
 (0)