forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement API to check if poetry environment is related to a folder (#…
- Loading branch information
Kartik Raj
authored
Mar 18, 2021
1 parent
b0af142
commit 488aaa2
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import { isParentPath } from '../platform/fs-paths'; | ||
import { shellExec } from '../process/rawProcessApis'; | ||
|
||
/** | ||
* Returns true if interpreter path belongs to a poetry environment which is associated with a particular folder, | ||
* false otherwise. | ||
* @param interpreterPath Absolute path to any python interpreter. | ||
* @param folder Absolute path to the folder. | ||
*/ | ||
export async function isPoetryEnvironmentRelatedToFolder( | ||
interpreterPath: string, | ||
folder: string, | ||
poetryPath = 'poetry', | ||
): Promise<boolean> { | ||
try { | ||
const result = await shellExec(`${poetryPath} env info -p`, { cwd: folder, timeout: 15000 }, undefined); | ||
const pathToEnv = result.stdout.trim(); | ||
return isParentPath(interpreterPath, pathToEnv); | ||
} catch { | ||
return false; // No need to log error as this is expected if the project is not initialized for poetry. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters