Skip to content

Commit

Permalink
Remove now obsolete pip version check due to vendoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vphilippon committed Mar 22, 2018
1 parent c54c9f9 commit 17644c2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 45 deletions.
5 changes: 1 addition & 4 deletions piptools/repositories/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from piptools.utils import as_tuple, key_from_req, make_install_requirement
from .base import BaseRepository
try:
from pip.utils.hashes import FAVORITE_HASH
except ImportError:
FAVORITE_HASH = 'sha256'
from pip.utils.hashes import FAVORITE_HASH


def ireq_satisfied_by_existing_pin(ireq, existing_pin):
Expand Down
13 changes: 3 additions & 10 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
from pip.index import PackageFinder
from pip.req.req_set import RequirementSet
from pip.wheel import Wheel
try:
from pip.utils.hashes import FAVORITE_HASH
except ImportError:
FAVORITE_HASH = 'sha256'
from pip.utils.hashes import FAVORITE_HASH

from .._compat import TemporaryDirectory
from ..cache import CACHE_DIR
from ..exceptions import NoCandidateFound
from ..utils import (fs_str, is_pinned_requirement, lookup_table,
make_install_requirement, pip_version_info)
make_install_requirement)
from .base import BaseRepository


Expand Down Expand Up @@ -87,11 +84,7 @@ def clear_caches(self):

def find_all_candidates(self, req_name):
if req_name not in self._available_candidates_cache:
# pip 8 changed the internal API, making this a public method
if pip_version_info >= (8, 0):
candidates = self.finder.find_all_candidates(req_name)
else:
candidates = self.finder._find_all_versions(req_name)
candidates = self.finder.find_all_candidates(req_name)
self._available_candidates_cache[req_name] = candidates
return self._available_candidates_cache[req_name]

Expand Down
6 changes: 1 addition & 5 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
from ..logging import log
from ..repositories import LocalRequirementsRepository, PyPIRepository
from ..resolver import Resolver
from ..utils import (assert_compatible_pip_version, dedup, is_pinned_requirement,
key_from_req, UNSAFE_PACKAGES)
from ..utils import (dedup, is_pinned_requirement, key_from_req, UNSAFE_PACKAGES)
from ..writer import OutputWriter

# Make sure we're using a compatible version of pip
assert_compatible_pip_version()

DEFAULT_REQUIREMENTS_FILE = 'requirements.in'


Expand Down
5 changes: 1 addition & 4 deletions piptools/scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
from .. import click, sync
from ..exceptions import PipToolsError
from ..logging import log
from ..utils import assert_compatible_pip_version, flat_map

# Make sure we're using a compatible version of pip
assert_compatible_pip_version()
from ..utils import flat_map

DEFAULT_REQUIREMENTS_FILE = 'requirements.txt'

Expand Down
26 changes: 4 additions & 22 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,16 @@
from itertools import chain, groupby
from collections import OrderedDict

import pip
from pip.req import InstallRequirement

from first import first

from .click import style


def safeint(s):
try:
return int(s)
except ValueError:
return 0


pip_version_info = tuple(safeint(digit) for digit in pip.__version__.split('.'))

UNSAFE_PACKAGES = {'setuptools', 'distribute', 'pip'}


def assert_compatible_pip_version():
# Make sure we're using a reasonably modern version of pip
if not pip_version_info >= (8, 0):
print('pip-compile requires at least version 8.0 of pip ({} found), '
'perhaps run `pip install --upgrade pip`?'.format(pip.__version__))
sys.exit(4)


def key_from_ireq(ireq):
"""Get a standardized key for an InstallRequirement."""
if ireq.req is None and ireq.link is not None:
Expand All @@ -45,10 +27,10 @@ def key_from_ireq(ireq):
def key_from_req(req):
"""Get an all-lowercase version of the requirement's name."""
if hasattr(req, 'key'):
# pip 8.1.1 or below, using pkg_resources
# from pkg_resources, such as installed dists for pip-sync
key = req.key
else:
# pip 8.1.2 or above, using packaging
# from packaging, such as install requirements from requirements.txt
key = req.name

key = key.replace('_', '-').lower()
Expand Down Expand Up @@ -221,10 +203,10 @@ def dedup(iterable):
def name_from_req(req):
"""Get the name of the requirement"""
if hasattr(req, 'project_name'):
# pip 8.1.1 or below, using pkg_resources
# from pkg_resources, such as installed dists for pip-sync
return req.project_name
else:
# pip 8.1.2 or above, using packaging
# from packaging, such as install requirements from requirements.txt
return req.name


Expand Down

0 comments on commit 17644c2

Please sign in to comment.