Add support for .tool-versions file in setup-python (#1043)

* add support for .tool-versions file

* update regex

* optimize code

* update test-python.yml for .tool-versions

* fix format-check errors

* fix formatting in test-python.yml

* Fix test-python.yml error

* workflow update with latest versions

* update test cases

* fix lint issue
This commit is contained in:
mahabaleshwars
2025-03-13 20:51:27 +05:30
committed by GitHub
parent 6fd11e170a
commit 19e4675e06
5 changed files with 193 additions and 6 deletions

View File

@ -278,9 +278,9 @@ jobs:
## Using the `python-version-file` input
`setup-python` action can read the Python or PyPy version from a version file. `python-version-file` input is used to specify the path to the version file. If the file that was supplied to `python-version-file` input doesn't exist, the action will fail with an error.
`setup-python` action can read Python or PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the file that was supplied to `python-version-file` input doesn't exist, the action will fail with error.
>In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority.
>In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority. The .tool-versions file supports version specifications in accordance with asdf standards, adhering to Semantic Versioning ([semver](https://semver.org)).
```yaml
steps:
@ -300,6 +300,15 @@ steps:
- run: python my_script.py
```
```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: '.tool-versions' # Read python version from a file .tool-versions
- run: python my_script.py
```
## Check latest version
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python or PyPy` version is always used.