Skip to content

Commit 3822413

Browse files
author
Kartik Raj
committed
Some more comments
1 parent 09c5842 commit 3822413

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/client/pythonEnvironments/common/environmentIdentifier.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,30 @@ function isLocalPipenvEnvironment(interpreterPath: string): boolean {
182182
* Returns true if interpreter path belongs to a global pipenv environment created for a particular project,
183183
* false otherwise.
184184
* @param interpreterPath Absolute path to any python interpreter.
185-
* @param cwd Absolute path to the project.
185+
* @param project Absolute path to the project.
186186
*/
187-
async function isGlobalPipenvEnvironmentRelatedToProject(interpreterPath: string, cwd: string): Promise<boolean> {
187+
async function isGlobalPipenvEnvironmentRelatedToProject(interpreterPath: string, project: string): Promise<boolean> {
188188
// PIPENV_NO_INHERIT is used to tell pipenv not to look for Pipfile in parent directories
189189
// https://pipenv.pypa.io/en/latest/advanced/#pipenv.environments.PIPENV_NO_INHERIT
190-
if (!checkIfPipFileExists(cwd, !process.env.PIPENV_NO_INHERIT)) {
190+
if (!checkIfPipFileExists(project, !process.env.PIPENV_NO_INHERIT)) {
191191
return false;
192192
}
193193

194-
// In PipEnv, for global environments the name of the cwd is used as a prefix in the virtual env.
195-
if (interpreterPath.indexOf(`${path.sep}${path.basename(cwd)}-`) === -1) {
196-
return false;
194+
/**
195+
* Global pipenv environments can be stored in 3 possible locations:
196+
* * WORKON_HOME environment variable: https://pipenv-fork.readthedocs.io/en/latest/advanced.html#custom-virtual-environment-location
197+
* * ~/.virtualenvs - for windows
198+
* * ~/.local/share/virtualenvs
199+
*
200+
* The name of the project is used as a prefix in the virtual env. We're assuming it's unique enough
201+
* detail so we don't have further ensure that the environment exists within these locations.
202+
*/
203+
if (interpreterPath.indexOf(`${path.sep}${path.basename(project)}-`) !== -1) {
204+
// Note it's still possible that this virtual environment belongs to another project with the same name,
205+
// and not this project. But the type of environment would still be pipenv, so we need not care.
206+
return true;
197207
}
198-
return true;
208+
return false;
199209
}
200210

201211
/**

0 commit comments

Comments
 (0)