From 18c67b44e436377f4d5cbce2263fcda1d59510b2 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Wed, 24 Nov 2021 14:50:35 +0000 Subject: [PATCH] Initial preparation to add support for poetry --- .github/workflows/e2e-cache.yml | 20 ++++++++++++++++++++ README.md | 25 ++++++++++++++++++++----- action.yml | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-cache.yml b/.github/workflows/e2e-cache.yml index 63bdc47..c6b4462 100644 --- a/.github/workflows/e2e-cache.yml +++ b/.github/workflows/e2e-cache.yml @@ -52,6 +52,26 @@ jobs: - name: Install dependencies 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: name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}) runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 0926910..dfb7dc3 100644 --- a/README.md +++ b/README.md @@ -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. - 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. -- optionally caching dependencies for pip and pipenv. +- optionally caching dependencies for pip, pipenv and poetry. - registering problem matchers for error output. # 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. - Support for pre-release versions of Python. - 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 @@ -209,18 +209,19 @@ pypy-3.7-nightly # Python 3.7 and nightly PyPy # 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 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. 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 steps: @@ -245,6 +246,20 @@ steps: - 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** ```yaml steps: diff --git a/action.yml b/action.yml index 8e6871e..bd9ee68 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: description: "Version range or exact version of a Python version to use, using SemVer's version range syntax." default: '3.x' 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 architecture: description: 'The target architecture (x86, x64) of the Python interpreter.'