Skip to content

Commit a2abdfb

Browse files
authored
fix: resolve on filesystem trigger does not use correct activate (#384)
fixes: #383 The fix is to trigger FS event on `activate` file creation. This makes sure that we have the right files available for the environment.
1 parent b0342ed commit a2abdfb

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed

src/managers/builtin/main.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Disposable, LogOutputChannel } from 'vscode';
22
import { PythonEnvironmentApi } from '../../api';
3-
import { SysPythonManager } from './sysPythonManager';
4-
import { PipPackageManager } from './pipManager';
5-
import { VenvManager } from './venvManager';
3+
import { createSimpleDebounce } from '../../common/utils/debounce';
4+
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
5+
import { createFileSystemWatcher, onDidDeleteFiles } from '../../common/workspace.apis';
66
import { getPythonApi } from '../../features/pythonApi';
77
import { NativePythonFinder } from '../common/nativePythonFinder';
8-
import { UvProjectCreator } from './uvProjectCreator';
98
import { isUvInstalled } from './helpers';
10-
import { createFileSystemWatcher, onDidDeleteFiles } from '../../common/workspace.apis';
11-
import { createSimpleDebounce } from '../../common/utils/debounce';
12-
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
9+
import { PipPackageManager } from './pipManager';
1310
import { isPipInstallCommand } from './pipUtils';
11+
import { SysPythonManager } from './sysPythonManager';
12+
import { UvProjectCreator } from './uvProjectCreator';
13+
import { VenvManager } from './venvManager';
1414

