@@ -3,7 +3,7 @@ import { getExecOutput } from "@actions/exec"
33import assert from "assert"
44import { GITHUB_ACTIONS } from "ci-info"
55import { info , warning } from "ci-log"
6- import { execaSync } from "execa"
6+ import { execa } from "execa"
77import memoize from "micro-memoize"
88import { addExeExt , dirname , join } from "patha"
99import which from "which"
@@ -21,6 +21,7 @@ import { isBinUptoDate } from "../utils/setup/version"
2121import { unique } from "../utils/std"
2222import { MinVersions } from "../versions/default_versions"
2323import { pathExists } from "path-exists"
24+ import { setupPipPackWithPython } from "../utils/setup/setupPipPack"
2425
2526export async function setupPython ( version : string , setupDir : string , arch : string ) : Promise < InstallationInfo > {
2627 const installInfo = await findOrSetupPython ( version , setupDir , arch )
@@ -33,11 +34,12 @@ export async function setupPython(version: string, setupDir: string, arch: strin
3334 throw new Error ( "pip was not installed correctly" )
3435 }
3536
36- // setup wheel
37+ // setup wheel and setuptools
3738 try {
38- setupWheel ( foundPython )
39+ await setupPipPackWithPython ( foundPython , "setuptools" , undefined , true )
40+ await setupPipPackWithPython ( foundPython , "wheel" , undefined , true )
3941 } catch ( err ) {
40- warning ( `Failed to install wheels : ${ ( err as Error ) . toString ( ) } . Ignoring...` )
42+ warning ( `Failed to install setuptools or wheel : ${ ( err as Error ) . toString ( ) } . Ignoring...` )
4143 }
4244
4345 return installInfo
@@ -99,6 +101,11 @@ async function setupPythonSystem(setupDir: string, version: string) {
99101 }
100102 case "darwin" : {
101103 installInfo = await setupBrewPack ( "python3" , version )
104+ // add the python and pip binaries to the path
105+ const brewPythonPrefix = await execa ( "brew" , [ "--prefix" , "python" ] , { stdio : "pipe" } )
106+ const brewPythonBin = join ( brewPythonPrefix . stdout , "libexec" , "bin" )
107+ await addPath ( brewPythonBin )
108+
102109 break
103110 }
104111 case "linux" : {
@@ -107,7 +114,7 @@ async function setupPythonSystem(setupDir: string, version: string) {
107114 } else if ( hasDnf ( ) ) {
108115 installInfo = setupDnfPack ( "python3" , version )
109116 } else if ( isUbuntu ( ) ) {
110- installInfo = await setupAptPack ( [ { name : "python3" , version } ] )
117+ installInfo = await setupAptPack ( [ { name : "python3" , version } , { name : "python-is-python3" } ] )
111118 } else {
112119 throw new Error ( "Unsupported linux distributions" )
113120 }
@@ -194,23 +201,23 @@ async function isPipUptoDate(pip: string) {
194201}
195202
196203async function setupPip ( foundPython : string ) {
197- const upgraded = ensurePipUpgrade ( foundPython )
204+ const upgraded = await ensurePipUpgrade ( foundPython )
198205 if ( ! upgraded ) {
199206 await setupPipSystem ( )
200207 // upgrade pip
201- ensurePipUpgrade ( foundPython )
208+ await ensurePipUpgrade ( foundPython )
202209 }
203210}
204211
205- function ensurePipUpgrade ( foundPython : string ) {
212+ async function ensurePipUpgrade ( foundPython : string ) {
206213 try {
207- execaSync ( foundPython , [ "-m" , "ensurepip" , "-U" , "--upgrade" ] , { stdio : "inherit" } )
214+ await execa ( foundPython , [ "-m" , "ensurepip" , "-U" , "--upgrade" ] , { stdio : "inherit" } )
208215 return true
209216 } catch ( err1 ) {
210217 info ( ( err1 as Error ) ?. toString ?.( ) )
211218 try {
212219 // ensure pip is disabled on Ubuntu
213- execaSync ( foundPython , [ "-m" , "pip" , "install" , "--upgrade" , "pip" ] , { stdio : "inherit" } )
220+ await execa ( foundPython , [ "-m" , "pip" , "install" , "--upgrade" , "pip" ] , { stdio : "inherit" } )
214221 return true
215222 } catch ( err2 ) {
216223 info ( ( err2 as Error ) ?. toString ?.( ) )
@@ -235,11 +242,6 @@ function setupPipSystem() {
235242 throw new Error ( `Could not install pip on ${ process . platform } ` )
236243}
237244
238- /** Install wheel (required for Conan, Meson, etc.) */
239- function setupWheel ( foundPython : string ) {
240- execaSync ( foundPython , [ "-m" , "pip" , "install" , "-U" , "wheel" ] , { stdio : "inherit" } )
241- }
242-
243245async function addPythonBaseExecPrefix_raw ( python : string ) {
244246 const dirs : string [ ] = [ ]
245247
0 commit comments