From abfae9a57a8c78d1eb5aa43ca99a265f2a70a0d5 Mon Sep 17 00:00:00 2001 From: Andrew DiLosa Date: Mon, 16 May 2022 19:39:32 -0700 Subject: [PATCH] update to v4, remove python-version default * python-version overrides python-version-file, like setup-node * checks '.python-version' by default if nothing else specified --- README.md | 30 +++++++++++++++--------------- action.yml | 5 ++--- package.json | 2 +- src/setup-python.ts | 32 ++++++++++++++++++++------------ 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 44bc683d..feed544e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# setup-python V3 +# setup-python v4

GitHub Actions status @@ -30,7 +30,7 @@ Basic: ```yaml steps: - uses: actions/checkout@v3 -- uses: actions/setup-python@v3 +- uses: actions/setup-python@v4 with: python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified @@ -40,8 +40,8 @@ steps: Read Python version from file: ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-python@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 with: python-version-file: '.python-version' # Read python version from a file architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified @@ -60,7 +60,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} architecture: x64 @@ -84,7 +84,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Display Python version @@ -102,7 +102,7 @@ jobs: python-version: ['3.7.4', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - run: python my_script.py @@ -112,7 +112,7 @@ Download and set up an accurate pre-release version of Python: ```yaml steps: - uses: actions/checkout@v3 -- uses: actions/setup-python@v3 +- uses: actions/setup-python@v4 with: python-version: '3.11.0-alpha.1' - run: python my_script.py @@ -122,7 +122,7 @@ Download and set up the latest available version of Python (includes both pre-re ```yaml steps: - uses: actions/checkout@v3 -- uses: actions/setup-python@v3 +- uses: actions/setup-python@v4 with: python-version: '3.11.0-alpha - 3.11.0' # SemVer's version range syntax - run: python my_script.py @@ -142,7 +142,7 @@ jobs: - 'pypy-3.8' # the latest available version of PyPy that supports Python 3.8 steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - run: python my_script.py @@ -241,7 +241,7 @@ The requirements file format allows to specify dependency versions using logical ```yaml steps: - uses: actions/checkout@v3 -- uses: actions/setup-python@v3 +- uses: actions/setup-python@v4 with: python-version: '3.9' cache: 'pip' @@ -254,7 +254,7 @@ steps: - uses: actions/checkout@v3 - name: Install pipenv run: pipx install pipenv -- uses: actions/setup-python@v3 +- uses: actions/setup-python@v4 with: python-version: '3.9' cache: 'pipenv' @@ -267,7 +267,7 @@ steps: - uses: actions/checkout@v3 - name: Install poetry run: pipx install poetry -- uses: actions/setup-python@v3 +- uses: actions/setup-python@v4 with: python-version: '3.9' cache: 'poetry' @@ -279,7 +279,7 @@ steps: ```yaml steps: - uses: actions/checkout@v3 -- uses: actions/setup-python@v3 +- uses: actions/setup-python@v4 with: python-version: '3.9' cache: 'pip' @@ -293,7 +293,7 @@ steps: - uses: actions/checkout@v3 - name: Install pipenv run: pipx install pipenv -- uses: actions/setup-python@v3 +- uses: actions/setup-python@v4 with: python-version: '3.9' cache: 'pipenv' diff --git a/action.yml b/action.yml index df9adbd9..d0a2dbd5 100644 --- a/action.yml +++ b/action.yml @@ -4,10 +4,9 @@ description: 'Set up a specific version of Python and add the command-line tools author: 'GitHub' inputs: python-version: - description: "Version range or exact version of a Python version to use, using SemVer's version range syntax." - default: '3.x' + description: "Version range or exact version of Python to use, using SemVer's version range syntax. Reads from .python-version if unset." python-version-file: - description: "File containing the Python version to use. This overrides 'python-version' if specified. Examples: .python-version" + description: "File containing the Python version to use. Example: .python-version" cache: description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.' required: false diff --git a/package.json b/package.json index 235d0c35..2b2cb2e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-python", - "version": "3.1.1", + "version": "4.0.0", "private": true, "description": "Setup python action", "main": "dist/index.js", diff --git a/src/setup-python.ts b/src/setup-python.ts index d8e68ca6..457a565c 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -24,22 +24,30 @@ async function cacheDependencies(cache: string, pythonVersion: string) { function resolveVersionInput(): string { let version = core.getInput('python-version'); - const versionFileInput = core.getInput('python-version-file'); + const versionFile = core.getInput('python-version-file'); - if (versionFileInput) { - const versionFilePath = path.join( - process.env.GITHUB_WORKSPACE!, - versionFileInput + if (version && versionFile) { + core.warning( + 'Both python-version and python-version-file inputs are specified, only python-version will be used' ); - if (!fs.existsSync(versionFilePath)) { - throw new Error( - `The specified node version file at: ${versionFilePath} does not exist` - ); - } - version = fs.readFileSync(versionFilePath, 'utf8'); - core.info(`Resolved ${versionFileInput} as ${version}`); + } + + if (version) { + return version; } + const versionFilePath = path.join( + process.env.GITHUB_WORKSPACE!, + versionFile || ".python-version" + ); + if (!fs.existsSync(versionFilePath)) { + throw new Error( + `The specified python version file at: ${versionFilePath} does not exist` + ); + } + version = fs.readFileSync(versionFilePath, 'utf8'); + core.info(`Resolved ${versionFile} as ${version}`); + return version; }