From 5029fcc4298def004a3d286aa3adfc312acb4efd Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Wed, 23 Jan 2019 00:50:04 +0300 Subject: [PATCH] Support of pip 19.0 --- .appveyor.yml | 10 ++++++++++ .travis.yml | 1 + piptools/_compat/pip_compat.py | 1 + piptools/repositories/pypi.py | 24 ++++++++++++++++-------- tests/test_cli.py | 8 ++++---- tox.ini | 3 +++ 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1672ebe7a..13f7f5c53 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -11,6 +11,8 @@ environment: PIP: 10.0.1 - TOXENV: py27-pip18.0 PIP: 18.0 + - TOXENV: py27-pip19.0 + PIP: 19.0 - TOXENV: py27-pipmaster PIP: master - TOXENV: py27-piplatest @@ -25,6 +27,8 @@ environment: PIP: 10.0.1 - TOXENV: py34-pip18.0 PIP: 18.0 + - TOXENV: py34-pip19.0 + PIP: 19.0 - TOXENV: py34-pipmaster PIP: master - TOXENV: py34-piplatest @@ -39,6 +43,8 @@ environment: PIP: 10.0.1 - TOXENV: py35-pip18.0 PIP: 18.0 + - TOXENV: py35-pip19.0 + PIP: 19.0 - TOXENV: py35-pipmaster PIP: master - TOXENV: py35-piplatest @@ -53,6 +59,8 @@ environment: PIP: 10.0.1 - TOXENV: py36-pip18.0 PIP: 18.0 + - TOXENV: py36-pip19.0 + PIP: 19.0 - TOXENV: py36-pipmaster PIP: master - TOXENV: py36-piplatest @@ -67,6 +75,8 @@ environment: PIP: 10.0.1 - TOXENV: py37-pip18.0 PIP: 18.0 + - TOXENV: py37-pip19.0 + PIP: 19.0 - TOXENV: py37-pipmaster PIP: master - TOXENV: py37-piplatest diff --git a/.travis.yml b/.travis.yml index 91fb3920e..5571f6e78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ env: - PIP=9.0.3 - PIP=10.0.1 - PIP=18.0 + - PIP=19.0 - PIP=latest - PIP=master diff --git a/piptools/_compat/pip_compat.py b/piptools/_compat/pip_compat.py index 28da51f03..187c6ea12 100644 --- a/piptools/_compat/pip_compat.py +++ b/piptools/_compat/pip_compat.py @@ -27,6 +27,7 @@ def do_import(module_path, subimport=None, old_path=None): user_cache_dir = do_import('utils.appdirs', 'user_cache_dir') FAVORITE_HASH = do_import('utils.hashes', 'FAVORITE_HASH') is_file_url = do_import('download', 'is_file_url') +path_to_url = do_import('download', 'path_to_url') url_to_path = do_import('download', 'url_to_path') PackageFinder = do_import('index', 'PackageFinder') FormatControl = do_import('index', 'FormatControl') diff --git a/piptools/repositories/pypi.py b/piptools/repositories/pypi.py index bf698039c..7a2bd85fa 100644 --- a/piptools/repositories/pypi.py +++ b/piptools/repositories/pypi.py @@ -7,6 +7,9 @@ from contextlib import contextmanager from shutil import rmtree +import pip +import pkg_resources + from .._compat import ( is_file_url, url_to_path, @@ -54,14 +57,19 @@ def __init__(self, pip_options, session): if pip_options.no_index: index_urls = [] - self.finder = PackageFinder( - find_links=pip_options.find_links, - index_urls=index_urls, - trusted_hosts=pip_options.trusted_hosts, - allow_all_prereleases=pip_options.pre, - process_dependency_links=pip_options.process_dependency_links, - session=self.session, - ) + finder_kwargs = { + "find_links": pip_options.find_links, + "index_urls": index_urls, + "trusted_hosts": pip_options.trusted_hosts, + "allow_all_prereleases": pip_options.pre, + "session": self.session, + } + + # pip 19.0 has removed process_dependency_links from the PackageFinder constructor + if pkg_resources.parse_version(pip.__version__) < pkg_resources.parse_version('19.0'): + finder_kwargs["process_dependency_links"] = pip_options.process_dependency_links + + self.finder = PackageFinder(**finder_kwargs) # Caches # stores project_name => InstallationCandidate mappings for all diff --git a/tests/test_cli.py b/tests/test_cli.py index ca8c18f52..6319a9327 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,5 @@ import os from textwrap import dedent -from six.moves.urllib.request import pathname2url import subprocess import sys import mock @@ -9,6 +8,7 @@ import pytest +from piptools._compat.pip_compat import path_to_url from piptools.repositories import PyPIRepository from piptools.scripts.compile import cli from piptools.scripts.sync import cli as sync_cli @@ -242,7 +242,7 @@ def test_sync_quiet(tmpdir): def test_editable_package(tmpdir): """ piptools can compile an editable """ fake_package_dir = os.path.join(os.path.split(__file__)[0], 'test_data', 'small_fake_package') - fake_package_dir = 'file:' + pathname2url(fake_package_dir) + fake_package_dir = path_to_url(fake_package_dir) runner = CliRunner() with runner.isolated_filesystem(): with open('requirements.in', 'w') as req_in: @@ -278,7 +278,7 @@ def test_locally_available_editable_package_is_not_archived_in_cache_dir(tmpdir) cache_dir = tmpdir.mkdir('cache_dir') fake_package_dir = os.path.join(os.path.split(__file__)[0], 'test_data', 'small_fake_package') - fake_package_dir = 'file:' + pathname2url(fake_package_dir) + fake_package_dir = path_to_url(fake_package_dir) with mock.patch('piptools.repositories.pypi.CACHE_DIR', new=str(cache_dir)): runner = CliRunner() @@ -360,7 +360,7 @@ def test_upgrade_packages_version_option(tmpdir): def test_generate_hashes_with_editable(): small_fake_package_dir = os.path.join( os.path.split(__file__)[0], 'test_data', 'small_fake_package') - small_fake_package_url = 'file:' + pathname2url(small_fake_package_dir) + small_fake_package_url = path_to_url(small_fake_package_dir) runner = CliRunner() with runner.isolated_filesystem(): with open('requirements.in', 'w') as fp: diff --git a/tox.ini b/tox.ini index c41a2bc5b..8138d21de 100644 --- a/tox.ini +++ b/tox.ini @@ -14,6 +14,7 @@ deps = pip9.0.3: pip==9.0.3 pip10.0.1: pip==10.0.1 pip18.0: pip==18.0 + pip19.0: pip==19.0 coverage mock pytest @@ -25,6 +26,7 @@ setenv = pip9.0.3: PIP=9.0.3 pip10.0.1: PIP=10.0.1 pip18.0: PIP=18.0 + pip19.0: PIP==19.0 install_command= python -m pip install {opts} {packages} commands = pip --version @@ -48,5 +50,6 @@ PIP = 9.0.3: pip9.0.3 10.0.1: pip10.0.1 18.0: pip18.0 + 19.0: pip19.0 latest: piplatest master: pipmaster