|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 |
| -import { pathExists } from 'fs-extra'; |
5 | 4 | import * as path from 'path';
|
6 | 5 | import { getEnvironmentVariable } from '../../../../common/utils/platform';
|
7 |
| -import { readFile } from '../../../common/externalDependencies'; |
| 6 | +import { pathExists, readFile } from '../../../common/externalDependencies'; |
8 | 7 |
|
9 | 8 | /**
|
10 | 9 | * Returns the path to Pipfile associated with the provided directory.
|
@@ -39,29 +38,6 @@ async function getAssociatedPipfile(
|
39 | 38 | return undefined;
|
40 | 39 | }
|
41 | 40 |
|
42 |
| -/** |
43 |
| - * Returns true if interpreter path belongs to a global pipenv environment which is associated with a particular folder, |
44 |
| - * false otherwise. |
45 |
| - * @param interpreterPath Absolute path to any python interpreter. |
46 |
| - */ |
47 |
| -export async function isPipenvEnvironmentRelatedToFolder(interpreterPath: string, folder: string): Promise<boolean> { |
48 |
| - const pipFileCorrespondingToEnvironment = await getPipfileIfGlobalPipenvEnvironment(interpreterPath); |
49 |
| - if (!pipFileCorrespondingToEnvironment) { |
50 |
| - return false; |
51 |
| - } |
52 |
| - const projectCorrespondingToEnvironment = path.dirname(pipFileCorrespondingToEnvironment); |
53 |
| - |
54 |
| - // PIPENV_NO_INHERIT is used to tell pipenv not to look for Pipfile in parent directories |
55 |
| - // https://pipenv.pypa.io/en/latest/advanced/#pipenv.environments.PIPENV_NO_INHERIT |
56 |
| - const pipFile = await getAssociatedPipfile(folder, !getEnvironmentVariable('PIPENV_NO_INHERIT')); |
57 |
| - if (!pipFile) { |
58 |
| - return false; |
59 |
| - } |
60 |
| - const projectCorrespondingToFolder = path.dirname(pipFile); |
61 |
| - |
62 |
| - return projectCorrespondingToEnvironment === projectCorrespondingToFolder; |
63 |
| -} |
64 |
| - |
65 | 41 | /**
|
66 | 42 | * If interpreter path belongs to a pipenv environment which is located inside a project, return associated Pipfile,
|
67 | 43 | * otherwise return `undefined`.
|
@@ -129,3 +105,23 @@ export async function isPipenvEnvironment(interpreterPath: string): Promise<bool
|
129 | 105 | }
|
130 | 106 | return false;
|
131 | 107 | }
|
| 108 | + |
| 109 | +/** |
| 110 | + * Returns true if interpreter path belongs to a global pipenv environment which is associated with a particular folder, |
| 111 | + * false otherwise. |
| 112 | + * @param interpreterPath Absolute path to any python interpreter. |
| 113 | + */ |
| 114 | +export async function isPipenvEnvironmentRelatedToFolder(interpreterPath: string, folder: string): Promise<boolean> { |
| 115 | + const pipFileAssociatedWithEnvironment = await getPipfileIfGlobalPipenvEnvironment(interpreterPath); |
| 116 | + if (!pipFileAssociatedWithEnvironment) { |
| 117 | + return false; |
| 118 | + } |
| 119 | + |
| 120 | + // PIPENV_NO_INHERIT is used to tell pipenv not to look for Pipfile in parent directories |
| 121 | + // https://pipenv.pypa.io/en/latest/advanced/#pipenv.environments.PIPENV_NO_INHERIT |
| 122 | + const pipFileAssociatedWithFolder = await getAssociatedPipfile(folder, !getEnvironmentVariable('PIPENV_NO_INHERIT')); |
| 123 | + if (!pipFileAssociatedWithFolder) { |
| 124 | + return false; |
| 125 | + } |
| 126 | + return pipFileAssociatedWithEnvironment === pipFileAssociatedWithFolder; |
| 127 | +} |
0 commit comments