1
1
import assert from "assert"
2
- /* eslint-disable require-atomic-updates */
2
+ import { homedir } from "os"
3
+ import { parse as pathParse } from "path"
3
4
import { getExecOutput } from "@actions/exec"
4
5
import { GITHUB_ACTIONS } from "ci-info"
5
6
import { info , warning } from "ci-log"
6
7
import { execa } from "execa"
8
+ import { readdir } from "fs/promises"
7
9
import memoize from "micro-memoize"
8
10
import { pathExists } from "path-exists"
9
11
import { addExeExt , dirname , join } from "patha"
@@ -89,7 +91,10 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string
89
91
const { setupActionsPython } = await import ( "./actions_python" )
90
92
await setupActionsPython ( version , setupDir , arch )
91
93
92
- foundPython = ( await findPython ( setupDir ) ) !
94
+ foundPython = await findPython ( setupDir )
95
+ if ( foundPython === undefined ) {
96
+ throw new Error ( "Python binary could not be found" )
97
+ }
93
98
const binDir = dirname ( foundPython )
94
99
installInfo = { bin : foundPython , installDir : binDir , binDir }
95
100
} catch ( err ) {
@@ -103,7 +108,10 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string
103
108
}
104
109
105
110
if ( foundPython === undefined || installInfo . bin === undefined ) {
106
- foundPython = ( await findPython ( setupDir ) ) !
111
+ foundPython = await findPython ( setupDir )
112
+ if ( foundPython === undefined ) {
113
+ throw new Error ( "Python binary could not be found" )
114
+ }
107
115
installInfo . bin = foundPython
108
116
}
109
117
@@ -120,7 +128,10 @@ async function setupPythonSystem(setupDir: string, version: string) {
120
128
await setupChocoPack ( "python3" , version )
121
129
}
122
130
// Adding the bin dir to the path
123
- const bin = ( await findPython ( setupDir ) ) !
131
+ const bin = await findPython ( setupDir )
132
+ if ( bin === undefined ) {
133
+ throw new Error ( "Python binary could not be found" )
134
+ }
124
135
const binDir = dirname ( bin )
125
136
/** The directory which the tool is installed to */
126
137
await addPath ( binDir )
@@ -166,6 +177,24 @@ async function findPython(binDir?: string) {
166
177
return foundPython
167
178
}
168
179
}
180
+
181
+ // On Windows, search in C:\PythonXX
182
+ if ( process . platform === "win32" ) {
183
+ const rootDir = pathParse ( homedir ( ) ) . root
184
+ // find all directories in rootDir using readdir
185
+ const pythonDirs = ( await readdir ( rootDir ) ) . filter ( ( dir ) => dir . startsWith ( "Python" ) )
186
+
187
+ for ( const pythonDir of pythonDirs ) {
188
+ for ( const pythonBin of [ "python3" , "python" ] ) {
189
+ // eslint-disable-next-line no-await-in-loop
190
+ const foundPython = await isPythonUpToDate ( pythonBin , join ( rootDir , pythonDir ) )
191
+ if ( foundPython !== undefined ) {
192
+ return foundPython
193
+ }
194
+ }
195
+ }
196
+ }
197
+
169
198
return undefined
170
199
}
171
200
0 commit comments