Skip to content

Commit

Permalink
Add pip>=20.3 support (#1216)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Kluger <andykluger@gmail.com>
  • Loading branch information
atugushev and AndydeCleyre committed Nov 20, 2020
1 parent 05c9ec0 commit 55ceda5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
20 changes: 10 additions & 10 deletions .appveyor.yml
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
- 3.7
pip-version:
- "latest"
- "20.1"
- "previous"
include:
- os: Ubuntu
python-version: 3.9-dev
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -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.* |
+---------------+-----------------+
28 changes: 21 additions & 7 deletions piptools/repositories/pypi.py
Expand Up @@ -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)

Expand All @@ -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()

Expand All @@ -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:
Expand Down Expand Up @@ -153,16 +160,18 @@ 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,
session=self.session,
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):
Expand All @@ -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)

Expand Down Expand Up @@ -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():
Expand Down
9 changes: 8 additions & 1 deletion 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
Expand All @@ -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 =
Expand Down

0 comments on commit 55ceda5

Please sign in to comment.