-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poetry cache does not work well with dependency groups #505
Comments
hi @fredrikaverpil thank you for the report, we will take a look. |
@panticmilos I see this got labeled as |
Hi @fredrikaverpil, First of all, sorry for the delayed response, and thank you for your patience 🙏 We have discussed your issue with our team and this is the conclusion. I don’t think we can utilize cache-dependency-path here since all of the dependencies groups are in the same file at the end. If there was some poetry command which would tell you which dependency group is installed, then it would make sense to implement such a thing. Otherwise, we would need one more input for it, which would make the solution the same as for actions/cache with an expanded primary key with a dependency group, and therefore we don’t see the need to implement such a thing, since we want to keep cache input as minimal as possible for setup actions. I will close this issue now, but we can continue the conversation. Also, feel free to reopen it any time |
@panticmilos I think this makes a lot of sense 👍 How about adding a note about this in your docs though? For others who may stumble across this thread; a custom action supporting caching of poetry dependency groups: # action.yml
name: poetry-install-with-caching
description: Poetry install with support for caching of dependency groups.
inputs:
python-version:
description: Python version, supporting MAJOR.MINOR only
required: true
poetry-version:
description: Poetry version
required: true
install-command:
description: Command run for installing dependencies
required: false
default: poetry install
cache-key:
description: Cache key to use for manual handling of caching
required: true
working-directory:
description: Directory to run install-command in
required: false
default: ""
runs:
using: composite
steps:
- uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- uses: actions/cache@v3
id: cache-pip
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "15"
with:
path: |
~/.cache/pip
key: pip-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}
- run: pipx install poetry==${{ inputs.poetry-version }} --python python${{ inputs.python-version }}
shell: bash
- uses: actions/cache@v3
id: cache-poetry
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "15"
with:
path: |
~/.cache/pypoetry/virtualenvs
~/.cache/pypoetry/cache
~/.cache/pypoetry/artifacts
key: poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles('poetry.lock') }}
- run: ${{ inputs.install-command }}
working-directory: ${{ inputs.working-directory }}
shell: bash |
# Add action to test with all dependencies installed PR adds a custom action for setting up poetry that allows specifying a cache key: actions/setup-python#505 (comment) This makes it possible to run 2 types of unit tests: (1) unit tests with only core dependencies (2) unit tests with extended dependencies (e.g., those that rely on an optional pdf parsing library) As part of this PR, we're moving some pdf parsing tests into the unit-tests section and making sure that these unit tests get executed when running with extended dependencies.
# Add action to test with all dependencies installed PR adds a custom action for setting up poetry that allows specifying a cache key: actions/setup-python#505 (comment) This makes it possible to run 2 types of unit tests: (1) unit tests with only core dependencies (2) unit tests with extended dependencies (e.g., those that rely on an optional pdf parsing library) As part of this PR, we're moving some pdf parsing tests into the unit-tests section and making sure that these unit tests get executed when running with extended dependencies.
# Add action to test with all dependencies installed PR adds a custom action for setting up poetry that allows specifying a cache key: actions/setup-python#505 (comment) This makes it possible to run 2 types of unit tests: (1) unit tests with only core dependencies (2) unit tests with extended dependencies (e.g., those that rely on an optional pdf parsing library) As part of this PR, we're moving some pdf parsing tests into the unit-tests section and making sure that these unit tests get executed when running with extended dependencies.
These are actually wasting time triggering uninstalls from the cached venv. ``` Installing dependencies from lock file Package operations: 1 install, 0 updates, 4 removals • Removing iniconfig (2.0.0) • Removing loguru (0.7.2) • Removing pluggy (1.4.0) • Removing pytest (8.0.0) • Installing coverage (7.4.1) Installing the current project: logot (0.4.0) ``` See actions/setup-python#582, actions/setup-python#505
Caching pre-commit halves the linting time and the `action/setup-python` cache does not handle `--extras` [properly ](actions/setup-python#505) so switching to action/cache for the poetry cache
Description:
When Poetry 1.2 dependency groups are defined in
pyproject.toml
andactions/setup-python@v4
caching is enabled withcache: "poetry"
, the caching does not work very well.Let's say you have a few dependency groups which you install in your CI with different kind of commands:
poetry install --only main
poetry install --only docs
poetry install --only linting
poetry install --only main,testing
poetry install --only main,testing,typing
Defined like this (semi-real world example) in
pyproject.toml
:Let's say you then use the following for all these CI jobs:
Whichever cache is written first will be used for all these CI jobs. Let's say the
docs
dependency group finishes first and will be written as the cache.The end result seems to be here that all the other dependency groups will only get the docs deps cached. And in this example they are not needed for any of the other dependency groups. So for example, the
typing
CI job will always have to install all its dependencies even if a cache exists.Now, I'm wondering if I can somehow utilize the
cache-dependency-path
option to e.g. set this for each CI job so to produce one cache per dependency group. Or is this use case simply not supported today?It's possible that this won't be supported and if so, I think the docs should include a recommendation on e.g. not using the built-in caching and instead rely on something like this:
Action version:
Specify the action version
Platform:
Runner type:
Tools version:
Repro steps:
actions/setup-python@v4
and specifycache: 'poetry'
.Expected behavior:
I'd expect to be able to append e.g. the dependency group name to the cache key.
Actual behavior:
I believe I can only add filepaths to the cache option of
cache-dependency-path
to control the cache key.The text was updated successfully, but these errors were encountered: