Skip to content

Commit

Permalink
Improve cache Poetry install instructions
Browse files Browse the repository at this point in the history
See #150.
  • Loading branch information
sebastian-correa committed Jul 20, 2024
1 parent 9849dc5 commit 0a8dade
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,51 @@ jobs:

The directory to cache will depend on the operating system of the runner.

Note that when the cache hits and the *Install Poetry* step is skipped, all configurations done during install are skipped. Therefore, the loaded Poetry will run with default settings.

This may break the cache of Python dependencies when the `.lock` file changes and the Poetry *install* is recovered from an old cache. For example, if you set

```yaml
with:
virtualenvs-in-project: true
```

and have a cache step for `.venv`, the `install-poetry` will run and configure Poetry to create the venv in `.venv` *the first time it is run*. Dependencies will install and will be cached. However, when you update your `.lock` file, the Poetry installation will be recovered from cache, and a new venv will be created in the default Poetry location (not `.venv`, because the install poetry step doesn't cache the settings), so the cache venv step will fail (as there's no `.venv` directory to cache).

To remedy this, you should use this instead

```yaml
name: test
on: pull_request
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS
key: poetry-0 # increment to reset cache
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Configure poetry
if: steps.cached-poetry.outputs.cache-hit == 'true'
run: poetry config virtualenvs.in-project true
```

## Contributing

Contributions are always welcome; submit a PR!
Expand Down

0 comments on commit 0a8dade

Please sign in to comment.