@@ -5,7 +5,7 @@ import { GITHUB_ACTIONS } from "ci-info"
5
5
import { info , warning } from "ci-log"
6
6
import { execaSync } from "execa"
7
7
import memoize from "micro-memoize"
8
- import { dirname , join } from "patha"
8
+ import { addExeExt , dirname , join } from "patha"
9
9
import which from "which"
10
10
import { addPath } from "../utils/env/addEnv"
11
11
import { hasDnf } from "../utils/env/hasDnf"
@@ -20,6 +20,7 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
20
20
import { isBinUptoDate } from "../utils/setup/version"
21
21
import { unique } from "../utils/std"
22
22
import { DefaultVersions } from "../versions/default_versions"
23
+ import { pathExists } from "path-exists"
23
24
24
25
export async function setupPython ( version : string , setupDir : string , arch : string ) : Promise < InstallationInfo > {
25
26
const installInfo = await findOrSetupPython ( version , setupDir , arch )
@@ -47,7 +48,7 @@ export async function setupPython(version: string, setupDir: string, arch: strin
47
48
48
49
async function findOrSetupPython ( version : string , setupDir : string , arch : string ) {
49
50
let installInfo : InstallationInfo | undefined
50
- let foundPython = await findPython ( )
51
+ let foundPython = await findPython ( setupDir )
51
52
52
53
if ( foundPython !== undefined ) {
53
54
const binDir = dirname ( foundPython )
@@ -61,7 +62,7 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string
61
62
const { setupActionsPython } = await import ( "./actions_python" )
62
63
await setupActionsPython ( version , setupDir , arch )
63
64
64
- foundPython = ( await findPython ( ) ) !
65
+ foundPython = ( await findPython ( setupDir ) ) !
65
66
const binDir = dirname ( foundPython )
66
67
installInfo = { bin : foundPython , installDir : binDir , binDir }
67
68
} catch ( err ) {
@@ -74,8 +75,8 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string
74
75
}
75
76
}
76
77
77
- if ( foundPython === undefined ) {
78
- foundPython = ( await findPython ( ) ) !
78
+ if ( foundPython === undefined || installInfo . bin === undefined ) {
79
+ foundPython = ( await findPython ( setupDir ) ) !
79
80
installInfo . bin = foundPython
80
81
}
81
82
@@ -92,14 +93,11 @@ async function setupPythonSystem(setupDir: string, version: string) {
92
93
await setupChocoPack ( "python3" , version )
93
94
}
94
95
// Adding the bin dir to the path
95
- const pythonBinPath =
96
- which . sync ( "python3.exe" , { nothrow : true } ) ??
97
- which . sync ( "python.exe" , { nothrow : true } ) ??
98
- join ( setupDir , "python.exe" )
99
- const pythonSetupDir = dirname ( pythonBinPath )
96
+ const bin = ( await findPython ( setupDir ) ) !
97
+ const binDir = dirname ( bin )
100
98
/** The directory which the tool is installed to */
101
- await addPath ( pythonSetupDir )
102
- installInfo = { installDir : pythonSetupDir , binDir : pythonSetupDir }
99
+ await addPath ( binDir )
100
+ installInfo = { installDir : binDir , binDir, bin }
103
101
break
104
102
}
105
103
case "darwin" : {
@@ -125,7 +123,15 @@ async function setupPythonSystem(setupDir: string, version: string) {
125
123
return installInfo
126
124
}
127
125
128
- async function findPython ( ) {
126
+ async function findPython ( binDir ?: string ) {
127
+ if ( binDir !== undefined ) {
128
+ for ( const pythonBinPath of [ "python3" , "python" ] ) {
129
+ // eslint-disable-next-line no-await-in-loop
130
+ if ( await pathExists ( join ( binDir , addExeExt ( pythonBinPath ) ) ) ) {
131
+ return pythonBinPath
132
+ }
133
+ }
134
+ }
129
135
if ( which . sync ( "python3" , { nothrow : true } ) !== null ) {
130
136
return "python3"
131
137
} else if ( which . sync ( "python" , { nothrow : true } ) !== null && ( await isBinUptoDate ( "python" , "3.0.0" ) ) ) {
0 commit comments