@@ -8,27 +8,34 @@ import { setupPython } from "../../python/python"
8
8
import { isBinUptoDate } from "./version"
9
9
import { join } from "path"
10
10
import { getVersion } from "../../default_versions"
11
+ import { InstallationInfo } from "./setupBin"
11
12
12
- let pip : string | undefined
13
-
13
+ let python : string | undefined
14
14
let binDir : string | undefined
15
15
16
+ let tried = false
17
+
16
18
/** A function that installs a package using pip */
17
- export async function setupPipPack ( name : string , version ?: string ) {
19
+ export async function setupPipPack ( name : string , version ?: string ) : Promise < InstallationInfo > {
18
20
// setup python and pip if needed
19
- if ( pip === undefined ) {
20
- if ( which . sync ( "pip3 " , { nothrow : true } ) !== null ) {
21
- pip = "pip3 "
22
- } else if ( which . sync ( "pip " , { nothrow : true } ) !== null && ( await isBinUptoDate ( "python" , "3.0.0" ) ) ) {
23
- pip = "pip "
21
+ if ( python === undefined ) {
22
+ if ( which . sync ( "python3 " , { nothrow : true } ) !== null ) {
23
+ python = "python3 "
24
+ } else if ( which . sync ( "python " , { nothrow : true } ) !== null && ( await isBinUptoDate ( "python" , "3.0.0" ) ) ) {
25
+ python = "python "
24
26
} else {
25
- info ( "pip3 was not found. Installing python" )
27
+ info ( "python3 was not found. Installing python" )
26
28
await setupPython ( getVersion ( "python" , undefined ) , "" , process . arch )
27
- pip = "pip3"
29
+ // try again
30
+ if ( tried ) {
31
+ throw new Error ( "Failed to install python" )
32
+ }
33
+ tried = true
34
+ return setupPipPack ( name , version )
28
35
}
29
36
}
30
37
31
- execa . sync ( pip , [ "install" , version !== undefined && version !== "" ? `${ name } ==${ version } ` : name ] , {
38
+ execa . sync ( python , [ "-m" , "pip" , "install" , version !== undefined && version !== "" ? `${ name } ==${ version } ` : name ] , {
32
39
stdio : "inherit" ,
33
40
} )
34
41
@@ -41,12 +48,12 @@ export async function setupPipPack(name: string, version?: string) {
41
48
// windows or others
42
49
try {
43
50
binDir = join (
44
- ( await getExecOutput ( `python3 -c "import sys;print(sys.base_exec_prefix);"` ) ) . stdout . trim ( ) ,
51
+ ( await getExecOutput ( `${ python } -c "import sys;print(sys.base_exec_prefix);"` ) ) . stdout . trim ( ) ,
45
52
"Scripts"
46
53
)
47
54
} catch {
48
55
binDir = join (
49
- ( await getExecOutput ( ' python -c "import sys;print(sys.base_exec_prefix);"' ) ) . stdout . trim ( ) ,
56
+ ( await getExecOutput ( ` ${ python } -c "import sys;print(sys.base_exec_prefix);"` ) ) . stdout . trim ( ) ,
50
57
"Scripts"
51
58
)
52
59
}
0 commit comments