Skip to content

Commit fcb9848

Browse files
authored
Add functionality to retrieve Poetry path from settings (#917)
fixes #918
1 parent eaeb861 commit fcb9848

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/managers/poetry/poetryUtils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { traceError, traceInfo } from '../../common/logging';
88
import { getWorkspacePersistentState } from '../../common/persistentState';
99
import { getUserHomeDir, untildify } from '../../common/utils/pathUtils';
1010
import { isWindows } from '../../common/utils/platformUtils';
11+
import { getConfiguration } from '../../common/workspace.apis';
1112
import {
1213
isNativeEnvInfo,
1314
NativeEnvInfo,
@@ -41,6 +42,12 @@ export async function clearPoetryCache(): Promise<void> {
4142
poetryVirtualenvsPath = undefined;
4243
}
4344

45+
function getPoetryPathFromSettings(): string | undefined {
46+
const config = getConfiguration('python');
47+
const value = config.get<string>('poetryPath');
48+
return value && typeof value === 'string' ? untildify(value) : value;
49+
}
50+
4451
async function setPoetry(poetry: string): Promise<void> {
4552
poetryPath = poetry;
4653
const state = await getWorkspacePersistentState();
@@ -115,6 +122,14 @@ export async function getPoetry(native?: NativePythonFinder): Promise<string | u
115122
return untildify(poetryPath);
116123
}
117124

125+
// try to get from settings
126+
const settingPath = getPoetryPathFromSettings();
127+
if (settingPath) {
128+
poetryPath = settingPath;
129+
traceInfo(`Using poetry from settings: ${settingPath}`);
130+
return poetryPath;
131+
}
132+
118133
// Check in standard PATH locations
119134
poetryPath = await findPoetry();
120135
if (poetryPath) {
@@ -292,7 +307,9 @@ export async function refreshPoetry(
292307
manager: EnvironmentManager,
293308
): Promise<PythonEnvironment[]> {
294309
traceInfo('Refreshing poetry environments');
295-
const data = await nativeFinder.refresh(hardRefresh);
310+
311+
const searchPath = getPoetryPathFromSettings();
312+
const data = await nativeFinder.refresh(hardRefresh, searchPath ? [Uri.file(searchPath)] : undefined);
296313

297314
let poetry = await getPoetry();
298315

0 commit comments

Comments
 (0)