@@ -6,20 +6,20 @@ import { traceError } from '../../../../common/logger';
6
6
import { getEnvironmentVariable } from '../../../../common/utils/platform' ;
7
7
import { arePathsSame , pathExists , readFile } from '../../../common/externalDependencies' ;
8
8
9
- function getSearchDepth ( ) {
9
+ function getSearchHeight ( ) {
10
10
// PIPENV_MAX_DEPTH tells pipenv the maximum number of directories to recursively search for
11
11
// a Pipfile, defaults to 3: https://pipenv.pypa.io/en/latest/advanced/#pipenv.environments.PIPENV_MAX_DEPTH
12
12
const maxDepthStr = getEnvironmentVariable ( 'PIPENV_MAX_DEPTH' ) ;
13
- if ( maxDepthStr ! == undefined ) {
14
- const maxDepth = parseInt ( maxDepthStr , 10 ) ;
15
- // eslint-disable-next-line no-restricted-globals
16
- if ( isNaN ( maxDepth ) ) {
17
- traceError ( `PIPENV_MAX_DEPTH is incorrectly set. Converting value ' ${ maxDepthStr } ' to number results in NaN` ) ;
18
- return 1 ;
19
- }
20
- return maxDepth ;
13
+ if ( maxDepthStr = == undefined ) {
14
+ return 3 ;
15
+ }
16
+ const maxDepth = parseInt ( maxDepthStr , 10 ) ;
17
+ // eslint-disable-next-line no-restricted-globals
18
+ if ( isNaN ( maxDepth ) ) {
19
+ traceError ( `PIPENV_MAX_DEPTH is incorrectly set. Converting value ' ${ maxDepthStr } ' to number results in NaN` ) ;
20
+ return 1 ;
21
21
}
22
- return 3 ;
22
+ return maxDepth ;
23
23
}
24
24
25
25
/**
@@ -32,15 +32,15 @@ export async function _getAssociatedPipfile(
32
32
options : { lookIntoParentDirectories : boolean } ,
33
33
) : Promise < string | undefined > {
34
34
const pipFileName = getEnvironmentVariable ( 'PIPENV_PIPFILE' ) || 'Pipfile' ;
35
- let depthToSearch = options . lookIntoParentDirectories ? getSearchDepth ( ) : 1 ;
36
- while ( depthToSearch > 0 && ! arePathsSame ( searchDir , path . dirname ( searchDir ) ) ) {
35
+ let heightToSearch = options . lookIntoParentDirectories ? getSearchHeight ( ) : 1 ;
36
+ while ( heightToSearch > 0 && ! arePathsSame ( searchDir , path . dirname ( searchDir ) ) ) {
37
37
const pipFile = path . join ( searchDir , pipFileName ) ;
38
38
// eslint-disable-next-line no-await-in-loop
39
39
if ( await pathExists ( pipFile ) ) {
40
40
return pipFile ;
41
41
}
42
42
searchDir = path . dirname ( searchDir ) ;
43
- depthToSearch -= 1 ;
43
+ heightToSearch -= 1 ;
44
44
}
45
45
return undefined ;
46
46
}
@@ -97,8 +97,8 @@ async function getProjectDir(envFolder: string): Promise<string | undefined> {
97
97
*/
98
98
async function getPipfileIfGlobal ( interpreterPath : string ) : Promise < string | undefined > {
99
99
const envFolder = path . dirname ( path . dirname ( interpreterPath ) ) ;
100
- const project = await getProjectDir ( envFolder ) ;
101
- if ( project === undefined ) {
100
+ const projectDir = await getProjectDir ( envFolder ) ;
101
+ if ( projectDir === undefined ) {
102
102
return undefined ;
103
103
}
104
104
@@ -107,11 +107,11 @@ async function getPipfileIfGlobal(interpreterPath: string): Promise<string | und
107
107
// |__ Pipfile <--- check if Pipfile exists here and return it
108
108
// The name of the project (directory where Pipfile resides) is used as a prefix in the environment folder
109
109
const envFolderName = path . basename ( envFolder ) ;
110
- if ( ! envFolderName . startsWith ( ` ${ path . basename ( project ) } -` ) ) {
110
+ if ( ! envFolderName . match ( new RegExp ( `^ ${ path . basename ( projectDir ) } -[0-9a-fA-F]+$` ) ) === null ) {
111
111
return undefined ;
112
112
}
113
113
114
- return _getAssociatedPipfile ( project , { lookIntoParentDirectories : false } ) ;
114
+ return _getAssociatedPipfile ( projectDir , { lookIntoParentDirectories : false } ) ;
115
115
}
116
116
117
117
/**
0 commit comments