Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,10 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
sysPythonManager.resolve(sysMgr);
await Promise.all([
registerSystemPythonFeatures(nativeFinder, context.subscriptions, outputChannel, sysMgr),
registerCondaFeatures(nativeFinder, context.subscriptions, outputChannel),
registerPyenvFeatures(nativeFinder, context.subscriptions),
registerPipenvFeatures(nativeFinder, context.subscriptions),
registerPoetryFeatures(nativeFinder, context.subscriptions, outputChannel),
registerCondaFeatures(nativeFinder, context.subscriptions, outputChannel, projectManager),
registerPyenvFeatures(nativeFinder, context.subscriptions, projectManager),
registerPipenvFeatures(nativeFinder, context.subscriptions, projectManager),
registerPoetryFeatures(nativeFinder, context.subscriptions, outputChannel, projectManager),
shellStartupVarsMgr.initialize(),
]);

Expand Down Expand Up @@ -616,7 +616,7 @@ async function resolveDefaultInterpreter(

if (defaultInterpreterPath) {
const defaultManager = getConfiguration('python-envs').get<string>('defaultEnvManager', 'undefined');
traceInfo(`resolveDefaultInterpreter setting exists; found defaultEnvManager: ${defaultManager}`);
traceInfo(`resolveDefaultInterpreter setting exists; found defaultEnvManager: ${defaultManager}. `);
if (!defaultManager || defaultManager === 'ms-python.python:venv') {
try {
const resolved: NativeEnvInfo = await nativeFinder.resolve(defaultInterpreterPath);
Expand Down
14 changes: 13 additions & 1 deletion src/features/settings/settingHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,25 @@ function getSettings(
return undefined;
}

let DEFAULT_ENV_MANAGER_BROKEN = false;

export function setDefaultEnvManagerBroken(broken: boolean) {
DEFAULT_ENV_MANAGER_BROKEN = broken;
}
export function isDefaultEnvManagerBroken(): boolean {
return DEFAULT_ENV_MANAGER_BROKEN;
}

export function getDefaultEnvManagerSetting(wm: PythonProjectManager, scope?: Uri): string {
const config = workspace.getConfiguration('python-envs', scope);
const settings = getSettings(wm, config, scope);
if (settings && settings.envManager.length > 0) {
return settings.envManager;
}

if (isDefaultEnvManagerBroken()) {
traceInfo(`Default environment manager is broken, using system default: ${DEFAULT_ENV_MANAGER_ID}`);
return DEFAULT_ENV_MANAGER_ID;
}
const defaultManager = config.get<string>('defaultEnvManager');
if (defaultManager === undefined || defaultManager === null || defaultManager === '') {
traceError('No default environment manager set. Check setting python-envs.defaultEnvManager');
Expand Down
43 changes: 42 additions & 1 deletion src/managers/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as fs from 'fs-extra';
import path from 'path';
import { PythonCommandRunConfiguration, PythonEnvironment } from '../../api';
import { commands, ConfigurationTarget, window, workspace } from 'vscode';
import { PythonCommandRunConfiguration, PythonEnvironment, PythonEnvironmentApi } from '../../api';
import { isWindows } from '../../common/utils/platformUtils';
import { ShellConstants } from '../../features/common/shellConstants';
import { getDefaultEnvManagerSetting, setDefaultEnvManagerBroken } from '../../features/settings/settingHelpers';
import { PythonProjectManager } from '../../internal.api';
import { Installable } from './types';

export function noop() {
Expand Down Expand Up @@ -194,3 +197,41 @@ export async function getShellActivationCommands(binDir: string): Promise<{
shellDeactivation,
};
}

export async function notifyMissingManagerIfDefault(
managerId: string,
projectManager: PythonProjectManager,
api: PythonEnvironmentApi,
) {
const defaultEnvManager = getDefaultEnvManagerSetting(projectManager);
Comment thread
eleanorjboyd marked this conversation as resolved.
if (defaultEnvManager === managerId) {
setDefaultEnvManagerBroken(true);
await api.refreshEnvironments(undefined);
window
.showErrorMessage(
`The default environment manager is set to '${defaultEnvManager}', but the ${
Comment thread
eleanorjboyd marked this conversation as resolved.
Outdated
managerId.split(':')[1]
} executable could not be found.`,
'Reset setting',
'View setting',
'Close',
)
.then((selection) => {
if (selection === 'Reset setting') {
// Remove the setting from all scopes
const config = workspace.getConfiguration('python-envs');
const inspect = config.inspect('defaultEnvManager');
if (inspect?.workspaceValue !== undefined) {
// Remove from workspace settings
config.update('defaultEnvManager', undefined, ConfigurationTarget.Workspace);
} else if (inspect?.globalValue !== undefined) {
// Remove from user settings
config.update('defaultEnvManager', undefined, ConfigurationTarget.Global);
}
}
if (selection === 'View setting') {
commands.executeCommand('workbench.action.openSettings', 'python-envs.defaultEnvManager');
}
});
}
}
4 changes: 4 additions & 0 deletions src/managers/conda/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Disposable, LogOutputChannel } from 'vscode';
import { PythonEnvironmentApi } from '../../api';
import { traceInfo } from '../../common/logging';
import { getPythonApi } from '../../features/pythonApi';
import { PythonProjectManager } from '../../internal.api';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { notifyMissingManagerIfDefault } from '../common/utils';
import { CondaEnvManager } from './condaEnvManager';
import { CondaPackageManager } from './condaPackageManager';
import { CondaSourcingStatus, constructCondaSourcingStatus } from './condaSourcingUtils';
Expand All @@ -12,6 +14,7 @@ export async function registerCondaFeatures(
nativeFinder: NativePythonFinder,
disposables: Disposable[],
log: LogOutputChannel,
projectManager: PythonProjectManager,
): Promise<void> {
const api: PythonEnvironmentApi = await getPythonApi();

Expand All @@ -34,5 +37,6 @@ export async function registerCondaFeatures(
);
} catch (ex) {
traceInfo('Conda not found, turning off conda features.', ex);
await notifyMissingManagerIfDefault('ms-python.python:conda', projectManager, api);
}
}
7 changes: 6 additions & 1 deletion src/managers/pipenv/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { Disposable } from 'vscode';
import { PythonEnvironmentApi } from '../../api';
import { traceInfo } from '../../common/logging';
import { getPythonApi } from '../../features/pythonApi';
import { PythonProjectManager } from '../../internal.api';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { PipenvManager } from './pipenvManager';
import { getPipenv } from './pipenvUtils';

import { notifyMissingManagerIfDefault } from '../common/utils';

export async function registerPipenvFeatures(
nativeFinder: NativePythonFinder,
disposables: Disposable[],
projectManager: PythonProjectManager,
): Promise<void> {
const api: PythonEnvironmentApi = await getPythonApi();

Expand All @@ -17,12 +21,13 @@ export async function registerPipenvFeatures(

if (pipenv) {
const mgr = new PipenvManager(nativeFinder, api);

disposables.push(mgr, api.registerEnvironmentManager(mgr));
} else {
traceInfo('Pipenv not found, turning off pipenv features.');
await notifyMissingManagerIfDefault('ms-python.python:pipenv', projectManager, api);
}
} catch (ex) {
traceInfo('Pipenv not found, turning off pipenv features.', ex);
await notifyMissingManagerIfDefault('ms-python.python:pipenv', projectManager, api);
}
}
7 changes: 7 additions & 0 deletions src/managers/poetry/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Disposable, LogOutputChannel } from 'vscode';
import { PythonEnvironmentApi } from '../../api';
import { traceInfo } from '../../common/logging';
import { getPythonApi } from '../../features/pythonApi';
import { PythonProjectManager } from '../../internal.api';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { notifyMissingManagerIfDefault } from '../common/utils';
import { PoetryManager } from './poetryManager';
import { PoetryPackageManager } from './poetryPackageManager';
import { getPoetry, getPoetryVersion } from './poetryUtils';
Expand All @@ -11,6 +13,7 @@ export async function registerPoetryFeatures(
nativeFinder: NativePythonFinder,
disposables: Disposable[],
outputChannel: LogOutputChannel,
projectManager: PythonProjectManager,
): Promise<void> {
const api: PythonEnvironmentApi = await getPythonApi();

Expand All @@ -31,8 +34,12 @@ export async function registerPoetryFeatures(
api.registerEnvironmentManager(envManager),
api.registerPackageManager(pkgManager),
);
} else {
traceInfo('Poetry not found, turning off poetry features.');
await notifyMissingManagerIfDefault('ms-python.python:poetry', projectManager, api);
}
} catch (ex) {
traceInfo('Poetry not found, turning off poetry features.', ex);
await notifyMissingManagerIfDefault('ms-python.python:poetry', projectManager, api);
}
}
7 changes: 6 additions & 1 deletion src/managers/pyenv/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@ import { Disposable } from 'vscode';
import { PythonEnvironmentApi } from '../../api';
import { traceInfo } from '../../common/logging';
import { getPythonApi } from '../../features/pythonApi';
import { PythonProjectManager } from '../../internal.api';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { notifyMissingManagerIfDefault } from '../common/utils';
import { PyEnvManager } from './pyenvManager';
import { getPyenv } from './pyenvUtils';

export async function registerPyenvFeatures(
nativeFinder: NativePythonFinder,
disposables: Disposable[],
projectManager: PythonProjectManager,
): Promise<void> {
const api: PythonEnvironmentApi = await getPythonApi();

try {
const pyenv = await getPyenv(nativeFinder);

if (pyenv) {
const mgr = new PyEnvManager(nativeFinder, api);
disposables.push(mgr, api.registerEnvironmentManager(mgr));
} else {
traceInfo('Pyenv not found, turning off pyenv features.');
await notifyMissingManagerIfDefault('ms-python.python:pyenv', projectManager, api);
}
} catch (ex) {
traceInfo('Pyenv not found, turning off pyenv features.', ex);
await notifyMissingManagerIfDefault('ms-python.python:pyenv', projectManager, api);
}
}
Loading