Skip to content
Open
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
28 changes: 20 additions & 8 deletions src/managers/pipenv/pipenvUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Utility functions for Pipenv environment management

import * as fs from 'fs-extra';
import * as path from 'path';
import { Uri } from 'vscode';
import which from 'which';
Expand All @@ -13,6 +14,7 @@ import {
import { ENVS_EXTENSION_ID } from '../../common/constants';
import { traceError, traceInfo } from '../../common/logging';
import { getWorkspacePersistentState } from '../../common/persistentState';
import { untildify } from '../../common/utils/pathUtils';
import { getSettingWorkspaceScope } from '../../features/settings/settingHelpers';
import {
isNativeEnvInfo,
Expand Down Expand Up @@ -54,22 +56,32 @@ function getPipenvPathFromSettings(): string | undefined {

export async function getPipenv(native?: NativePythonFinder): Promise<string | undefined> {
if (pipenvPath) {
return pipenvPath;
if (await fs.exists(untildify(pipenvPath))) {
return untildify(pipenvPath);
}
pipenvPath = undefined;
}

const state = await getWorkspacePersistentState();
pipenvPath = await state.get<string>(PIPENV_PATH_KEY);
if (pipenvPath) {
traceInfo(`Using pipenv from persistent state: ${pipenvPath}`);
return pipenvPath;
const storedPath = await state.get<string>(PIPENV_PATH_KEY);
if (storedPath) {
if (await fs.exists(untildify(storedPath))) {
pipenvPath = storedPath;
traceInfo(`Using pipenv from persistent state: ${pipenvPath}`);
return untildify(pipenvPath);
}
await state.set(PIPENV_PATH_KEY, undefined);
}

// try to get from settings
const settingPath = getPipenvPathFromSettings();
if (settingPath) {
pipenvPath = settingPath;
traceInfo(`Using pipenv from settings: ${settingPath}`);
return pipenvPath;
if (await fs.exists(untildify(settingPath))) {
pipenvPath = settingPath;
traceInfo(`Using pipenv from settings: ${settingPath}`);
return untildify(pipenvPath);
}
traceInfo(`Pipenv path from settings does not exist: ${settingPath}`);
}

// Try to find pipenv in PATH
Expand Down
27 changes: 17 additions & 10 deletions src/managers/poetry/poetryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,27 @@ export async function setPoetryForWorkspaces(fsPath: string[], envPath: string |

export async function getPoetry(native?: NativePythonFinder): Promise<string | undefined> {
if (poetryPath) {
return poetryPath;
if (await fs.exists(untildify(poetryPath))) {
return untildify(poetryPath);
}
poetryPath = undefined;
}

const state = await getWorkspacePersistentState();
poetryPath = await state.get<string>(POETRY_PATH_KEY);
if (poetryPath) {
traceInfo(`Using poetry from persistent state: ${poetryPath}`);
// Also retrieve the virtualenvs path if we haven't already
if (!poetryVirtualenvsPath) {
getPoetryVirtualenvsPath(untildify(poetryPath)).catch((e) =>
traceError(`Error getting Poetry virtualenvs path: ${e}`),
);
const storedPath = await state.get<string>(POETRY_PATH_KEY);
if (storedPath) {
if (await fs.exists(untildify(storedPath))) {
poetryPath = storedPath;
traceInfo(`Using poetry from persistent state: ${poetryPath}`);
// Also retrieve the virtualenvs path if we haven't already
if (!poetryVirtualenvsPath) {
getPoetryVirtualenvsPath(untildify(poetryPath)).catch((e) =>
traceError(`Error getting Poetry virtualenvs path: ${e}`),
);
}
return untildify(poetryPath);
}
return untildify(poetryPath);
await state.set(POETRY_PATH_KEY, undefined);
}

// Check in standard PATH locations
Expand Down
17 changes: 12 additions & 5 deletions src/managers/pyenv/pyenvUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,21 @@ export async function setPyenvForWorkspaces(fsPath: string[], envPath: string |

export async function getPyenv(native?: NativePythonFinder): Promise<string | undefined> {
if (pyenvPath) {
return pyenvPath;
if (await fs.exists(untildify(pyenvPath))) {
return untildify(pyenvPath);
}
pyenvPath = undefined;
}

const state = await getWorkspacePersistentState();
pyenvPath = await state.get<string>(PYENV_PATH_KEY);
if (pyenvPath) {
traceInfo(`Using pyenv from persistent state: ${pyenvPath}`);
return untildify(pyenvPath);
const storedPath = await state.get<string>(PYENV_PATH_KEY);
if (storedPath) {
if (await fs.exists(untildify(storedPath))) {
pyenvPath = storedPath;
traceInfo(`Using pyenv from persistent state: ${pyenvPath}`);
return untildify(pyenvPath);
}
await state.set(PYENV_PATH_KEY, undefined);
}

const pyenvBin = isWindows() ? 'pyenv.exe' : 'pyenv';
Expand Down