Skip to content

Commit 3994c45

Browse files
author
Kartik Raj
committed
Code reviews
1 parent 73fc23e commit 3994c45

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/client/pythonEnvironments/common/pythonBinariesWatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export function watchLocationForPythonBinaries(
1818
const patterns = [executablePattern, `*/${executablePattern}`, `*/${binName}/${executablePattern}`];
1919
for (const pattern of patterns) {
2020
watchLocationForPattern(baseDir, pattern, (type: FileChangeType, e: string) => {
21-
const regex = picomatch.toRegex(executablePattern, { nocase: getOSType() === OSType.Windows });
22-
if (!regex.test(path.basename(e))) {
21+
const regex = picomatch.toRegex(path.join('**', executablePattern), { nocase: getOSType() === OSType.Windows });
22+
if (!regex.test(e)) {
2323
// When deleting the file for some reason path to all directories leading up to python are reported
2424
// Skip those events
2525
return;

src/client/pythonEnvironments/discovery/locators/services/windowsStoreLocator.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export function isForbiddenStorePath(interpreterPath: string): boolean {
7272
*/
7373
export async function isWindowsStoreEnvironment(interpreterPath: string): Promise<boolean> {
7474
const pythonPathToCompare = path.normalize(interpreterPath).toUpperCase();
75-
const localAppDataStorePath = path.normalize(getWindowsStoreAppsRoot()).toUpperCase();
75+
const localAppDataStorePath = path
76+
.normalize(getWindowsStoreAppsRoot())
77+
.toUpperCase();
7678
if (pythonPathToCompare.includes(localAppDataStorePath)) {
7779
return true;
7880
}
@@ -96,7 +98,7 @@ export async function isWindowsStoreEnvironment(interpreterPath: string): Promis
9698
* python3.exe
9799
* python38.exe
98100
*/
99-
const windowsPythonExes = 'python3\.[0-9]\.exe';
101+
const windowsStorePythonExes = 'python3\.[0-9]\.exe';
100102

101103
/**
102104
* Checks if a given path ends with python3.*.exe. Not all python executables are matched as
@@ -105,7 +107,7 @@ const windowsPythonExes = 'python3\.[0-9]\.exe';
105107
* @returns {boolean} : Returns true if the path matches pattern for windows python executable.
106108
*/
107109
export function isWindowsStorePythonExe(interpreterPath: string): boolean {
108-
const regex = picomatch.toRegex(windowsPythonExes, { nocase: true });
110+
const regex = picomatch.toRegex(windowsStorePythonExes, { nocase: true });
109111
return regex.test(path.basename(interpreterPath));
110112
}
111113

@@ -130,15 +132,16 @@ export async function getWindowsStorePythonExes(): Promise<string[]> {
130132

131133
// Collect python*.exe directly under %LOCALAPPDATA%/Microsoft/WindowsApps
132134
const files = await fsapi.readdir(windowsAppsRoot);
133-
return files.map((filename: string) => path.join(windowsAppsRoot, filename)).filter(isWindowsStorePythonExe);
135+
return files
136+
.map((filename: string) => path.join(windowsAppsRoot, filename))
137+
.filter(isWindowsStorePythonExe);
134138
}
135139

136140
export class WindowsStoreLocator extends Locator {
137141
private readonly kind: PythonEnvKind = PythonEnvKind.WindowsStore;
138142

139-
public constructor() {
140-
super();
141-
this.registerWatchers().ignoreErrors();
143+
public initialize(): void {
144+
this.startWatcher().ignoreErrors();
142145
}
143146

144147
public iterEnvs(): IPythonEnvsIterator {
@@ -171,10 +174,10 @@ export class WindowsStoreLocator extends Locator {
171174
return undefined;
172175
}
173176

174-
private async registerWatchers(): Promise<void> {
177+
private async startWatcher(): Promise<void> {
175178
const windowsAppsRoot = getWindowsStoreAppsRoot();
176179
watchLocationForPythonBinaries(windowsAppsRoot, (type: FileChangeType) => {
177180
this.emitter.fire({ type, kind: this.kind });
178-
}, windowsPythonExes);
181+
}, windowsStorePythonExes);
179182
}
180183
}

src/test/pythonEnvironments/discovery/locators/windowsStoreLocator.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ suite('Windows Store Locator', async () => {
7171
});
7272
setup(async () => {
7373
locator = new WindowsStoreLocator();
74+
locator.initialize();
7475
// Wait for watchers to get ready
7576
await sleep(1000);
7677
});

0 commit comments

Comments
 (0)