Skip to content

Commit 746f28a

Browse files
author
IvanZosimov
committed
Update REAMDE.md and advanced-usage.md
1 parent 6dd8ff7 commit 746f28a

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This action provides the following functionality for GitHub Actions users:
2424

2525
See [action.yml](action.yml)
2626

27+
**Python**
2728
```yaml
2829
steps:
2930
- uses: actions/checkout@v3
@@ -32,6 +33,16 @@ steps:
3233
python-version: '3.10'
3334
- run: python my_script.py
3435
```
36+
37+
**PyPy**
38+
```yaml
39+
steps:
40+
- uses: actions/checkout@v3
41+
- uses: actions/setup-python@v4
42+
with:
43+
python-version: 'pypy3.7'
44+
- run: python my_script.py
45+
```
3546
The `python-version` input is optional. If not supplied, the Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH vary between runners and can be changed unexpectedly so we recommend always use `setup-python`.
3647

3748
The action will first check the local [tool cache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/).
@@ -40,11 +51,11 @@ For information regarding locally cached versions of Python/PyPy on GitHub hoste
4051

4152
## Supported version syntax
4253

43-
The `python-version` input supports the [Semantic Versioning Specification](https://github.com/npm/node-semver#versions) and some special version notations (e.g. `x.y-dev`), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide.
54+
The `python-version` input supports the [Semantic Versioning Specification](https://semver.org/) and some special version notations (e.g. `semver ranges`, `x.y-dev syntax`, etc), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide.
4455

4556
## Supported architectures
4657

47-
Using `architecture` input it's possible to specify required python's interpreter architecture: `x86` or `x64`. If input is not specified it defaults to `x64`.
58+
Using `architecture` input it's possible to specify required python's interpreter architecture: `x86` or `x64`. If input is not specified the architecture defaults to `x64`.
4859

4960
## Caching packages dependencies
5061

docs/advanced-usage.md

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ steps:
3636
- The only downside to this is that set up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions.
3737
- MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux.
3838
39-
You should specify **only a major and minor version** if you are okay with the most recent patch version being used:
39+
You can specify **only a major and minor version** if you are okay with the most recent patch version being used:
4040
4141
```yaml
4242
steps:
@@ -72,7 +72,7 @@ steps:
7272
- run: python my_script.py
7373
```
7474
75-
You can also use several types of ranges that are specified in [Semantic Versioning Specification](https://github.com/npm/node-semver#ranges), for instance:
75+
You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance:
7676
7777
- **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions):
7878
@@ -95,14 +95,13 @@ steps:
9595
python-version: '3.x'
9696
- run: python my_script.py
9797
```
98-
Please refer to the [Advanced range syntax section](https://github.com/npm/node-semver#advanced-range-syntax) of the [Semantic Versioning Specification](https://github.com/npm/node-semver) to check other available range syntaxes.
98+
Please refer to the [Advanced range syntax section](https://github.com/npm/node-semver#advanced-range-syntax) of the [semver](https://github.com/npm/node-semver) to check other available range syntaxes.
9999
100100
## Specifying a PyPy version
101101
The version of PyPy should be specified in the format `pypy<python_version>[-v<pypy_version>]` or `pypy-<python_version>[-v<pypy_version>]`.
102102
The `-v<pypy_version>` parameter is optional and can be skipped. The latest PyPy version will be used in this case.
103103

104104
```
105-
pypy3.7 or pypy-3.7 # the latest available version of PyPy that supports Python 3.7
106105
pypy3.8 or pypy-3.8 # the latest available version of PyPy that supports Python 3.8
107106
pypy2.7 or pypy-2.7 # the latest available version of PyPy that supports Python 2.7
108107
pypy3.7-v7.3.3 or pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3
@@ -122,15 +121,14 @@ jobs:
122121
python-version:
123122
- 'pypy3.7' # the latest available version of PyPy that supports Python 3.7
124123
- 'pypy3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3
125-
- 'pypy3.8' # the latest available version of PyPy that supports Python 3.8
126124
steps:
127125
- uses: actions/checkout@v3
128126
- uses: actions/setup-python@v4
129127
with:
130128
python-version: ${{ matrix.python-version }}
131129
- run: python my_script.py
132130
```
133-
More details on PyPy syntax and examples of using preview / nightly versions of PyPy can be found in the [Available versions of PyPy](#pypy) section.
131+
More details on PyPy syntax can be found in the [Available versions of PyPy](#pypy) section.
134132

135133
## Matrix Testing
136134

@@ -239,17 +237,6 @@ steps:
239237
- run: poetry install
240238
- run: poetry run pytest
241239
```
242-
**Using wildcard patterns to cache dependencies**
243-
```yaml
244-
steps:
245-
- uses: actions/checkout@v3
246-
- uses: actions/setup-python@v4
247-
with:
248-
python-version: '3.9'
249-
cache: 'pip'
250-
cache-dependency-path: '**/requirements-dev.txt'
251-
- run: pip install -r subdirectory/requirements-dev.txt
252-
```
253240

254241
**Using a list of file paths to cache dependencies**
255242
```yaml
@@ -266,6 +253,17 @@ steps:
266253
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
267254
- run: pipenv install
268255
```
256+
**Using wildcard patterns to cache dependencies**
257+
```yaml
258+
steps:
259+
- uses: actions/checkout@v3
260+
- uses: actions/setup-python@v4
261+
with:
262+
python-version: '3.9'
263+
cache: 'pip'
264+
cache-dependency-path: '**/requirements-dev.txt'
265+
- run: pip install -r subdirectory/requirements-dev.txt
266+
```
269267

270268
**Using a list of wildcard patterns to cache dependencies**
271269
```yaml
@@ -287,7 +285,7 @@ steps:
287285

288286
### `python-version`
289287

290-
Using **python-version** output it's possible to get the installed by action python's version. This output is useful when the input `python-version` given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with exact installed version (e.g. 3.10.1).
288+
Using **python-version** output it's possible to get the installed by action Pytho/PyPy version. This output is useful when the input `python-version` given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1).
291289

292290
```yaml
293291
jobs:
@@ -304,7 +302,7 @@ jobs:
304302

305303
### `python-path`
306304

307-
**python-path** output is available with the absolute path of the python interpreter executable if you need it:
305+
**python-path** output is available with the absolute path of the Python/PyPy interpreter executable if you need it:
308306

309307
```yaml
310308
jobs:
@@ -318,12 +316,29 @@ jobs:
318316
python-version: "3.10"
319317
- run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version
320318
```
319+
### `cache-hit`
320+
321+
**cache-hit** output is available with a boolean value that indicates whether a cache hit occured on the primary key:
322+
323+
```
324+
jobs:
325+
build:
326+
runs-on: ubuntu-latest
327+
steps:
328+
- uses: actions/checkout@v3
329+
- uses: actions/setup-python@v4
330+
id: cp310
331+
with:
332+
python-version: "3.8.0"
333+
cache: "poetry"
334+
- run: echo '${{ steps.cp310.outputs.cache-hit }}' # true if cache-hit occured on the primary key
335+
```
321336
322337
## Evironment variables
323338
324339
These environment variables become available after setup-python action execution:
325340
326-
| Env.Variable | Description |
341+
| **Env.variable** | **Description** |
327342
| ----------- | ----------- |
328343
| pythonLocation |Contains the absolute path to the folder where the requested version of Python or PyPy is installed|
329344
| Python_ROOT_DIR | https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython |
@@ -333,10 +348,10 @@ These environment variables become available after setup-python action execution
333348
## Using `update-environment` flag
334349
335350
The `update-environment` flag defaults to `true`.
336-
With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for `python` to just work out of the box.
351+
With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for Python/PyPy to just work out of the box.
337352
338353
If `update-environment` is set to `false`, the action will not add/update environment variables.
339-
This can prove useful if you want the only side-effect to be to ensure python is installed and rely on the `python-path` output to run python.
354+
This can prove useful if you want the only side-effect to be to ensure Python/PyPy is installed and rely on the `python-path` output to run executable.
340355
Such a requirement on side-effect could be because you don't want your composite action messing with your user's workflows.
341356
342357
```yaml
@@ -382,7 +397,7 @@ Such a requirement on side-effect could be because you don't want your composite
382397

383398
# Hosted tool cache
384399

385-
GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tool cache and there is where you will find Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy in this tool cache and adding it to PATH.
400+
GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of the tool cache with Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy from this tool cache and adding it to PATH.
386401

387402
|| Location |
388403
|------|-------|

0 commit comments

Comments
 (0)