1515
export async function registerSystemPythonFeatures(
1616
nativeFinder: NativePythonFinder,
@@ -31,7 +31,7 @@ export async function registerSystemPythonFeatures(
3131
const venvDebouncedRefresh = createSimpleDebounce(500, () => {
3232
venvManager.watcherRefresh();
3333
});
34-
const watcher = createFileSystemWatcher('{**/pyenv.cfg,**/bin/python,**/python.exe}', false, true, false);
34+
const watcher = createFileSystemWatcher('{**/activate}', false, true, false);
3535
disposables.push(
3636
watcher,
3737
watcher.onDidCreate(() => {

src/managers/builtin/venvUtils.ts

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as fsapi from 'fs-extra';
2+
import * as os from 'os';
3+
import * as path from 'path';
14
import { l10n, LogOutputChannel, ProgressLocation, QuickPickItem, QuickPickItemKind, ThemeIcon, Uri } from 'vscode';
25
import {
36
EnvironmentManager,
@@ -6,36 +9,33 @@ import {
69
PythonEnvironmentApi,
710
PythonEnvironmentInfo,
811
} from '../../api';
9-
import * as path from 'path';
10-
import * as os from 'os';
11-
import * as fsapi from 'fs-extra';
12-
import { resolveSystemPythonEnvironmentPath } from './utils';
1312
import { ENVS_EXTENSION_ID } from '../../common/constants';
13+
import { Common, VenvManagerStrings } from '../../common/localize';
14+
import { getWorkspacePersistentState } from '../../common/persistentState';
15+
import { pickEnvironmentFrom } from '../../common/pickers/environments';
16+
import { EventNames } from '../../common/telemetry/constants';
17+
import { sendTelemetryEvent } from '../../common/telemetry/sender';
18+
import { isWindows } from '../../common/utils/platformUtils';
19+
import {
20+
showErrorMessage,
21+
showInputBox,
22+
showOpenDialog,
23+
showQuickPick,
24+
showWarningMessage,
25+
withProgress,
26+
} from '../../common/window.apis';
27+
import { getConfiguration } from '../../common/workspace.apis';
28+
import { ShellConstants } from '../../features/common/shellConstants';
1429
import {
1530
isNativeEnvInfo,
1631
NativeEnvInfo,
1732
NativePythonEnvironmentKind,
1833
NativePythonFinder,
1934
} from '../common/nativePythonFinder';
20-
import { getWorkspacePersistentState } from '../../common/persistentState';
2135
import { shortVersion, sortEnvironments } from '../common/utils';
22-
import { getConfiguration } from '../../common/workspace.apis';
23-
import { pickEnvironmentFrom } from '../../common/pickers/environments';
24-
import {
25-
showQuickPick,
26-
withProgress,
27-
showWarningMessage,
28-
showInputBox,
29-
showOpenDialog,
30-
showErrorMessage,
31-
} from '../../common/window.apis';
32-
import { Common, VenvManagerStrings } from '../../common/localize';
33-
import { isUvInstalled, runUV, runPython } from './helpers';
36+
import { isUvInstalled, runPython, runUV } from './helpers';
3437
import { getProjectInstallable, getWorkspacePackagesToInstall, PipPackages } from './pipUtils';
35-
import { isWindows } from '../../common/utils/platformUtils';
36-
import { sendTelemetryEvent } from '../../common/telemetry/sender';
37-
import { EventNames } from '../../common/telemetry/constants';
38-
import { ShellConstants } from '../../features/common/shellConstants';
38+
import { resolveSystemPythonEnvironmentPath } from './utils';
3939

4040
export const VENV_WORKSPACE_KEY = `${ENVS_EXTENSION_ID}:venv:WORKSPACE_SELECTED`;
4141
export const VENV_GLOBAL_KEY = `${ENVS_EXTENSION_ID}:venv:GLOBAL_SELECTED`;
@@ -136,24 +136,22 @@ async function getPythonInfo(env: NativeEnvInfo): Promise<PythonEnvironmentInfo>
136136
shellDeactivation.set('unknown', [{ executable: 'deactivate' }]);
137137
}
138138

139-
if (await fsapi.pathExists(path.join(binDir, 'activate'))) {
140-
shellActivation.set(ShellConstants.SH, [{ executable: 'source', args: [path.join(binDir, `activate`)] }]);
141-
shellDeactivation.set(ShellConstants.SH, [{ executable: 'deactivate' }]);
139+
shellActivation.set(ShellConstants.SH, [{ executable: 'source', args: [path.join(binDir, `activate`)] }]);
140+
shellDeactivation.set(ShellConstants.SH, [{ executable: 'deactivate' }]);
142141

143-
shellActivation.set(ShellConstants.BASH, [{ executable: 'source', args: [path.join(binDir, `activate`)] }]);
144-
shellDeactivation.set(ShellConstants.BASH, [{ executable: 'deactivate' }]);
142+
shellActivation.set(ShellConstants.BASH, [{ executable: 'source', args: [path.join(binDir, `activate`)] }]);
143+
shellDeactivation.set(ShellConstants.BASH, [{ executable: 'deactivate' }]);
145144

146-
shellActivation.set(ShellConstants.GITBASH, [
147-
{ executable: 'source', args: [pathForGitBash(path.join(binDir, `activate`))] },
148-
]);
149-
shellDeactivation.set(ShellConstants.GITBASH, [{ executable: 'deactivate' }]);
145+
shellActivation.set(ShellConstants.GITBASH, [
146+
{ executable: 'source', args: [pathForGitBash(path.join(binDir, `activate`))] },
147+
]);
148+
shellDeactivation.set(ShellConstants.GITBASH, [{ executable: 'deactivate' }]);
150149

151-
shellActivation.set(ShellConstants.ZSH, [{ executable: 'source', args: [path.join(binDir, `activate`)] }]);
152-
shellDeactivation.set(ShellConstants.ZSH, [{ executable: 'deactivate' }]);
150+
shellActivation.set(ShellConstants.ZSH, [{ executable: 'source', args: [path.join(binDir, `activate`)] }]);
151+
shellDeactivation.set(ShellConstants.ZSH, [{ executable: 'deactivate' }]);
153152

154-
shellActivation.set(ShellConstants.KSH, [{ executable: '.', args: [path.join(binDir, `activate`)] }]);
155-
shellDeactivation.set(ShellConstants.KSH, [{ executable: 'deactivate' }]);
156-
}
153+
shellActivation.set(ShellConstants.KSH, [{ executable: '.', args: [path.join(binDir, `activate`)] }]);
154+
shellDeactivation.set(ShellConstants.KSH, [{ executable: 'deactivate' }]);
157155

158156
if (await fsapi.pathExists(path.join(binDir, 'Activate.ps1'))) {
159157
shellActivation.set(ShellConstants.PWSH, [{ executable: '&', args: [path.join(binDir, `Activate.ps1`)] }]);

0 commit comments

Comments
 (0)