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

Fix a bug where pip-compile would ignore some of versions if prefer binary distributions #1119

Merged
merged 4 commits into from
May 21, 2020

Conversation

atugushev
Copy link
Member

@atugushev atugushev commented Apr 25, 2020

Fixes #1118.

Relevant lines of code:

candidates_by_version = lookup_table(
all_candidates, key=lambda c: c.version, unique=True
)

The parameter unique=True was the root of the issue and the cause of losing installation candidates. See examples of lookup_table() results below.

Before

candidates_by_version = {
    ...
    <Version('0.2.2')>: <InstallationCandidate('entrypoints', <Version('0.2.2')>, <Link https://files.pythonhosted.org/packages/f8/ad/0e77a853c745a15981ab51fa9a0cb4eca7a7a007b4c1970106ee6ba01e0c/entrypoints-0.2.2-py2.py3-none-any.whl#sha256=0a0685962ee5ac303f470acbb659f0f97aef5b9deb6b85d059691c706ef6e45e (from https://pypi.org/simple/entrypoints/) (requires-python:>=2.7)>)>,
    <Version('0.2.3')>: <InstallationCandidate('entrypoints', <Version('0.2.3')>, <Link https://files.pythonhosted.org/packages/27/e8/607697e6ab8a961fc0b141a97ea4ce72cd9c9e264adeb0669f6d194aa626/entrypoints-0.2.3.tar.gz#sha256=d2d587dde06f99545fb13a383d2cd336a8ff1f359c5839ce3a64c917d10c029f (from https://pypi.org/simple/entrypoints/) (requires-python:>=2.7)>)>,
    <Version('0.3')>: <InstallationCandidate('entrypoints', <Version('0.3')>, <Link https://files.pythonhosted.org/packages/b4/ef/063484f1f9ba3081e920ec9972c96664e2edb9fdc3d8669b0e3b8fc0ad7c/entrypoints-0.3.tar.gz#sha256=c70dd71abe5a8c85e55e12c19bd91ccfeec11a6e99044204511f9ed547d48451 (from https://pypi.org/simple/entrypoints/) (requires-python:>=2.7)>)>
}

Note entrypoints-0.3.tar.gz in <Version('0.3')> .

After

candidates_by_version = {
    <Version('0.2.2')>: {
        <InstallationCandidate('entrypoints', <Version('0.2.2')>, <Link https://files.pythonhosted.org/packages/f8/ad/0e77a853c745a15981ab51fa9a0cb4eca7a7a007b4c1970106ee6ba01e0c/entrypoints-0.2.2-py2.py3-none-any.whl#sha256=0a0685962ee5ac303f470acbb659f0f97aef5b9deb6b85d059691c706ef6e45e (from https://pypi.org/simple/entrypoints/) (requires-python:>=2.7)>)>
    },

    <Version('0.2.3')>: {
        <InstallationCandidate('entrypoints', <Version('0.2.3')>, <Link https://files.pythonhosted.org/packages/cc/8b/4eefa9b47f1910b3d2081da67726b066e379b04ca897acfe9f92bac56147/entrypoints-0.2.3-py2.py3-none-any.whl#sha256=10ad569bb245e7e2ba425285b9fa3e8178a0dc92fc53b1e1c553805e15a8825b (from https://pypi.org/simple/entrypoints/) (requires-python:>=2.7)>)>,
        <InstallationCandidate('entrypoints', <Version('0.2.3')>, <Link https://files.pythonhosted.org/packages/27/e8/607697e6ab8a961fc0b141a97ea4ce72cd9c9e264adeb0669f6d194aa626/entrypoints-0.2.3.tar.gz#sha256=d2d587dde06f99545fb13a383d2cd336a8ff1f359c5839ce3a64c917d10c029f (from https://pypi.org/simple/entrypoints/) (requires-python:>=2.7)>)>
    },

    <Version('0.3')>: {
        <InstallationCandidate('entrypoints', <Version('0.3')>, <Link https://files.pythonhosted.org/packages/b4/ef/063484f1f9ba3081e920ec9972c96664e2edb9fdc3d8669b0e3b8fc0ad7c/entrypoints-0.3.tar.gz#sha256=c70dd71abe5a8c85e55e12c19bd91ccfeec11a6e99044204511f9ed547d48451 (from https://pypi.org/simple/entrypoints/) (requires-python:>=2.7)>)>,
        <InstallationCandidate('entrypoints', <Version('0.3')>, <Link https://files.pythonhosted.org/packages/ac/c6/44694103f8c221443ee6b0041f69e2740d89a25641e62fb4f2ee568f2f9c/entrypoints-0.3-py2.py3-none-any.whl#sha256=589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19 (from https://pypi.org/simple/entrypoints/) (requires-python:>=2.7)>)>
    }
}

Changelog-friendly one-liner: Fix a bug where pip-compile would ignore some of package versions when PIP_PREFER_BINARY is on.

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).

@atugushev atugushev added bug fix resolver Related to dependency resolver labels Apr 25, 2020
matching_versions = ireq.specifier.filter(
(candidate.version for candidate in all_candidates), prereleases=prereleases
)

# Reuses pip's internal candidate sort key to sort
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: This comment is no longer relevant after the latest 5.0.0 refactoring.

@codecov
Copy link

codecov bot commented Apr 25, 2020

Codecov Report

Merging #1119 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1119      +/-   ##
==========================================
+ Coverage   99.47%   99.48%   +0.01%     
==========================================
  Files          37       36       -1     
  Lines        2680     2736      +56     
  Branches      322      324       +2     
==========================================
+ Hits         2666     2722      +56     
  Misses          8        8              
  Partials        6        6              
Impacted Files Coverage Δ
piptools/repositories/pypi.py 95.41% <100.00%> (ø)
tests/conftest.py 100.00% <100.00%> (ø)
tests/test_cli_compile.py 100.00% <100.00%> (ø)
tests/test_data/packages/fake_with_deps/setup.py

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 32deaf3...4095169. Read the comment docs.

@atugushev atugushev changed the title Fix a bug where pip-compile would ignore some of versions Fix a bug where pip-compile would ignore some of versions if prefer binary distributions Apr 25, 2020
@atugushev atugushev force-pushed the fix-matching-candidates-1118 branch from c712fd1 to 6ba4b7f Compare April 25, 2020 19:27
@atugushev atugushev marked this pull request as ready for review April 25, 2020 20:11
Copy link
Contributor

@AndydeCleyre AndydeCleyre left a comment

Choose a reason for hiding this comment

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

Very nice!

Can you just change all the new docstring instances of "by" to "from"? And maybe the "is exist" to "existing"?

@atugushev
Copy link
Member Author

Thanks, @AndydeCleyre!

@atugushev atugushev added this to the 5.2.0 milestone May 21, 2020
@atugushev atugushev merged commit 5dd163a into jazzband:master May 21, 2020
@atugushev atugushev deleted the fix-matching-candidates-1118 branch May 21, 2020 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolver Related to dependency resolver
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not getting correct package version under "prefer binary" mode
2 participants