mirror of
https://github.com/actions/setup-python.git
synced 2025-04-25 07:52:12 +00:00
Merge branch 'actions:main' into main
This commit is contained in:
commit
755680b3c0
6 changed files with 72 additions and 41 deletions
27
.github/workflows/test-python.yml
vendored
27
.github/workflows/test-python.yml
vendored
|
@ -120,3 +120,30 @@ jobs:
|
||||||
- name: Run simple code
|
- name: Run simple code
|
||||||
run: python -c 'import math; print(math.factorial(5))'
|
run: python -c 'import math; print(math.factorial(5))'
|
||||||
|
|
||||||
|
setup-dev-version:
|
||||||
|
name: Setup 3.9-dev ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: setup-python 3.9-dev
|
||||||
|
id: setup-python
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
python-version: '3.9-dev'
|
||||||
|
|
||||||
|
- name: Check python-path
|
||||||
|
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Validate version
|
||||||
|
run: ${{ startsWith(steps.setup-python.outputs.python-version, '3.9.') }}
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Run simple code
|
||||||
|
run: python -c 'import math; print(math.factorial(5))'
|
||||||
|
|
43
README.md
43
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>
|
||||||
|
@ -20,6 +20,7 @@ This action sets up a Python environment for use in actions by:
|
||||||
- Support for pre-release versions of Python.
|
- Support for pre-release versions of Python.
|
||||||
- Support for installing any version of PyPy on-flight
|
- Support for installing any version of PyPy on-flight
|
||||||
- Support for built-in caching of pip, pipenv and poetry dependencies
|
- Support for built-in caching of pip, pipenv and poetry dependencies
|
||||||
|
- Support for `.python-version` file
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
|
@ -29,13 +30,23 @@ 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
|
||||||
- run: python my_script.py
|
- run: python my_script.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Read Python version from file:
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version-file: '.python-version' # Read python version from a file
|
||||||
|
- run: python my_script.py
|
||||||
|
```
|
||||||
|
|
||||||
Matrix Testing:
|
Matrix Testing:
|
||||||
```yaml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
|
@ -48,7 +59,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
|
||||||
|
@ -72,7 +83,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
|
||||||
|
@ -90,7 +101,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
|
||||||
|
@ -100,7 +111,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
|
||||||
|
@ -110,7 +121,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
|
||||||
|
@ -130,7 +141,7 @@ jobs:
|
||||||
- 'pypy3.8' # the latest available version of PyPy that supports Python 3.8
|
- 'pypy3.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
|
||||||
|
@ -144,13 +155,15 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v4
|
||||||
id: cp310
|
id: cp310
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.10"
|
||||||
- run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version
|
- run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
>The environment variable `pythonLocation` also becomes available after Python or PyPy installation. It contains the absolute path to the folder where the desired version of Python or PyPy is installed.
|
||||||
|
|
||||||
# Getting started with Python + Actions
|
# Getting started with Python + Actions
|
||||||
|
|
||||||
Check out our detailed guide on using [Python with GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-python-with-github-actions).
|
Check out our detailed guide on using [Python with GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-python-with-github-actions).
|
||||||
|
@ -164,7 +177,7 @@ Check out our detailed guide on using [Python with GitHub Actions](https://help.
|
||||||
- For every minor version of Python, expect only the latest patch to be preinstalled.
|
- For every minor version of Python, expect only the latest patch to be preinstalled.
|
||||||
- If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache.
|
- If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache.
|
||||||
- If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache.
|
- If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache.
|
||||||
- Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest release of a minor version, *alpha and beta releases included*.
|
- Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest patch version release for a given minor version, *alpha and beta releases included*.
|
||||||
- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)).
|
- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)).
|
||||||
- All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file.
|
- All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file.
|
||||||
- If there is a specific version of Python that is not available, you can open an issue here
|
- If there is a specific version of Python that is not available, you can open an issue here
|
||||||
|
@ -243,7 +256,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'
|
||||||
|
@ -256,7 +269,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'
|
||||||
|
@ -269,7 +282,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'
|
||||||
|
@ -281,7 +294,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'
|
||||||
|
@ -295,7 +308,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'
|
||||||
|
|
13
dist/setup/index.js
vendored
13
dist/setup/index.js
vendored
|
@ -63993,7 +63993,7 @@ function findPyPyVersion(versionSpec, architecture) {
|
||||||
const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : '';
|
const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : '';
|
||||||
const pythonPath = path.join(utils_1.IS_WINDOWS ? installDir : _binDir, `python${binaryExtension}`);
|
const pythonPath = path.join(utils_1.IS_WINDOWS ? installDir : _binDir, `python${binaryExtension}`);
|
||||||
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
|
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
|
||||||
core.exportVariable('pythonLocation', pythonLocation);
|
core.exportVariable('pythonLocation', installDir);
|
||||||
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
|
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
|
||||||
core.addPath(pythonLocation);
|
core.addPath(pythonLocation);
|
||||||
core.addPath(_binDir);
|
core.addPath(_binDir);
|
||||||
|
@ -64183,15 +64183,10 @@ function useCpythonVersion(version, architecture) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.useCpythonVersion = useCpythonVersion;
|
exports.useCpythonVersion = useCpythonVersion;
|
||||||
/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */
|
/** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */
|
||||||
function desugarDevVersion(versionSpec) {
|
function desugarDevVersion(versionSpec) {
|
||||||
if (versionSpec.endsWith('-dev')) {
|
const devVersion = /^(\d+)\.(\d+)-dev$/;
|
||||||
const versionRoot = versionSpec.slice(0, -'-dev'.length);
|
return versionSpec.replace(devVersion, '~$1.$2.0-0');
|
||||||
return `>= ${versionRoot}.0-a0`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return versionSpec;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/** Extracts python version from install path from hosted tool cache as described in README.md */
|
/** Extracts python version from install path from hosted tool cache as described in README.md */
|
||||||
function versionFromPath(installDir) {
|
function versionFromPath(installDir) {
|
||||||
|
|
|
@ -45,8 +45,8 @@ We won't pursue the goal to provide wide customization of caching in the scope o
|
||||||
|
|
||||||
```
|
```
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: 3.9
|
python-version: 3.9
|
||||||
cache: pip
|
cache: pip
|
||||||
|
@ -56,8 +56,8 @@ steps:
|
||||||
|
|
||||||
```
|
```
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: 3.9
|
python-version: 3.9
|
||||||
cache: pipenv
|
cache: pipenv
|
||||||
|
@ -66,8 +66,8 @@ steps:
|
||||||
|
|
||||||
```
|
```
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: 3.9
|
python-version: 3.9
|
||||||
cache: pip
|
cache: pip
|
||||||
|
@ -80,8 +80,8 @@ steps:
|
||||||
|
|
||||||
```
|
```
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: 3.9
|
python-version: 3.9
|
||||||
cache: pip
|
cache: pip
|
||||||
|
|
|
@ -54,7 +54,7 @@ export async function findPyPyVersion(
|
||||||
`python${binaryExtension}`
|
`python${binaryExtension}`
|
||||||
);
|
);
|
||||||
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
|
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
|
||||||
core.exportVariable('pythonLocation', pythonLocation);
|
core.exportVariable('pythonLocation', installDir);
|
||||||
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
|
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
|
||||||
core.addPath(pythonLocation);
|
core.addPath(pythonLocation);
|
||||||
core.addPath(_binDir);
|
core.addPath(_binDir);
|
||||||
|
|
|
@ -117,14 +117,10 @@ export async function useCpythonVersion(
|
||||||
return {impl: 'CPython', version: installed};
|
return {impl: 'CPython', version: installed};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */
|
/** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */
|
||||||
function desugarDevVersion(versionSpec: string) {
|
function desugarDevVersion(versionSpec: string) {
|
||||||
if (versionSpec.endsWith('-dev')) {
|
const devVersion = /^(\d+)\.(\d+)-dev$/;
|
||||||
const versionRoot = versionSpec.slice(0, -'-dev'.length);
|
return versionSpec.replace(devVersion, '~$1.$2.0-0');
|
||||||
return `>= ${versionRoot}.0-a0`;
|
|
||||||
} else {
|
|
||||||
return versionSpec;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Extracts python version from install path from hosted tool cache as described in README.md */
|
/** Extracts python version from install path from hosted tool cache as described in README.md */
|
||||||
|
|
Loading…
Add table
Reference in a new issue