Skip to content
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

Add --cache-dir option to pip-compile #1022

Merged

Conversation

richafrank
Copy link
Contributor

@richafrank richafrank commented Dec 24, 2019

Ensure tests pass without dependencies cached from previous tests.

Running tests individually, I was seeing intermittent failures depending on whether the cache was populated or not, specifically test_stdin and test_filter_pip_markers. Also I refactored a test to use an existing fixture.

Changelog-friendly one-liner: Add --cache-dir option to pip-compile.

Contributor checklist
  • Provided the tests for the changes.
  • Gave a clear one-line description in the PR (that the maintainers can add to CHANGELOG.md on release).
  • Assign the PR to an existing or new milestone for the target version (following Semantic Versioning).

@codecov
Copy link

codecov bot commented Dec 24, 2019

Codecov Report

Merging #1022 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1022      +/-   ##
==========================================
- Coverage   99.11%   99.11%   -0.01%     
==========================================
  Files          34       34              
  Lines        2364     2360       -4     
  Branches      303      302       -1     
==========================================
- Hits         2343     2339       -4     
  Misses         11       11              
  Partials       10       10
Impacted Files Coverage Δ
piptools/resolver.py 100% <ø> (ø) ⬆️
piptools/utils.py 100% <ø> (ø) ⬆️
piptools/cache.py 100% <100%> (ø) ⬆️
piptools/scripts/compile.py 100% <100%> (ø) ⬆️
tests/test_cli_compile.py 100% <100%> (ø) ⬆️
piptools/repositories/pypi.py 92.92% <100%> (ø) ⬆️
tests/test_top_level_editable.py 100% <100%> (ø) ⬆️
tests/test_utils.py 100% <100%> (ø) ⬆️
tests/conftest.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0da08e5...9ce14df. Read the comment docs.

@atugushev atugushev added refactor Refactoring code tests Testing and related things labels Dec 25, 2019
Copy link
Member

@atugushev atugushev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @richafrank,

Thanks for bringing this up! I like the intention. Is there a way to isolate the DependencyCache.cache_dir explicitly for each test, rather than clear the cache? The workaround with clearing works, but if we want to run tests in parallel someday the isolation would help. The cache directory could be configured via an environment variable (e.g. PIP_TOOLS_CACHE_DIR). Also, this could be useful for #395. Please, let me know what you think.

@richafrank
Copy link
Contributor Author

Thanks @atugushev . I can definitely make it more explicit!

Since this is manifesting in the cli tests, my recommendation would be to add a --cache-dir cli arg to pip-compile that falls back to an env var, as you suggested, followed by the current CACHE_DIR, and then change the parameter to Resolver from a cache instance to the cache dir to pass through. The only consumers of the cache parameter right now are the tests, which only configure the cache_dir anyway. For isolation in the tests then, we could have the runner fixture provide a CliRunner that uses a tmpdir for --cache-dir.

Adding a cli arg in addition to the env var would mean more transparency and give more flexibility, allowing tests to run in parallel in the same process even. But that's more to change, so curious your thoughts.

@richafrank
Copy link
Contributor Author

(I updated this branch with my suggestion from above, if that sounds good.)

@richafrank
Copy link
Contributor Author

richafrank commented Dec 26, 2019

Unfortunately, as long as we have a default cache directory, one could easily add a test that relies on it unintentionally. That would be a good reason to add back the autouse clear_cache fixture as well.

Copy link
Member

@atugushev atugushev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on it! I'd prefer to use an auto-used fixture wich sets the PIP_TOOLS_CACHE_DIR to a temporary directory globally. This should decrease the patch size, see the details below.

piptools/scripts/compile.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/test_cli_compile.py Outdated Show resolved Hide resolved
tests/test_cli_compile.py Outdated Show resolved Hide resolved
@richafrank
Copy link
Contributor Author

Thanks @atugushev . Sounds like I went a bit too explicit! Your suggestions look good to me.

Copy link
Member

@atugushev atugushev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for accepting my suggestions. Left a few minor comments below:

tests/test_cli_compile.py Outdated Show resolved Hide resolved
tests/test_cli_compile.py Outdated Show resolved Hide resolved
tests/test_cli_compile.py Outdated Show resolved Hide resolved
Adds a --cache-dir arg to the compile cli and uses it for test isolation
via monkeypatching of consumed env var
@richafrank
Copy link
Contributor Author

👍 on the cleanup

Copy link
Member

@atugushev atugushev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked deeply at the PR and found that cache dir is also using in PyPIRepository class. See the details below.

piptools/scripts/compile.py Outdated Show resolved Hide resolved
piptools/scripts/compile.py Outdated Show resolved Hide resolved
piptools/scripts/compile.py Show resolved Hide resolved
Copy link
Member

@atugushev atugushev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 👏👏👏

@atugushev atugushev added the enhancement Improvements to functionality label Dec 29, 2019
@atugushev atugushev added this to the 4.4.0 milestone Dec 29, 2019
@atugushev atugushev changed the title Isolate tests from dependency cache Add --cache-dir option to pip-compile Dec 29, 2019
@atugushev atugushev merged commit 6709244 into jazzband:master Jan 5, 2020
@atugushev
Copy link
Member

@richafrank thanks for the contribution!

@richafrank
Copy link
Contributor Author

Thanks @atugushev !

@richafrank richafrank deleted the isolate-dependency-cache-tests branch January 6, 2020 02:42
@atugushev
Copy link
Member

pip-tools v4.4.0 is released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to functionality refactor Refactoring code tests Testing and related things
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants