Skip to content

Commit

Permalink
Merge branch 'noneditable_vcs' of github.com:venmo/pip-tools
Browse files Browse the repository at this point in the history
* 'noneditable_vcs' of github.com:venmo/pip-tools:
  extract vcs detection to is_vcs_link
  appease flake8
  support pinned vcs dependencies [jazzband#355]
  • Loading branch information
suutari-ai committed Feb 8, 2017
2 parents 77a2daf + 3ba9176 commit 51ed27a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
5 changes: 3 additions & 2 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from ..cache import CACHE_DIR
from ..exceptions import NoCandidateFound
from ..utils import (is_pinned_requirement, lookup_table,
make_install_requirement, pip_version_info)
make_install_requirement, pip_version_info,
is_vcs_link)
from .base import BaseRepository

try:
Expand Down Expand Up @@ -94,7 +95,7 @@ def find_best_match(self, ireq, prereleases=None):
Returns a Version object that indicates the best match for the given
InstallRequirement according to the external repository.
"""
if ireq.editable:
if ireq.editable or is_vcs_link(ireq):
return ireq # return itself as the best match

all_candidates = self.find_all_candidates(ireq.name)
Expand Down
16 changes: 8 additions & 8 deletions piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .exceptions import UnsupportedConstraint
from .logging import log
from .utils import (format_requirement, format_specifier, full_groupby,
is_pinned_requirement, key_from_req)
is_pinned_requirement, key_from_req, is_vcs_link)

green = partial(click.style, fg='green')
magenta = partial(click.style, fg='magenta')
Expand Down Expand Up @@ -125,9 +125,9 @@ def resolve(self, max_rounds=10):

def _check_constraints(self):
for constraint in chain(self.our_constraints, self.their_constraints):
if constraint.link is not None and not constraint.editable:
msg = ('pip-compile does not support URLs as packages, unless they are editable. '
'Perhaps add -e option?')
if ((is_vcs_link(constraint) and not constraint.editable and
not is_pinned_requirement(constraint))):
msg = 'pip-compile does not support non-editable vcs URLs that are not pinned to one version.'
raise UnsupportedConstraint(msg, constraint)

def _group_constraints(self, constraints):
Expand All @@ -148,9 +148,9 @@ def _group_constraints(self, constraints):
"""
for _, ireqs in full_groupby(constraints, key=_dep_key):
ireqs = list(ireqs)
editable_ireq = first(ireqs, key=lambda ireq: ireq.editable)
if editable_ireq:
yield editable_ireq # ignore all the other specs: the editable one is the one that counts
exception_ireq = first(ireqs, key=lambda ireq: ireq.editable or is_vcs_link(ireq))
if exception_ireq:
yield exception_ireq # ignore all the other specs: the editable/vcs one is the one that counts
continue

ireqs = iter(ireqs)
Expand Down Expand Up @@ -227,7 +227,7 @@ def get_best_match(self, ireq):
Flask==0.10.1 => Flask==0.10.1
"""
if ireq.editable:
if ireq.editable or is_vcs_link(ireq):
# NOTE: it's much quicker to immediately return instead of
# hitting the index server
best_match = ireq
Expand Down
9 changes: 4 additions & 5 deletions piptools/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from . import click
from .exceptions import IncompatibleRequirements, UnsupportedConstraint
from .utils import flat_map, key_from_req
from .utils import flat_map, key_from_req, is_pinned_requirement, is_vcs_link

PACKAGES_TO_IGNORE = [
'pip',
Expand Down Expand Up @@ -69,9 +69,8 @@ def merge(requirements, ignore_conflicts):
by_key = {}

for ireq in requirements:
if ireq.link is not None and not ireq.editable:
msg = ('pip-compile does not support URLs as packages, unless they are editable. '
'Perhaps add -e option?')
if ((is_vcs_link(ireq) and not ireq.editable and not is_pinned_requirement(ireq))):
msg = 'pip-compile does not support non-editable vcs URLs that are not pinned to one version.'
raise UnsupportedConstraint(msg, ireq)

key = ireq.link or key_from_req(ireq.req)
Expand All @@ -95,7 +94,7 @@ def diff(compiled_requirements, installed_dists):
Calculate which packages should be installed or uninstalled, given a set
of compiled requirements and a list of currently installed modules.
"""
requirements_lut = {r.link or key_from_req(r.req): r for r in compiled_requirements}
requirements_lut = {r.link if r.editable else key_from_req(r.req): r for r in compiled_requirements}

satisfied = set() # holds keys
to_install = set() # holds keys-and-versions
Expand Down
12 changes: 10 additions & 2 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def format_requirement(ireq, include_specifier=True):
Generic formatter for pretty printing InstallRequirements to the terminal
in a less verbose way than using its `__str__` method.
"""
if ireq.editable:
line = '-e {}'.format(ireq.link)
if ireq.editable or is_vcs_link(ireq):
line = '{}{}'.format('-e ' if ireq.editable else '', ireq.link)
elif include_specifier:
line = str(ireq.req)
else:
Expand Down Expand Up @@ -117,6 +117,14 @@ def is_pinned_requirement(ireq):
return (op == '==' or op == '===') and not version.endswith('.*')


def is_vcs_link(ireq):
"""
Returns whether an InstallRequirement is a version control link.
"""

return ireq.link is not None and not ireq.link.is_artifact


def as_tuple(ireq):
"""
Pulls out the (name: str, version:str, extras:(str)) tuple from the pinned InstallRequirement.
Expand Down

0 comments on commit 51ed27a

Please sign in to comment.