-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathnativePythonFinder.ts
More file actions
668 lines (601 loc) · 26.6 KB
/
nativePythonFinder.ts
File metadata and controls
668 lines (601 loc) · 26.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
import * as ch from 'child_process';
import * as fs from 'fs-extra';
import * as path from 'path';
import { PassThrough } from 'stream';
import { Disposable, ExtensionContext, LogOutputChannel, Uri, workspace } from 'vscode';
import * as rpc from 'vscode-jsonrpc/node';
import { PythonProjectApi } from '../../api';
import { ENVS_EXTENSION_ID, PYTHON_EXTENSION_ID } from '../../common/constants';
import { getExtension } from '../../common/extension.apis';
import { traceLog, traceVerbose } from '../../common/logging';
import { untildify } from '../../common/utils/pathUtils';
import { isWindows } from '../../common/utils/platformUtils';
import { createRunningWorkerPool, WorkerPool } from '../../common/utils/workerPool';
import { getConfiguration } from '../../common/workspace.apis';
import { noop } from './utils';
export async function getNativePythonToolsPath(): Promise<string> {
const envsExt = getExtension(ENVS_EXTENSION_ID);
if (envsExt) {
const petPath = path.join(envsExt.extensionPath, 'python-env-tools', 'bin', isWindows() ? 'pet.exe' : 'pet');
if (await fs.pathExists(petPath)) {
return petPath;
}
}
const python = getExtension(PYTHON_EXTENSION_ID);
if (!python) {
throw new Error('Python extension not found');
}
return path.join(python.extensionPath, 'python-env-tools', 'bin', isWindows() ? 'pet.exe' : 'pet');
}
export interface NativeEnvInfo {
displayName?: string;
name?: string;
executable?: string;
kind?: NativePythonEnvironmentKind;
version?: string;
prefix?: string;
manager?: NativeEnvManagerInfo;
project?: string;
arch?: 'x64' | 'x86';
symlinks?: string[];
}
export interface NativeEnvManagerInfo {
tool: string;
executable: string;
version?: string;
}
export type NativeInfo = NativeEnvInfo | NativeEnvManagerInfo;
export function isNativeEnvInfo(info: NativeInfo): boolean {
return !(info as NativeEnvManagerInfo).tool;
}
export enum NativePythonEnvironmentKind {
conda = 'Conda',
homebrew = 'Homebrew',
pyenv = 'Pyenv',
globalPaths = 'GlobalPaths',
pyenvVirtualEnv = 'PyenvVirtualEnv',
pipenv = 'Pipenv',
poetry = 'Poetry',
macPythonOrg = 'MacPythonOrg',
macCommandLineTools = 'MacCommandLineTools',
linuxGlobal = 'LinuxGlobal',
macXCode = 'MacXCode',
venv = 'Venv',
virtualEnv = 'VirtualEnv',
virtualEnvWrapper = 'VirtualEnvWrapper',
windowsStore = 'WindowsStore',
windowsRegistry = 'WindowsRegistry',
}
export interface NativePythonFinder extends Disposable {
/**
* Refresh the list of python environments.
* Returns an async iterable that can be used to iterate over the list of python environments.
* Internally this will take all of the current workspace folders and search for python environments.
*
* If a Uri is provided, then it will search for python environments in that location (ignoring workspaces).
* Uri can be a file or a folder.
* If a NativePythonEnvironmentKind is provided, then it will search for python environments of that kind (ignoring workspaces).
*/
refresh(hardRefresh: boolean, options?: NativePythonEnvironmentKind | Uri[]): Promise<NativeInfo[]>;
/**
* Will spawn the provided Python executable and return information about the environment.
* @param executable
*/
resolve(executable: string): Promise<NativeEnvInfo>;
}
interface NativeLog {
level: string;
message: string;
}
interface RefreshOptions {
searchKind?: NativePythonEnvironmentKind;
searchPaths?: string[];
}
class NativePythonFinderImpl implements NativePythonFinder {
private readonly connection: rpc.MessageConnection;
private readonly pool: WorkerPool<NativePythonEnvironmentKind | Uri[] | undefined, NativeInfo[]>;
private cache: Map<string, NativeInfo[]> = new Map();
constructor(
private readonly outputChannel: LogOutputChannel,
private readonly toolPath: string,
private readonly api: PythonProjectApi,
private readonly cacheDirectory?: Uri,
) {
this.connection = this.start();
this.pool = createRunningWorkerPool<NativePythonEnvironmentKind | Uri[] | undefined, NativeInfo[]>(
async (options) => await this.doRefresh(options),
1,
'NativeRefresh-task',
);
}
public async resolve(executable: string): Promise<NativeEnvInfo> {
await this.configure();
const environment = await this.connection.sendRequest<NativeEnvInfo>('resolve', {
executable,
});
this.outputChannel.info(`Resolved Python Environment ${environment.executable}`);
return environment;
}
public async refresh(hardRefresh: boolean, options?: NativePythonEnvironmentKind | Uri[]): Promise<NativeInfo[]> {
if (hardRefresh) {
return this.handleHardRefresh(options);
}
return this.handleSoftRefresh(options);
}
private getKey(options?: NativePythonEnvironmentKind | Uri[]): string {
if (options === undefined) {
return 'all';
}
if (typeof options === 'string') {
return options;
}
if (Array.isArray(options)) {
return options.map((item) => item.fsPath).join(',');
}
return 'all';
}
private async handleHardRefresh(options?: NativePythonEnvironmentKind | Uri[]): Promise<NativeInfo[]> {
const key = this.getKey(options);
this.cache.delete(key);
if (!options) {
traceVerbose('Finder - refreshing all environments');
} else {
traceVerbose('Finder - from cache environments', key);
}
const result = await this.pool.addToQueue(options);
this.cache.set(key, result);
return result;
}
private async handleSoftRefresh(options?: NativePythonEnvironmentKind | Uri[]): Promise<NativeInfo[]> {
const key = this.getKey(options);
const cacheResult = this.cache.get(key);
if (!cacheResult) {
return this.handleHardRefresh(options);
}
if (!options) {
traceVerbose('Finder - from cache refreshing all environments');
} else {
traceVerbose('Finder - from cache environments', key);
}
return cacheResult;
}
public dispose() {
this.connection.dispose();
}
private getRefreshOptions(options?: NativePythonEnvironmentKind | Uri[]): RefreshOptions | undefined {
// settings on where else to search
const venvFolders = getPythonSettingAndUntildify<string[]>('venvFolders') ?? [];
if (options) {
if (typeof options === 'string') {
// kind
return { searchKind: options };
}
if (Array.isArray(options)) {
const uriSearchPaths = options.map((item) => item.fsPath);
uriSearchPaths.push(...venvFolders);
return { searchPaths: uriSearchPaths };
}
}
// return undefined to use configured defaults (for nativeFinder refresh)
return undefined;
}
private start(): rpc.MessageConnection {
this.outputChannel.info(`[pet] Starting Python Locator ${this.toolPath} server`);
// jsonrpc package cannot handle messages coming through too quickly.
// Lets handle the messages and close the stream only when
// we have got the exit event.
const readable = new PassThrough();
const writable = new PassThrough();
const disposables: Disposable[] = [];
try {
const proc = ch.spawn(this.toolPath, ['server'], { env: process.env });
proc.stdout.pipe(readable, { end: false });
proc.stderr.on('data', (data) => this.outputChannel.error(`[pet] ${data.toString()}`));
writable.pipe(proc.stdin, { end: false });
disposables.push({
dispose: () => {
try {
if (proc.exitCode === null) {
proc.kill();
}
} catch (ex) {
this.outputChannel.error('[pet] Error disposing finder', ex);
}
},
});
} catch (ex) {
this.outputChannel.error(`[pet] Error starting Python Finder ${this.toolPath} server`, ex);
}
const connection = rpc.createMessageConnection(
new rpc.StreamMessageReader(readable),
new rpc.StreamMessageWriter(writable),
);
disposables.push(
connection,
new Disposable(() => {
readable.end();
writable.end();
}),
connection.onError((ex) => {
this.outputChannel.error('[pet] Connection Error:', ex);
}),
connection.onNotification('log', (data: NativeLog) => {
const msg = `[pet] ${data.message}`;
switch (data.level) {
case 'info':
this.outputChannel.info(msg);
break;
case 'warning':
this.outputChannel.warn(msg);
break;
case 'error':
this.outputChannel.error(msg);
break;
case 'debug':
this.outputChannel.debug(msg);
break;
default:
this.outputChannel.trace(msg);
}
}),
connection.onNotification('telemetry', (data) => this.outputChannel.info('[pet] Telemetry: ', data)),
connection.onClose(() => {
disposables.forEach((d) => d.dispose());
}),
);
connection.listen();
return connection;
}
private async doRefresh(options?: NativePythonEnvironmentKind | Uri[]): Promise<NativeInfo[]> {
const disposables: Disposable[] = [];
const unresolved: Promise<void>[] = [];
const nativeInfo: NativeInfo[] = [];
try {
await this.configure();
const refreshOptions = this.getRefreshOptions(options);
disposables.push(
this.connection.onNotification('environment', (data: NativeEnvInfo) => {
this.outputChannel.info(`Discovered env: ${data.executable || data.prefix}`);
if (data.executable && (!data.version || !data.prefix)) {
unresolved.push(
this.connection
.sendRequest<NativeEnvInfo>('resolve', {
executable: data.executable,
})
.then((environment: NativeEnvInfo) => {
this.outputChannel.info(
`Resolved environment during PET refresh: ${environment.executable}`,
);
nativeInfo.push(environment);
})
.catch((ex) =>
this.outputChannel.error(`Error in Resolving ${JSON.stringify(data)}`, ex),
),
);
} else {
nativeInfo.push(data);
}
}),
this.connection.onNotification('manager', (data: NativeEnvManagerInfo) => {
this.outputChannel.info(`Discovered manager: (${data.tool}) ${data.executable}`);
nativeInfo.push(data);
}),
);
await this.connection.sendRequest<{ duration: number }>('refresh', refreshOptions);
await Promise.all(unresolved);
} catch (ex) {
this.outputChannel.error('[pet] Error refreshing', ex);
throw ex;
} finally {
disposables.forEach((d) => d.dispose());
}
return nativeInfo;
}
private lastConfiguration?: ConfigurationOptions;
/**
* Configuration request, this must always be invoked before any other request.
* Must be invoked when ever there are changes to any data related to the configuration details.
*/
private async configure() {
// Get all extra search paths including legacy settings and new searchPaths
const extraSearchPaths = await getAllExtraSearchPaths();
traceLog('Final environment directories:', extraSearchPaths);
const options: ConfigurationOptions = {
workspaceDirectories: this.api.getPythonProjects().map((item) => item.uri.fsPath),
environmentDirectories: extraSearchPaths,
condaExecutable: getPythonSettingAndUntildify<string>('condaPath'),
poetryExecutable: getPythonSettingAndUntildify<string>('poetryPath'),
cacheDirectory: this.cacheDirectory?.fsPath,
};
// No need to send a configuration request, is there are no changes.
if (JSON.stringify(options) === JSON.stringify(this.lastConfiguration || {})) {
this.outputChannel.debug('[pet] configure: No changes detected, skipping configuration update.');
return;
}
this.outputChannel.info('[pet] configure: Sending configuration update:', JSON.stringify(options));
try {
this.lastConfiguration = options;
await this.connection.sendRequest('configure', options);
} catch (ex) {
this.outputChannel.error('[pet] configure: Configuration error', ex);
}
}
}
type ConfigurationOptions = {
workspaceDirectories: string[];
environmentDirectories: string[];
condaExecutable: string | undefined;
poetryExecutable: string | undefined;
cacheDirectory?: string;
};
/**
* Gets all custom virtual environment locations to look for environments from the legacy python settings (venvPath, venvFolders).
*/
function getCustomVirtualEnvDirsLegacy(): string[] {
const venvDirs: string[] = [];
const venvPath = getPythonSettingAndUntildify<string>('venvPath');
if (venvPath) {
venvDirs.push(untildify(venvPath));
}
const venvFolders = getPythonSettingAndUntildify<string[]>('venvFolders') ?? [];
venvFolders.forEach((item) => {
venvDirs.push(item);
});
return Array.from(new Set(venvDirs));
}
function getPythonSettingAndUntildify<T>(name: string, scope?: Uri): T | undefined {
const value = getConfiguration('python', scope).get<T>(name);
if (typeof value === 'string') {
return value ? (untildify(value as string) as unknown as T) : undefined;
}
return value;
}
/**
* Checks if a search path is a regex pattern.
* A path is considered a regex pattern if it contains regex special characters
* but is not a Windows path (which can contain backslashes).
* @param searchPath The search path to check
* @returns true if the path is a regex pattern, false otherwise
*/
function isRegexSearchPattern(searchPath: string): boolean {
// Check if it's a regex pattern (contains regex special characters)
// Note: Windows paths contain backslashes, so we need to be more careful
const regexChars = /[*?[\]{}()^$+|\\]/;
const hasBackslash = searchPath.includes('\\');
const isWindowsPath = hasBackslash && (searchPath.match(/^[A-Za-z]:\\/) || searchPath.match(/^\\\\[^\\]+\\/));
return regexChars.test(searchPath) && !isWindowsPath;
}
/**
* Extracts the environment directory from a Python executable path.
* This follows the pattern: executable -> bin -> env -> search directory
* @param executablePath Path to Python executable
* @returns The environment directory path, or undefined if not found
*/
function extractEnvironmentDirectory(executablePath: string): string | undefined {
try {
// TODO: This logic may need to be adjusted for Windows paths (esp with Conda as doesn't use Scripts folder?)
const environmentDir = path.dirname(path.dirname(path.dirname(executablePath)));
if (environmentDir && environmentDir !== path.dirname(environmentDir)) {
traceLog('Extracted environment directory:', environmentDir, 'from executable:', executablePath);
return environmentDir;
} else {
traceLog(
'Warning: identified executable python at',
executablePath,
'not configured in correct folder structure, skipping',
);
return undefined;
}
} catch (error) {
traceLog('Error extracting environment directory from:', executablePath, 'Error:', error);
return undefined;
}
}
/**
* Gets all extra environment search paths from various configuration sources.
* Combines legacy python settings (with migration), globalSearchPaths, and workspaceSearchPaths.
* @returns Array of search directory paths
*/
async function getAllExtraSearchPaths(): Promise<string[]> {
const searchDirectories: string[] = [];
// Handle migration from legacy python settings to new search paths settings
const legacyPathsCovered = await handleLegacyPythonSettingsMigration();
// Only get legacy custom venv directories if they haven't been migrated to globalSearchPaths correctly
if (!legacyPathsCovered) {
const customVenvDirs = getCustomVirtualEnvDirsLegacy();
searchDirectories.push(...customVenvDirs);
traceLog('Added legacy custom venv directories (not covered by globalSearchPaths):', customVenvDirs);
} else {
traceLog('Skipping legacy custom venv directories - they are covered by globalSearchPaths');
}
// Get globalSearchPaths (absolute paths, no regex)
const globalSearchPaths = getGlobalSearchPaths();
traceLog('Retrieved globalSearchPaths:', globalSearchPaths);
for (const globalPath of globalSearchPaths) {
try {
if (!globalPath || globalPath.trim() === '') {
continue;
}
const trimmedPath = globalPath.trim();
traceLog('Processing global search path:', trimmedPath);
// Simply add the trimmed global path
searchDirectories.push(trimmedPath);
} catch (error) {
traceLog('Error processing global search path:', globalPath, 'Error:', error);
}
}
// Get workspaceSearchPaths (can include regex patterns)
const workspaceSearchPaths = getWorkspaceSearchPaths();
traceLog('Retrieved workspaceSearchPaths:', workspaceSearchPaths);
for (const searchPath of workspaceSearchPaths) {
try {
if (!searchPath || searchPath.trim() === '') {
continue;
}
const trimmedPath = searchPath.trim();
const isRegexPattern = isRegexSearchPattern(trimmedPath);
if (isRegexPattern) {
// Search for Python executables using the regex pattern
// Look for common Python executable names within the pattern
const pythonExecutablePatterns = isWindows()
? [`${trimmedPath}/**/python.exe`, `${trimmedPath}/**/python3.exe`]
: [`${trimmedPath}/**/python`, `${trimmedPath}/**/python3`];
traceLog('Searching for Python executables with patterns:', pythonExecutablePatterns);
for (const pattern of pythonExecutablePatterns) {
try {
const foundFiles = await workspace.findFiles(pattern, null);
traceLog(
'Python executable search found',
foundFiles.length,
'files matching pattern:',
pattern,
);
for (const file of foundFiles) {
// given the executable path, extract and save the environment directory
const environmentDir = extractEnvironmentDirectory(file.fsPath);
if (environmentDir) {
searchDirectories.push(environmentDir);
}
}
} catch (error) {
traceLog('Error searching for Python executables with pattern:', pattern, 'Error:', error);
}
}
} else {
// If it's not a regex, treat it as a normal directory path and just add it
searchDirectories.push(trimmedPath);
}
} catch (error) {
traceLog('Error processing workspace search path:', searchPath, 'Error:', error);
}
}
// Remove duplicates and return
const uniquePaths = Array.from(new Set(searchDirectories));
traceLog(
'getAllExtraSearchPaths completed. Total unique search directories:',
uniquePaths.length,
'Paths:',
uniquePaths,
);
return uniquePaths;
}
/**
* Gets globalSearchPaths setting with proper validation.
* Only gets user-level (global) setting since this setting is application-scoped.
*/
function getGlobalSearchPaths(): string[] {
try {
const envConfig = getConfiguration('python-env');
const inspection = envConfig.inspect<string[]>('globalSearchPaths');
const globalPaths = inspection?.globalValue || [];
traceLog('Retrieved globalSearchPaths:', globalPaths);
return untildifyArray(globalPaths);
} catch (error) {
traceLog('Error getting globalSearchPaths:', error);
return [];
}
}
/**
* Gets workspaceSearchPaths setting with workspace precedence.
* Gets the most specific workspace-level setting available.
*/
function getWorkspaceSearchPaths(): string[] {
try {
const envConfig = getConfiguration('python-env');
const inspection = envConfig.inspect<string[]>('workspaceSearchPaths');
// For workspace settings, prefer workspaceFolder > workspace
if (inspection?.workspaceFolderValue) {
traceLog('Using workspaceFolder level workspaceSearchPaths setting');
return inspection.workspaceFolderValue;
}
if (inspection?.workspaceValue) {
traceLog('Using workspace level workspaceSearchPaths setting');
return inspection.workspaceValue;
}
// Default empty array (don't use global value for workspace settings)
traceLog('No workspaceSearchPaths setting found at workspace level, using empty array');
return [];
} catch (error) {
traceLog('Error getting workspaceSearchPaths:', error);
return [];
}
}
/**
* Applies untildify to an array of paths
* @param paths Array of potentially tilde-containing paths
* @returns Array of expanded paths
*/
function untildifyArray(paths: string[]): string[] {
return paths.map((p) => untildify(p));
}
/**
* Handles migration from legacy python settings to the new globalSearchPaths setting.
* Legacy settings (venvPath, venvFolders) are User-scoped only, so they all migrate to globalSearchPaths.
* Does NOT delete the old settings, only adds them to the new settings.
* @returns true if legacy paths are covered by globalSearchPaths (either already there or just migrated), false if legacy paths should be included separately
*/
async function handleLegacyPythonSettingsMigration(): Promise<boolean> {
try {
const pythonConfig = getConfiguration('python');
const envConfig = getConfiguration('python-env');
// Get legacy settings at global level only (they were User-scoped)
const venvPathInspection = pythonConfig.inspect<string>('venvPath');
const venvFoldersInspection = pythonConfig.inspect<string[]>('venvFolders');
// Collect global (user-level) legacy paths for globalSearchPaths
const globalLegacyPaths: string[] = [];
if (venvPathInspection?.globalValue) {
globalLegacyPaths.push(venvPathInspection.globalValue);
}
if (venvFoldersInspection?.globalValue) {
globalLegacyPaths.push(...venvFoldersInspection.globalValue);
}
if (globalLegacyPaths.length === 0) {
// No legacy settings exist, so they're "covered" (nothing to worry about)
traceLog('No legacy python settings found');
return true;
}
traceLog('Found legacy python settings - global paths:', globalLegacyPaths);
// Check if legacy paths are already in globalSearchPaths
const globalSearchPathsInspection = envConfig.inspect<string[]>('globalSearchPaths');
const currentGlobalSearchPaths = globalSearchPathsInspection?.globalValue || [];
// Check if all legacy paths are already covered by globalSearchPaths
const legacyPathsAlreadyCovered = globalLegacyPaths.every((legacyPath) =>
currentGlobalSearchPaths.includes(legacyPath),
);
if (legacyPathsAlreadyCovered) {
traceLog('All legacy paths are already in globalSearchPaths, no migration needed');
return true; // Legacy paths are covered
}
// Need to migrate - add legacy paths to globalSearchPaths
const combinedGlobalPaths = Array.from(new Set([...currentGlobalSearchPaths, ...globalLegacyPaths]));
await envConfig.update('globalSearchPaths', combinedGlobalPaths, true); // true = global/user level
traceLog('Migrated legacy global python settings to globalSearchPaths. Combined paths:', combinedGlobalPaths);
// Show notification to user about migration
if (!migrationNotificationShown) {
migrationNotificationShown = true;
traceLog(
'User notification: Automatically migrated legacy python settings to python-env.globalSearchPaths.',
);
}
return true; // Legacy paths are now covered by globalSearchPaths
} catch (error) {
traceLog('Error during legacy python settings migration:', error);
return false; // On error, include legacy paths separately to be safe
}
}
// Module-level variable to track migration notification
let migrationNotificationShown = false;
export function getCacheDirectory(context: ExtensionContext): Uri {
return Uri.joinPath(context.globalStorageUri, 'pythonLocator');
}
export async function clearCacheDirectory(context: ExtensionContext): Promise<void> {
const cacheDirectory = getCacheDirectory(context);
await fs.emptyDir(cacheDirectory.fsPath).catch(noop);
}
export async function createNativePythonFinder(
outputChannel: LogOutputChannel,
api: PythonProjectApi,
context: ExtensionContext,
): Promise<NativePythonFinder> {
return new NativePythonFinderImpl(outputChannel, await getNativePythonToolsPath(), api, getCacheDirectory(context));
}