mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 07:22:14 +00:00
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
This commit is contained in:
parent
dbfda6e73c
commit
abfae9a57a
4 changed files with 38 additions and 31 deletions
30
README.md
30
README.md
|
@ -1,4 +1,4 @@
|
||||||
# setup-python V3
|
# setup-python v4
|
||||||
|
|
||||||
<p align="left">
|
<p align="left">
|
||||||
<a href="https://github.com/actions/setup-python"><img alt="GitHub Actions status" src="https://github.com/actions/setup-python/workflows/Main%20workflow/badge.svg"></a>
|
<a href="https://github.com/actions/setup-python"><img alt="GitHub Actions status" src="https://github.com/actions/setup-python/workflows/Main%20workflow/badge.svg"></a>
|
||||||
|
@ -30,7 +30,7 @@ Basic:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
|
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
|
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
|
||||||
|
@ -40,8 +40,8 @@ steps:
|
||||||
Read Python version from file:
|
Read Python version from file:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version-file: '.python-version' # Read python version from a file
|
python-version-file: '.python-version' # Read python version from a file
|
||||||
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
|
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
|
||||||
|
@ -60,7 +60,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
architecture: x64
|
architecture: x64
|
||||||
|
@ -84,7 +84,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
- name: Display Python version
|
- name: Display Python version
|
||||||
|
@ -102,7 +102,7 @@ jobs:
|
||||||
python-version: ['3.7.4', '3.8', '3.9', '3.10']
|
python-version: ['3.7.4', '3.8', '3.9', '3.10']
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
- run: python my_script.py
|
- run: python my_script.py
|
||||||
|
@ -112,7 +112,7 @@ Download and set up an accurate pre-release version of Python:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.11.0-alpha.1'
|
python-version: '3.11.0-alpha.1'
|
||||||
- run: python my_script.py
|
- run: python my_script.py
|
||||||
|
@ -122,7 +122,7 @@ Download and set up the latest available version of Python (includes both pre-re
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.11.0-alpha - 3.11.0' # SemVer's version range syntax
|
python-version: '3.11.0-alpha - 3.11.0' # SemVer's version range syntax
|
||||||
- run: python my_script.py
|
- run: python my_script.py
|
||||||
|
@ -142,7 +142,7 @@ jobs:
|
||||||
- 'pypy-3.8' # the latest available version of PyPy that supports Python 3.8
|
- 'pypy-3.8' # the latest available version of PyPy that supports Python 3.8
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
- run: python my_script.py
|
- run: python my_script.py
|
||||||
|
@ -241,7 +241,7 @@ The requirements file format allows to specify dependency versions using logical
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.9'
|
||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
|
@ -254,7 +254,7 @@ steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Install pipenv
|
- name: Install pipenv
|
||||||
run: pipx install pipenv
|
run: pipx install pipenv
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.9'
|
||||||
cache: 'pipenv'
|
cache: 'pipenv'
|
||||||
|
@ -267,7 +267,7 @@ steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Install poetry
|
- name: Install poetry
|
||||||
run: pipx install poetry
|
run: pipx install poetry
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.9'
|
||||||
cache: 'poetry'
|
cache: 'poetry'
|
||||||
|
@ -279,7 +279,7 @@ steps:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.9'
|
||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
|
@ -293,7 +293,7 @@ steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Install pipenv
|
- name: Install pipenv
|
||||||
run: pipx install pipenv
|
run: pipx install pipenv
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.9'
|
||||||
cache: 'pipenv'
|
cache: 'pipenv'
|
||||||
|
|
|
@ -4,10 +4,9 @@ description: 'Set up a specific version of Python and add the command-line tools
|
||||||
author: 'GitHub'
|
author: 'GitHub'
|
||||||
inputs:
|
inputs:
|
||||||
python-version:
|
python-version:
|
||||||
description: "Version range or exact version of a Python version to use, using SemVer's version range syntax."
|
description: "Version range or exact version of Python to use, using SemVer's version range syntax. Reads from .python-version if unset."
|
||||||
default: '3.x'
|
|
||||||
python-version-file:
|
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:
|
cache:
|
||||||
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.'
|
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.'
|
||||||
required: false
|
required: false
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "setup-python",
|
"name": "setup-python",
|
||||||
"version": "3.1.1",
|
"version": "4.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Setup python action",
|
"description": "Setup python action",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|
|
@ -24,21 +24,29 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
|
||||||
|
|
||||||
function resolveVersionInput(): string {
|
function resolveVersionInput(): string {
|
||||||
let version = core.getInput('python-version');
|
let version = core.getInput('python-version');
|
||||||
const versionFileInput = core.getInput('python-version-file');
|
const versionFile = core.getInput('python-version-file');
|
||||||
|
|
||||||
|
if (version && versionFile) {
|
||||||
|
core.warning(
|
||||||
|
'Both python-version and python-version-file inputs are specified, only python-version will be used'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
if (versionFileInput) {
|
|
||||||
const versionFilePath = path.join(
|
const versionFilePath = path.join(
|
||||||
process.env.GITHUB_WORKSPACE!,
|
process.env.GITHUB_WORKSPACE!,
|
||||||
versionFileInput
|
versionFile || ".python-version"
|
||||||
);
|
);
|
||||||
if (!fs.existsSync(versionFilePath)) {
|
if (!fs.existsSync(versionFilePath)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The specified node version file at: ${versionFilePath} does not exist`
|
`The specified python version file at: ${versionFilePath} does not exist`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
version = fs.readFileSync(versionFilePath, 'utf8');
|
version = fs.readFileSync(versionFilePath, 'utf8');
|
||||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
core.info(`Resolved ${versionFile} as ${version}`);
|
||||||
}
|
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue