Initial preparation to add support for poetry

This commit is contained in:
Patrick Arminio 2021-11-24 14:50:35 +00:00
parent 6c048c7558
commit 18c67b44e4
No known key found for this signature in database
GPG Key ID: 0B13AD30354F6EBE
3 changed files with 41 additions and 6 deletions

View File

@ -52,6 +52,26 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: pipenv install numpy run: pipenv install numpy
python-poetry-dependencies-caching:
name: Test poetry (Python ${{ matrix.python-version}}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', 'pypy-3.7-v7.3.5', 'pypy-3.7-v7.x']
steps:
- uses: actions/checkout@v2
- name: Install poetry
run: pipx install poetry
- name: Setup Python
uses: ./
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: poetry add flake8
python-pip-dependencies-caching-path: python-pip-dependencies-caching-path:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}) name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}

View File

@ -9,7 +9,7 @@ This action sets up a Python environment for use in actions by:
- optionally installing and adding to PATH a version of Python that is already installed in the tools cache. - optionally installing and adding to PATH a version of Python that is already installed in the tools cache.
- downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the tools cache. - downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the tools cache.
- failing if a specific version of Python is not preinstalled or available for download. - failing if a specific version of Python is not preinstalled or available for download.
- optionally caching dependencies for pip and pipenv. - optionally caching dependencies for pip, pipenv and poetry.
- registering problem matchers for error output. - registering problem matchers for error output.
# What's new # What's new
@ -19,7 +19,7 @@ This action sets up a Python environment for use in actions by:
- Automatic setup and download of Python packages if using a self-hosted runner. - Automatic setup and download of Python packages if using a self-hosted runner.
- 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 and pipenv dependencies - Support for built-in caching of pip, pipenv and poetry dependencies
# Usage # Usage
@ -209,18 +209,19 @@ pypy-3.7-nightly # Python 3.7 and nightly PyPy
# Caching packages dependencies # Caching packages dependencies
The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip` and `pipenv`. The `cache` input is optional, and caching is turned off by default. The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip`, `pipenv` and `poetry`. The `cache` input is optional, and caching is turned off by default.
The action defaults to searching for a dependency file (`requirements.txt` for pip or `Pipfile.lock` for pipenv) in the repository, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases where multiple dependency files are used, they are located in different subdirectories or different files for the hash want to be used. The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases where multiple dependency files are used, they are located in different subdirectories or different files for the hash want to be used.
- For pip, the action will cache global cache directory - For pip, the action will cache global cache directory
- For pipenv, the action will cache virtualenv directory - For pipenv, the action will cache virtualenv directory
- For poetry, the action will cache virtualenv directory
**Please Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available that can lead to an increase in total build time. **Please Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available that can lead to an increase in total build time.
The requirements file format allows to specify dependency versions using logical operators (for example chardet>=3.0.4) or specify dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary. The requirements file format allows to specify dependency versions using logical operators (for example chardet>=3.0.4) or specify dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary.
**Caching pip dependencies:** **Caching pip dependencies:**
```yaml ```yaml
steps: steps:
@ -245,6 +246,20 @@ steps:
- run: pipenv install - run: pipenv install
``` ```
**Caching poetry dependencies:**
```yaml
steps:
- uses: actions/checkout@v2
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v2
with:
python-version: '3.9'
cache: 'poetry'
- run: poetry install
- run: poetry run pytest
```
**Using wildcard patterns to cache dependencies** **Using wildcard patterns to cache dependencies**
```yaml ```yaml
steps: steps:

View File

@ -7,7 +7,7 @@ inputs:
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 a Python version to use, using SemVer's version range syntax."
default: '3.x' default: '3.x'
cache: cache:
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv.' description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.'
required: false required: false
architecture: architecture:
description: 'The target architecture (x86, x64) of the Python interpreter.' description: 'The target architecture (x86, x64) of the Python interpreter.'