@@ -5,56 +5,71 @@ import { info, warning } from "../utils/io/io"
55import { debug } from "@actions/core"
66import path from "path"
77import { isGitHubCI } from "../utils/env/isci"
8- import { cacheDependencies } from "./actions_cache"
8+ import { isCacheFeatureAvailable , IS_LINUX , IS_WINDOWS } from "setup-python/src/utils"
9+ import { getCacheDistributor } from "setup-python/src/cache-distributions/cache-factory"
910
1011function isPyPyVersion ( versionSpec : string ) {
1112 return versionSpec . startsWith ( "pypy" )
1213}
1314
14- // function resolveVersionInput(version: string): string {
15- // let versionFile = getInput("python-version-file")
15+ /*
16+ function resolveVersionInput(version: string): string {
17+ let versionFile = getInput("python-version-file")
1618
17- // if (version && versionFile) {
18- // warning("Both python-version and python-version-file inputs are specified, only python-version will be used")
19- // }
19+ if (version && versionFile) {
20+ warning("Both python-version and python-version-file inputs are specified, only python-version will be used")
21+ }
2022
21- // if (version) {
22- // return version
23- // }
23+ if (version) {
24+ return version
25+ }
2426
25- // versionFile = versionFile || ".python-version"
26- // if (!existsSync(versionFile)) {
27- // throw new Error(`The specified python version file at: ${versionFile} does not exist`)
28- // }
29- // version = readFileSync(versionFile, "utf8")
30- // info(`Resolved ${versionFile} as ${version}`)
27+ versionFile = versionFile || ".python-version"
28+ if (!existsSync(versionFile)) {
29+ throw new Error(`The specified python version file at: ${versionFile} does not exist`)
30+ }
31+ version = readFileSync(versionFile, "utf8")
32+ info(`Resolved ${versionFile} as ${version}`)
3133
32- // return version
33- // }
34+ return version
35+ }
36+ */
37+
38+ export async function cacheDependencies ( cache : string , pythonVersion : string ) {
39+ const cacheDependencyPath = undefined // core.getInput("cache-dependency-path") || undefined
40+ const cacheDistributor = getCacheDistributor ( cache , pythonVersion , cacheDependencyPath )
41+ await cacheDistributor . restoreCache ( )
42+ }
3443
3544export async function setupActionsPython ( version : string , _setupDir : string , arch : string ) {
36- if ( process . env . AGENT_TOOLSDIRECTORY ?. trim ( ) ) {
37- debug ( `Python is expected to be installed into AGENT_TOOLSDIRECTORY=${ process . env . AGENT_TOOLSDIRECTORY } ` )
45+ // According to the README windows binaries do not require to be installed
46+ // in the specific location, but Mac and Linux do
47+ if ( ! IS_WINDOWS && ! process . env . AGENT_TOOLSDIRECTORY ?. trim ( ) ) {
48+ if ( IS_LINUX ) {
49+ process . env . AGENT_TOOLSDIRECTORY = "/opt/hostedtoolcache"
50+ } else {
51+ process . env . AGENT_TOOLSDIRECTORY = "/Users/runner/hostedtoolcache"
52+ }
3853 process . env . RUNNER_TOOL_CACHE = process . env . AGENT_TOOLSDIRECTORY
39- } else {
40- debug ( `Python is expected to be installed into RUNNER_TOOL_CACHE==${ process . env . RUNNER_TOOL_CACHE } ` )
4154 }
55+ debug ( `Python is expected to be installed into RUNNER_TOOL_CACHE=${ process . env . RUNNER_TOOL_CACHE } ` )
4256 // const version = resolveVersionInput(versionGiven)
4357 if ( version ) {
4458 let pythonVersion : string
4559 if ( isPyPyVersion ( version ) ) {
46- const installed = await findPyPyVersion ( version , arch )
60+ const installed = await findPyPyVersion ( version , arch , true )
4761 pythonVersion = `${ installed . resolvedPyPyVersion } -${ installed . resolvedPythonVersion } `
4862 info ( `Successfully set up PyPy ${ installed . resolvedPyPyVersion } with Python (${ installed . resolvedPythonVersion } )` )
4963 } else {
50- const installed = await useCpythonVersion ( version , arch )
64+ const installed = await useCpythonVersion ( version , arch , true )
5165 pythonVersion = installed . version
5266 info ( `Successfully set up ${ installed . impl } (${ pythonVersion } )` )
5367 }
5468
55- const cache = "pip" // core.getInput("cache") // package manager used for caching
56-
57- await cacheDependencies ( cache , pythonVersion )
69+ if ( isCacheFeatureAvailable ( ) ) {
70+ const cache = "pip" // core.getInput("cache") // package manager used for caching
71+ await cacheDependencies ( cache , pythonVersion )
72+ }
5873 }
5974
6075 if ( isGitHubCI ( ) ) {
0 commit comments