Skip to content

Commit d5497e2

Browse files
committed
updates from feedback
1 parent c287104 commit d5497e2

File tree

2 files changed

+13
-88
lines changed

2 files changed

+13
-88
lines changed

src/common/utils/pathUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,12 @@ export function untildify(path: string): string {
9393
export function getUserHomeDir(): string {
9494
return os.homedir();
9595
}
96+
97+
/**
98+
* Applies untildify to an array of paths
99+
* @param paths Array of potentially tilde-containing paths
100+
* @returns Array of expanded paths
101+
*/
102+
export function untildifyArray(paths: string[]): string[] {
103+
return paths.map((p) => untildify(p));
104+
}

src/managers/common/nativePythonFinder.ts

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PythonProjectApi } from '../../api';
88
import { ENVS_EXTENSION_ID, PYTHON_EXTENSION_ID } from '../../common/constants';
99
import { getExtension } from '../../common/extension.apis';
1010
import { traceError, traceLog, traceVerbose, traceWarn } from '../../common/logging';
11-
import { untildify } from '../../common/utils/pathUtils';
11+
import { untildify, untildifyArray } from '../../common/utils/pathUtils';
1212
import { isWindows } from '../../common/utils/platformUtils';
1313
import { createRunningWorkerPool, WorkerPool } from '../../common/utils/workerPool';
1414
import { getConfiguration, getWorkspaceFolders } from '../../common/workspace.apis';
@@ -390,15 +390,9 @@ function getPythonSettingAndUntildify<T>(name: string, scope?: Uri): T | undefin
390390
export async function getAllExtraSearchPaths(): Promise<string[]> {
391391
const searchDirectories: string[] = [];
392392

393-
// Handle migration from legacy python settings to new search paths settings
394-
const legacyPathsCovered = await handleLegacyPythonSettingsMigration();
395-
396-
// Only get legacy custom venv directories if they haven't been migrated to globalSearchPaths correctly
397-
if (!legacyPathsCovered) {
398-
const customVenvDirs = getCustomVirtualEnvDirsLegacy();
399-
searchDirectories.push(...customVenvDirs);
400-
traceLog('Added legacy custom venv directories (not covered by globalSearchPaths):', customVenvDirs);
401-
}
393+
// add legacy custom venv directories
394+
const customVenvDirs = getCustomVirtualEnvDirsLegacy();
395+
searchDirectories.push(...customVenvDirs);
402396

403397
// Get globalSearchPaths
404398
const globalSearchPaths = getGlobalSearchPaths().filter((path) => path && path.trim() !== '');
@@ -491,84 +485,6 @@ function getWorkspaceSearchPaths(): string[] {
491485
}
492486
}
493487

494-
/**
495-
* Applies untildify to an array of paths
496-
* @param paths Array of potentially tilde-containing paths
497-
* @returns Array of expanded paths
498-
*/
499-
function untildifyArray(paths: string[]): string[] {
500-
return paths.map((p) => untildify(p));
501-
}
502-
503-
/**
504-
* Handles migration from legacy python settings to the new globalSearchPaths setting.
505-
* Legacy settings (venvPath, venvFolders) are User-scoped only, so they all migrate to globalSearchPaths.
506-
* Does NOT delete the old settings, only adds them to the new settings.
507-
* @returns true if legacy paths are covered by globalSearchPaths (either already there or just migrated), false if legacy paths should be included separately
508-
*/
509-
async function handleLegacyPythonSettingsMigration(): Promise<boolean> {
510-
try {
511-
const pythonConfig = getConfiguration('python');
512-
const envConfig = getConfiguration('python-env');
513-
514-
// Get legacy settings at global level only (they were User-scoped)
515-
const venvPathInspection = pythonConfig.inspect<string>('venvPath');
516-
const venvFoldersInspection = pythonConfig.inspect<string[]>('venvFolders');
517-
518-
// Collect global (user-level) legacy paths for globalSearchPaths
519-
const globalLegacyPaths: string[] = [];
520-
if (venvPathInspection?.globalValue) {
521-
globalLegacyPaths.push(venvPathInspection.globalValue);
522-
}
523-
if (venvFoldersInspection?.globalValue) {
524-
globalLegacyPaths.push(...venvFoldersInspection.globalValue);
525-
}
526-
527-
if (globalLegacyPaths.length === 0) {
528-
// No legacy settings exist, so they're "covered" (nothing to worry about)
529-
return true;
530-
}
531-
532-
// Check if legacy paths are already in globalSearchPaths
533-
const globalSearchPathsInspection = envConfig.inspect<string[]>('globalSearchPaths');
534-
const currentGlobalSearchPaths = globalSearchPathsInspection?.globalValue || [];
535-
536-
// Check if all legacy paths are already covered by globalSearchPaths
537-
const legacyPathsAlreadyCovered = globalLegacyPaths.every((legacyPath) =>
538-
currentGlobalSearchPaths.includes(legacyPath),
539-
);
540-
541-
if (legacyPathsAlreadyCovered) {
542-
traceLog('All legacy paths are already in globalSearchPaths, no migration needed');
543-
return true; // Legacy paths are covered
544-
}
545-
546-
// Need to migrate - add legacy paths to globalSearchPaths
547-
const combinedGlobalPaths = Array.from(new Set([...currentGlobalSearchPaths, ...globalLegacyPaths]));
548-
await envConfig.update('globalSearchPaths', combinedGlobalPaths, true); // true = global/user level
549-
traceLog(
550-
'Migrated legacy global python settings to globalSearchPaths. globalSearchPaths setting is now:',
551-
combinedGlobalPaths,
552-
);
553-
554-
// Show notification to user about migration
555-
if (!migrationNotificationShown) {
556-
migrationNotificationShown = true;
557-
traceLog(
558-
'User notification: Automatically migrated legacy python settings to python-env.globalSearchPaths.',
559-
);
560-
}
561-
562-
return true; // Legacy paths are now covered by globalSearchPaths
563-
} catch (error) {
564-
traceError('Error during legacy python settings migration:', error);
565-
return false; // On error, include legacy paths separately to be safe
566-
}
567-
}
568-
569-
// Module-level variable to track migration notification
570-
let migrationNotificationShown = false;
571-
572488
export function getCacheDirectory(context: ExtensionContext): Uri {
573489
return Uri.joinPath(context.globalStorageUri, 'pythonLocator');
574490
}

0 commit comments

Comments
 (0)