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

Include already-installed matching requirements in the to_install set, so that pip-sync reliably installs dependencies #907

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions piptools/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def diff(
"""
requirements_lut = {diff_key_from_ireq(r): r for r in compiled_requirements}

satisfied = set() # holds keys
to_install = set() # holds InstallRequirement objects
to_uninstall = set() # holds keys

Expand All @@ -159,11 +158,9 @@ def diff(
key = key_from_req(dist)
if key not in requirements_lut or not requirements_lut[key].match_markers():
to_uninstall.add(key)
elif requirements_lut[key].specifier.contains(dist.version):
satisfied.add(key)

for key, requirement in requirements_lut.items():
if key not in satisfied and requirement.match_markers():
if requirement.match_markers():
to_install.add(requirement)

# Make sure to not uninstall any packages that should be ignored
Expand Down
12 changes: 6 additions & 6 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_diff_should_do_nothing():
reqs = [] # no requirements

to_install, to_uninstall = diff(reqs, installed)
assert to_install == set()
assert to_install == set(reqs)
assert to_uninstall == set()


Expand All @@ -136,7 +136,7 @@ def test_diff_should_uninstall(fake_dist):
reqs = []

to_install, to_uninstall = diff(reqs, installed)
assert to_install == set()
assert to_install == set(reqs)
assert to_uninstall == {"django"} # no version spec when uninstalling


Expand Down Expand Up @@ -200,7 +200,7 @@ def test_diff_leave_packaging_packages_alone(fake_dist, from_line):
reqs = [from_line("django==1.7")]

to_install, to_uninstall = diff(reqs, installed)
assert to_install == set()
assert to_install == set(reqs)
assert to_uninstall == {"first"}


Expand All @@ -221,7 +221,7 @@ def test_diff_leave_piptools_alone(fake_dist, from_line):
reqs = [from_line("django==1.7")]

to_install, to_uninstall = diff(reqs, installed)
assert to_install == set()
assert to_install == set(reqs)
assert to_uninstall == {"foobar"}


Expand All @@ -242,12 +242,12 @@ def test_diff_with_editable(fake_dist, from_editable):


def test_diff_with_matching_url_versions(fake_dist, from_line):
# if URL version is explicitly provided, use it to avoid reinstalling
# if URL version is explicitly provided, pip itself will avoid reinstalling
installed = [fake_dist("example==1.0")]
reqs = [from_line("file:///example.zip#egg=example==1.0")]

to_install, to_uninstall = diff(reqs, installed)
assert to_install == set()
assert to_install == set(reqs)
assert to_uninstall == set()


Expand Down