Skip to content
Closed
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
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@
"category": "Python",
"icon": "$(trash)"
},
{
"command": "python-envs.clearInlineScriptCache",
"title": "%python-envs.clearInlineScriptCache.title%",
"category": "Python",
"icon": "$(trash)",
"enablement": "config.python.useEnvironmentsExtension != false && config.python-envs.inlineScripts.enabled == true"
},
{
"command": "python-envs.runInTerminal",
"title": "%python-envs.runInTerminal.title%",
Expand Down Expand Up @@ -414,6 +421,10 @@
"command": "python-envs.runAsTask",
"when": "config.python.useEnvironmentsExtension != false"
},
{
"command": "python-envs.clearInlineScriptCache",
"when": "config.python.useEnvironmentsExtension != false && config.python-envs.inlineScripts.enabled == true"
},
{
"command": "python-envs.terminal.activate",
"when": "pythonTerminalActivation"
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"python-envs.refreshPackages.title": "Refresh Packages List",
"python-envs.packages.title": "Manage Packages",
"python-envs.clearCache.title": "Clear Cache",
"python-envs.clearInlineScriptCache.title": "Clear Script Environment Cache",
"python-envs.runInTerminal.title": "Run in Terminal",
"python-envs.createTerminal.title": "Create Python Terminal",
"python-envs.runAsTask.title": "Run as Task",
Expand Down
29 changes: 18 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { PythonEnvironment, PythonEnvironmentApi, PythonProjectCreator } from '.
import { ENVS_EXTENSION_ID } from './common/constants';
import { ensureCorrectVersion } from './common/extVersion';
import { registerLogger, traceError, traceInfo, traceWarn } from './common/logging';
import { clearPersistentState, setPersistentState } from './common/persistentState';
import { setPersistentState } from './common/persistentState';
import { newProjectSelection } from './common/pickers/managers';
import { StopWatch } from './common/stopWatch';
import { EventNames } from './common/telemetry/constants';
Expand Down Expand Up @@ -44,6 +44,8 @@ import { NewScriptProject } from './features/creators/newScriptProject';
import { ProjectCreatorsImpl } from './features/creators/projectCreators';
import {
addPythonProjectCommand,
clearCacheCommand,
clearInlineScriptCacheCommand,
copyPathToClipboard,
createAnyEnvironmentCommand,
createEnvironmentCommand,
Expand Down Expand Up @@ -96,6 +98,7 @@ import { TemporaryStateManager } from './features/views/temporaryStateManager';
import { PythonEnvTreeItem } from './features/views/treeViewItems';
import { collectEnvironmentInfo, getEnvManagerAndPackageManagerConfigLevels, runPetInTerminalImpl } from './helpers';
import { EnvironmentManagers, ProjectCreators, PythonProjectManager } from './internal.api';
import type { InlineScriptEnvManager } from './managers/builtin/inlineScript/envManager';
import { registerInlineScriptFeatures } from './managers/builtin/inlineScript/main';
import { registerSystemPythonFeatures } from './managers/builtin/main';
import { SysPythonManager } from './managers/builtin/sysPythonManager';
Expand Down Expand Up @@ -191,6 +194,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
const terminalActivation = new TerminalActivationImpl();
const shellEnvsProviders = createShellEnvProviders();
const shellStartupProviders = createShellStartupProviders();
let inlineScriptEnvManager: InlineScriptEnvManager | undefined;

const terminalManager: TerminalManager = new TerminalManagerImpl(
terminalActivation,
Expand Down Expand Up @@ -367,9 +371,10 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
await removePythonProject(item, projectManager, envManagers);
}),
commands.registerCommand('python-envs.clearCache', async () => {
await clearPersistentState();
await envManagers.clearCache(undefined);
await clearShellProfileCache(shellStartupProviders);
await clearCacheCommand(envManagers, () => clearShellProfileCache(shellStartupProviders));
}),
commands.registerCommand('python-envs.clearInlineScriptCache', async () => {
await clearInlineScriptCacheCommand(() => inlineScriptEnvManager);
}),
commands.registerCommand('python-envs.runInTerminal', (item) => {
return runInTerminalCommand(item, api, terminalManager);
Expand Down Expand Up @@ -651,13 +656,15 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
),
safeRegister(
'inlineScript',
registerInlineScriptFeatures(
nativeFinder,
context.subscriptions,
outputChannel,
sysMgr,
context.globalStorageUri,
),
(async () => {
inlineScriptEnvManager = await registerInlineScriptFeatures(
nativeFinder,
context.subscriptions,
outputChannel,
sysMgr,
context.globalStorageUri,
);
})(),
),
safeRegister('shellStartupVars', shellStartupVarsMgr.initialize()),
]);
Expand Down
50 changes: 50 additions & 0 deletions src/features/envCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ import {
PythonProjectCreator,
PythonProjectCreatorOptions,
} from '../api';
import { INLINE_SCRIPT_MANAGER_ID } from '../common/constants';
import { traceError, traceInfo, traceVerbose } from '../common/logging';
import { clearPersistentState } from '../common/persistentState';
import type { InlineScriptEnvManager } from '../managers/builtin/inlineScript/envManager';
import {
EnvironmentManagers,
InternalEnvironmentManager,
InternalPackageManager,
ProjectCreators,
PythonProjectManager,
} from '../internal.api';
import { isInlineScriptsFeatureEnabled } from '../helpers';
import { waitForEnvManagerId } from './common/managerReady';
import { removePythonProjectSetting, setEnvironmentManager, setPackageManager } from './settings/settingHelpers';

import { valid as pep440Valid } from '@renovatebot/pep440';
Expand All @@ -50,6 +55,7 @@ import {
showInputBox,
showOpenDialog,
showQuickPick,
showWarningMessage,
withProgress,
} from '../common/window.apis';
import { runAsTask } from './execution/runAsTask';
Expand Down Expand Up @@ -306,6 +312,50 @@ export async function removeEnvironmentCommand(context: unknown, managers: Envir
}
}

export async function clearCacheCommand(
envManagers: EnvironmentManagers,
clearShellProfileCache: () => Promise<void>,
): Promise<void> {
await clearPersistentState();
await envManagers.clearCache(undefined);
await clearShellProfileCache();
}

export async function clearInlineScriptCacheCommand(
getManager: () => InlineScriptEnvManager | undefined | Promise<InlineScriptEnvManager | undefined>,
): Promise<void> {
if (!isInlineScriptsFeatureEnabled()) {
const message = l10n.t(
'Script environment cache is unavailable because inline script environments are disabled in this window.',
);
showErrorMessage(message);
throw new Error(message);
}

await waitForEnvManagerId([INLINE_SCRIPT_MANAGER_ID]);
const manager = await getManager();
if (!manager) {
const message = l10n.t(
'Script environment cache is unavailable because the inline script environment manager is not available in this window.',
);
showErrorMessage(message);
throw new Error(message);
}

const clearLabel = l10n.t('Clear Cache');
const confirm = await showWarningMessage(
l10n.t('Delete cached environments created for inline Python scripts?'),
{ modal: true },
clearLabel,
l10n.t('Cancel'),
);
if (confirm !== clearLabel) {
return;
}

await manager.clearScriptCache();
}

export async function handlePackageUninstall(context: unknown, em: EnvironmentManagers) {
if (context instanceof PackageTreeItem || context instanceof ProjectPackage) {
if (context.pkg.isTransitive) {
Expand Down
Loading
Loading