Skip to content

Commit

Permalink
Merge branch 'pip-tools-integration'
Browse files Browse the repository at this point in the history
* pip-tools-integration:
  CHANGELOG: Remove "Ignore pkg-resources (jazzband#437)" entry
  Update ChangeLog for the last merge
  Do not allow conflicting pinned versions
  Update release date for 1.10.1.
  Fixed bug breaking pip-sync on Python 3, raising TypeError
  Added release date for 1.10.0.
  • Loading branch information
suutari committed Sep 28, 2017
2 parents 22f29fb + 5340e63 commit 8c17da6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
16 changes: 5 additions & 11 deletions prequ/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@
from .logging import log
from .utils import (
UNSAFE_PACKAGES, first, format_requirement, format_specifier, full_groupby,
get_pinned_version, is_pinned_requirement, is_vcs_link, key_from_req)
get_pinned_version, is_pinned_requirement, is_vcs_link, key_from_ireq,
key_from_req)

green = partial(click.style, fg='green')
magenta = partial(click.style, fg='magenta')


def _dep_key(ireq):
if ireq.req is None and ireq.link is not None:
return str(ireq.link)
else:
return key_from_req(ireq.req)


class RequirementSummary(object):
"""
Summary of a requirement's properties for comparison purposes.
Expand Down Expand Up @@ -97,7 +91,7 @@ def resolve(self, max_rounds=10):
self.their_constraints))

log.debug('Limiting constraints:')
for constraint in sorted(self.limiters, key=_dep_key):
for constraint in sorted(self.limiters, key=key_from_ireq):
log.debug(' {}'.format(constraint))

# Ignore existing packages
Expand Down Expand Up @@ -153,7 +147,7 @@ def _group_constraints(self, constraints):
flask~=0.7
"""
for _, ireqs in full_groupby(constraints, key=_dep_key):
for _, ireqs in full_groupby(constraints, key=key_from_ireq):
ireqs = list(ireqs)
exception_ireq = first(
x for x in ireqs if x.editable or is_vcs_link(x))
Expand Down Expand Up @@ -189,7 +183,7 @@ def _resolve_one_round(self): # noqa: C901 (too complex)
configuration.
"""
# Sort this list for readability of terminal output
constraints = sorted(self.constraints, key=_dep_key)
constraints = sorted(self.constraints, key=key_from_ireq)
unsafe_constraints = []
original_constraints = copy.copy(constraints)
if not self.allow_unsafe:
Expand Down
2 changes: 1 addition & 1 deletion prequ/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .exceptions import IncompatibleRequirements, UnsupportedConstraint
from .utils import (
flat_map, format_requirement, is_pinned_requirement, is_vcs_link,
key_from_req)
key_from_ireq, key_from_req)

PACKAGES_TO_IGNORE = [
'pip',
Expand Down
8 changes: 8 additions & 0 deletions prequ/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def assert_compatible_pip_version():
'perhaps run `pip install --upgrade pip`?').format(pip.__version__))


def key_from_ireq(ireq):
"""Get a standardized key for an InstallRequirement."""
if ireq.req is None and ireq.link is not None:
return str(ireq.link)
else:
return key_from_req(ireq.req)


def key_from_req(req):
"""Get an all-lowercase version of the requirement's name."""
if hasattr(req, 'key'):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ def test_diff_with_editable(fake_dist, from_editable):
assert str(package.link) == _get_file_url(path_to_package)


@pytest.mark.parametrize(
'lines',
[
['django==1.8'],
['django==1.8', 'click==4.0'],
]
)
def test_sync_install(from_line, lines):
with mock.patch('prequ.sync.check_call') as check_call:
to_install = {from_line(line) for line in lines}

sync(to_install, set())
check_call.assert_called_once_with(['pip', 'install', '-q'] + sorted(lines))


def test_sync_with_editable(from_editable):
with mock.patch('prequ.sync.check_call') as check_call:
path_to_package = os.path.join(os.path.dirname(__file__), 'fake_pypi', 'small_fake_package')
Expand Down

0 comments on commit 8c17da6

Please sign in to comment.