Skip to content
Merged
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
42 changes: 37 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"command": "python-envs.setEnvManager",
"title": "%python-envs.setEnvManager.title%",
"category": "Python",
"icon": "$(gear)"
"icon": "$(gear)",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.setPkgManager",
Expand Down Expand Up @@ -293,6 +294,22 @@
"command": "python-envs.addPythonProjectGivenResource",
"when": "false"
},
{
"command": "python-envs.setEnvManager",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.packages",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.set",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.setPkgManager",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.removePythonProject",
"when": "false"
Expand All @@ -307,7 +324,7 @@
},
{
"command": "python-envs.runAsTask",
"when": "true"
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.terminal.activate",
Expand Down Expand Up @@ -336,6 +353,18 @@
{
"command": "python-envs.revealProjectInExplorer",
"when": "false"
},
{
"command": "python-envs.createNewProjectFromTemplate",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.terminal.revertStartupScriptChanges",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.reportIssue",
"when": "config.python.useEnvironmentsExtension != false"
}
],
"view/item/context": [
Expand Down Expand Up @@ -477,7 +506,8 @@
{
"id": "python",
"title": "Python",
"icon": "files/logo.svg"
"icon": "files/logo.svg",
"when": "config.python.useEnvironmentsExtension != false"
}
]
},
Expand All @@ -487,13 +517,15 @@
"id": "python-projects",
"name": "Python Projects",
"icon": "files/logo.svg",
"contextualTitle": "Python Projects"
"contextualTitle": "Python Projects",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"id": "env-managers",
"name": "Environment Managers",
"icon": "files/logo.svg",
"contextualTitle": "Environment Managers"
"contextualTitle": "Environment Managers",
"when": "config.python.useEnvironmentsExtension != false"
}
]
},
Expand Down
42 changes: 29 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { commands, ExtensionContext, extensions, LogOutputChannel, Terminal, Uri, window, workspace } from 'vscode';
import { PythonEnvironment, PythonEnvironmentApi, PythonProjectCreator } from './api';
import { ensureCorrectVersion } from './common/extVersion';
import { registerLogger, traceError, traceInfo } from './common/logging';
import { registerLogger, traceError, traceInfo, traceWarn } from './common/logging';
import { clearPersistentState, setPersistentState } from './common/persistentState';
import { newProjectSelection } from './common/pickers/managers';
import { StopWatch } from './common/stopWatch';
Expand All @@ -15,6 +15,7 @@ import {
onDidChangeActiveTerminal,
onDidChangeTerminalShellIntegration,
} from './common/window.apis';
import { getConfiguration } from './common/workspace.apis';
import { createManagerReady } from './features/common/managerReady';
import { AutoFindProjects } from './features/creators/autoFindProjects';
import { ExistingProjects } from './features/creators/existingProjects';
Expand Down Expand Up @@ -66,6 +67,7 @@ import { EnvironmentManagers, ProjectCreators, PythonProjectManager } from './in
import { registerSystemPythonFeatures } from './managers/builtin/main';
import { SysPythonManager } from './managers/builtin/sysPythonManager';
import { createNativePythonFinder, NativePythonFinder } from './managers/common/nativePythonFinder';
import { IDisposable } from './managers/common/types';
import { registerCondaFeatures } from './managers/conda/main';
import { registerPoetryFeatures } from './managers/poetry/main';
import { registerPyenvFeatures } from './managers/pyenv/main';
Expand Down Expand Up @@ -148,19 +150,16 @@ async function collectEnvironmentInfo(
return info.join('\n');
}

export async function activate(context: ExtensionContext): Promise<PythonEnvironmentApi> {
const start = new StopWatch();

// Attempt to set setting of config.python.useEnvironmentsExtension to true
try {
const config = workspace.getConfiguration('python');
await config.update('useEnvironmentsExtension', true, true);
} catch (err) {
traceError(
'Failed to set config.python.useEnvironmentsExtension to true. Please do so manually in your user settings now to ensure the Python environment extension is enabled during upcoming experimentation.',
err,
export async function activate(context: ExtensionContext): Promise<PythonEnvironmentApi | undefined> {
const useEnvironmentsExtension = getConfiguration('python').get<boolean>('useEnvironmentsExtension', true);
if (!useEnvironmentsExtension) {
traceWarn(
'The Python environments extension has been disabled via a setting. If you would like to opt into using the extension, please add the following to your user settings (note that updating this setting requires a window reload afterwards):\n\n"python.useEnvironmentsExtension": true',
);
await deactivate(context);
return;
}
const start = new StopWatch();

// Logging should be set up before anything else.
const outputChannel: LogOutputChannel = createLogOutputChannel('Python Environments');
Expand Down Expand Up @@ -508,4 +507,21 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
return api;
}

export function deactivate() {}
export async function disposeAll(disposables: IDisposable[]): Promise<void> {
await Promise.all(
disposables.map(async (d) => {
try {
return Promise.resolve(d.dispose());
} catch (_err) {
// do nothing
}
return Promise.resolve();
}),
);
}

export async function deactivate(context: ExtensionContext) {
await disposeAll(context.subscriptions);
context.subscriptions.length = 0; // Clear subscriptions to prevent memory leaks
traceInfo('Python Environments extension deactivated.');
}
3 changes: 3 additions & 0 deletions src/managers/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ export interface Installable {
*/
readonly uri?: Uri;
}
export interface IDisposable {
dispose(): void | undefined | Promise<void>;
}