Skip to content

Commit

Permalink
Move PIP_VERSION to pip_compat module
Browse files Browse the repository at this point in the history
To DRY
  • Loading branch information
atugushev committed Sep 17, 2019
1 parent 4e7404f commit 1d0c6b5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions piptools/_compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .pip_compat import (
DEV_PKGS,
FAVORITE_HASH,
PIP_VERSION,
FormatControl,
InstallationCandidate,
InstallCommand,
Expand Down
4 changes: 3 additions & 1 deletion piptools/_compat/pip_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pip
from pip._vendor.packaging.version import parse as parse_version

PIP_VERSION = tuple(map(int, parse_version(pip.__version__).base_version.split(".")))


def do_import(module_path, subimport=None, old_path=None):
old_path = old_path or module_path
Expand Down Expand Up @@ -53,7 +55,7 @@ def do_import(module_path, subimport=None, old_path=None):
Resolver = do_import("legacy_resolve", "Resolver", old_path="resolve")

# pip 18.1 has refactored InstallRequirement constructors use by pip-tools.
if parse_version(pip.__version__) < parse_version("18.1"):
if PIP_VERSION < (18, 1):
install_req_from_line = InstallRequirement.from_line
install_req_from_editable = InstallRequirement.from_editable
else:
Expand Down
3 changes: 2 additions & 1 deletion piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from ..exceptions import NoCandidateFound
from ..logging import log
from ..utils import (
PIP_VERSION,
create_install_command,
fs_str,
is_pinned_requirement,
Expand All @@ -37,6 +36,8 @@
)
from .base import BaseRepository

from piptools._compat.pip_compat import PIP_VERSION

try:
from pip._internal.req.req_tracker import RequirementTracker
except ImportError:
Expand Down
5 changes: 1 addition & 4 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
from collections import OrderedDict
from itertools import chain, groupby

import pip
import six
from click.utils import LazyFile
from pip._vendor.packaging.version import parse as parse_version
from six.moves import shlex_quote

from ._compat import InstallCommand, install_req_from_line
from ._compat import PIP_VERSION, InstallCommand, install_req_from_line
from .click import style

PIP_VERSION = tuple(map(int, parse_version(pip.__version__).base_version.split(".")))
UNSAFE_PACKAGES = {"setuptools", "distribute", "pip"}
COMPILE_EXCLUDE_OPTIONS = {
"--dry-run",
Expand Down
3 changes: 1 addition & 2 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

from .utils import invoke

from piptools._compat.pip_compat import path_to_url
from piptools._compat.pip_compat import PIP_VERSION, path_to_url
from piptools.repositories import PyPIRepository
from piptools.scripts.compile import cli
from piptools.utils import PIP_VERSION

TEST_DATA_PATH = os.path.join(os.path.split(__file__)[0], "test_data")
MINIMAL_WHEELS_PATH = os.path.join(TEST_DATA_PATH, "minimal_wheels")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from mock import MagicMock, patch

from piptools._compat import PackageFinder, install_req_from_line
from piptools.utils import PIP_VERSION
from piptools._compat.pip_compat import PIP_VERSION


def test_pypirepo_build_dir_is_str(pypi_repository):
Expand Down

0 comments on commit 1d0c6b5

Please sign in to comment.