Skip to content
Merged
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
1 change: 1 addition & 0 deletions news/2 Fixes/15439.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix for missing pyenv virtual environments from selectable environments.
32 changes: 22 additions & 10 deletions src/client/pythonEnvironments/common/externalDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,35 @@ export async function getFileInfo(filePath: string): Promise<{ ctime: number; mt
}
}

export async function resolveSymbolicLink(filepath: string): Promise<string> {
const stats = await fsapi.lstat(filepath);
export async function resolveSymbolicLink(absPath: string): Promise<string> {
const stats = await fsapi.lstat(absPath);
if (stats.isSymbolicLink()) {
const link = await fsapi.readlink(filepath);
const link = await fsapi.readlink(absPath);
return resolveSymbolicLink(link);
}
return filepath;
return absPath;
}

export async function* getSubDirs(root: string): AsyncIterableIterator<string> {
const dirContents = await fsapi.readdir(root);
/**
* Returns full path to sub directories of a given directory.
* @param root
* @param resolveSymlinks
*/
export async function* getSubDirs(root: string, resolveSymlinks: boolean): AsyncIterableIterator<string> {
const dirContents = await fsapi.promises.readdir(root, { withFileTypes: true });
const generators = dirContents.map((item) => {
async function* generator() {
const stat = await fsapi.lstat(path.join(root, item));

if (stat.isDirectory()) {
yield item;
const fullPath = path.join(root, item.name);
if (item.isDirectory()) {
yield fullPath;
} else if (resolveSymlinks && item.isSymbolicLink()) {
// The current FS item is a symlink. It can potentially be a file
// or a directory. Resolve it first and then check if it is a directory.
const resolvedPath = await resolveSymbolicLink(fullPath);
const resolvedPathStat = await fsapi.lstat(resolvedPath);
if (resolvedPathStat.isDirectory()) {
yield resolvedPath;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ export function parsePyenvVersion(str: string): Promise<IPyenvVersionStrings | u
async function* getPyenvEnvironments(): AsyncIterableIterator<PythonEnvInfo> {
const pyenvVersionDir = getPyenvVersionsDir();

const subDirs = getSubDirs(pyenvVersionDir);
for await (const subDir of subDirs) {
const envDir = path.join(pyenvVersionDir, subDir);
const interpreterPath = await getInterpreterPathFromDir(envDir);
const subDirs = getSubDirs(pyenvVersionDir, true);
for await (const subDirPath of subDirs) {
const envDirName = path.basename(subDirPath);
const interpreterPath = await getInterpreterPathFromDir(subDirPath);

if (interpreterPath) {
// The sub-directory name sometimes can contain distro and python versions.
// here we attempt to extract the texts out of the name.
const versionStrings = await parsePyenvVersion(subDir);
const versionStrings = await parsePyenvVersion(envDirName);

// Here we look for near by files, or config files to see if we can get python version info
// without running python itself.
Expand All @@ -290,7 +290,7 @@ async function* getPyenvEnvironments(): AsyncIterableIterator<PythonEnvInfo> {
// `pyenv local|global <env-name>` or `pyenv shell <env-name>`
//
// For the display name we are going to treat these as `pyenv` environments.
const display = `${subDir}:pyenv`;
const display = `${envDirName}:pyenv`;

const org = versionStrings && versionStrings.distro ? versionStrings.distro : '';

Expand All @@ -299,14 +299,14 @@ async function* getPyenvEnvironments(): AsyncIterableIterator<PythonEnvInfo> {
const envInfo = buildEnvInfo({
kind: PythonEnvKind.Pyenv,
executable: interpreterPath,
location: envDir,
location: subDirPath,
version: pythonVersion,
source: [PythonEnvSource.Pyenv],
display,
org,
fileInfo,
});
envInfo.name = subDir;
envInfo.name = envDirName;

yield envInfo;
}
Expand Down