From 55ceda567c3255c4844ff5468ceaf9137a597cf0 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Sat, 21 Nov 2020 00:46:27 +0700 Subject: [PATCH] Add pip>=20.3 support (#1216) Co-authored-by: Andy Kluger --- .appveyor.yml | 20 ++++++++++---------- .github/workflows/ci.yml | 2 +- README.rst | 2 +- piptools/repositories/pypi.py | 28 +++++++++++++++++++++------- tox.ini | 9 ++++++++- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 220bcea89..be0a13fda 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -3,28 +3,28 @@ environment: PYTHON: "C:\\Python36" matrix: - - TOXENV: py27-pip20.1-coverage - PIP: 20.1 + - TOXENV: py27-pipprevious-coverage + PIP: previous - TOXENV: py27-piplatest-coverage PIP: latest - - TOXENV: py35-pip20.1 - PIP: 20.1 + - TOXENV: py35-pipprevious + PIP: previous - TOXENV: py35-piplatest PIP: latest - - TOXENV: py36-pip20.1 - PIP: 20.1 + - TOXENV: py36-pipprevious + PIP: previous - TOXENV: py36-piplatest PIP: latest - - TOXENV: py37-pip20.1 - PIP: 20.1 + - TOXENV: py37-pipprevious + PIP: previous - TOXENV: py37-piplatest PIP: latest - - TOXENV: py38-pip20.1-coverage - PIP: 20.1 + - TOXENV: py38-pipprevious-coverage + PIP: previous - TOXENV: py38-piplatest-coverage PIP: latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 702da07b2..e7bf5ad4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - 3.7 pip-version: - "latest" - - "20.1" + - "previous" include: - os: Ubuntu python-version: 3.9-dev diff --git a/README.rst b/README.rst index fbd160242..66481cd5f 100644 --- a/README.rst +++ b/README.rst @@ -464,5 +464,5 @@ versions. +---------------+-----------------+ | 5.0.0 - 5.3.0 | 20.0 - 20.1.1 | +---------------+-----------------+ -| >= 5.4.0 | 20.1 - 20.2.* | +| >= 5.4.0 | 20.1 - 20.3.* | +---------------+-----------------+ diff --git a/piptools/repositories/pypi.py b/piptools/repositories/pypi.py index 261ffcd3f..e1c4e913c 100644 --- a/piptools/repositories/pypi.py +++ b/piptools/repositories/pypi.py @@ -58,7 +58,12 @@ def __init__(self, pip_args, cache_dir): # General options (find_links, index_url, extra_index_url, trusted_host, # and pre) are deferred to pip. self.command = create_command("install") - self.options, _ = self.command.parse_args(pip_args) + extra_pip_args = ( + [] + if PIP_VERSION[:2] <= (20, 2) + else ["--use-deprecated", "legacy-resolver"] + ) + self.options, _ = self.command.parse_args(pip_args + extra_pip_args) if self.options.cache_dir: self.options.cache_dir = normalize_path(self.options.cache_dir) @@ -85,7 +90,8 @@ def __init__(self, pip_args, cache_dir): self.freshen_build_caches() self._cache_dir = normalize_path(cache_dir) self._download_dir = fs_str(os.path.join(self._cache_dir, "pkgs")) - self._wheel_download_dir = fs_str(os.path.join(self._cache_dir, "wheels")) + if PIP_VERSION[:2] <= (20, 2): + self._wheel_download_dir = fs_str(os.path.join(self._cache_dir, "wheels")) self._setup_logging() @@ -107,7 +113,8 @@ def source_dir(self): def clear_caches(self): rmtree(self._download_dir, ignore_errors=True) - rmtree(self._wheel_download_dir, ignore_errors=True) + if PIP_VERSION[:2] <= (20, 2): + rmtree(self._wheel_download_dir, ignore_errors=True) def find_all_candidates(self, req_name): if req_name not in self._available_candidates_cache: @@ -153,7 +160,7 @@ def resolve_reqs(self, download_dir, ireq, wheel_cache): with get_requirement_tracker() as req_tracker, TempDirectory( kind="resolver" ) as temp_dir, indent_log(): - preparer = self.command.make_requirement_preparer( + preparer_kwargs = dict( temp_build_dir=temp_dir, options=self.options, req_tracker=req_tracker, @@ -161,8 +168,10 @@ def resolve_reqs(self, download_dir, ireq, wheel_cache): finder=self.finder, use_user_site=False, download_dir=download_dir, - wheel_download_dir=self._wheel_download_dir, ) + if PIP_VERSION[:2] <= (20, 2): + preparer_kwargs["wheel_download_dir"] = self._wheel_download_dir + preparer = self.command.make_requirement_preparer(**preparer_kwargs) reqset = RequirementSet() if PIP_VERSION[:2] <= (20, 1): @@ -186,7 +195,10 @@ def resolve_reqs(self, download_dir, ireq, wheel_cache): if not ireq.prepared: # If still not prepared, e.g. a constraint, do enough to assign # the ireq a name: - resolver._get_abstract_dist_for(ireq) + if PIP_VERSION[:2] <= (20, 2): + resolver._get_abstract_dist_for(ireq) + else: + resolver._get_dist_for(ireq) return set(results) @@ -219,7 +231,9 @@ def get_dependencies(self, ireq): download_dir = self._get_download_path(ireq) if not os.path.isdir(download_dir): os.makedirs(download_dir) - if not os.path.isdir(self._wheel_download_dir): + if PIP_VERSION[:2] <= (20, 2) and not os.path.isdir( + self._wheel_download_dir + ): os.makedirs(self._wheel_download_dir) with global_tempdir_manager(): diff --git a/tox.ini b/tox.ini index f8b19a095..a333e84da 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = # NOTE: keep this in sync with the env list in .github/workflows/ci.yml. - py{27,35,36,37,38,39,py,py3}-pip{20.1,20.2,latest,master}-coverage + py{27,35,36,37,38,39,py,py3}-pip{20.1,20.2,20.3,previous,latest,master}-coverage checkqa readme skip_missing_interpreters = True @@ -11,14 +11,21 @@ extras = testing coverage: coverage deps = + pipprevious: pip==20.2.* + # TODO: change to `pip` after pip-20.3 being released + piplatest: -e git+https://github.com/pypa/pip.git@master#egg=pip pipmaster: -e git+https://github.com/pypa/pip.git@master#egg=pip pip20.1: pip==20.1.* pip20.2: pip==20.2.* + # TODO: change to `pip==20.3.*` after pip-20.3 being released + pip20.3: -e git+https://github.com/pypa/pip.git@master#egg=pip setenv = + pipprevious: PIP=previous piplatest: PIP=latest pipmaster: PIP=master pip20.1: PIP==20.1 pip20.2: PIP==20.2 + pip20.3: PIP==20.3 coverage: PYTEST_ADDOPTS=--strict --doctest-modules --cov --cov-report=term-missing --cov-report=xml {env:PYTEST_ADDOPTS:} commands_pre =