From 48ad28ec26f5783faddde4ffbd8881cd75e3a853 Mon Sep 17 00:00:00 2001 From: "Bailly, Maurice" Date: Fri, 13 Mar 2020 12:47:00 +0100 Subject: [PATCH] FIX: Pip 20 support for importing PipSession --- pkgversion/pkgversion.py | 13 +++++++++---- tests/test_pkgversion.py | 2 +- tox.ini | 32 +++++--------------------------- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/pkgversion/pkgversion.py b/pkgversion/pkgversion.py index e781977..34dd2ef 100755 --- a/pkgversion/pkgversion.py +++ b/pkgversion/pkgversion.py @@ -5,12 +5,17 @@ from subprocess import PIPE, Popen try: - from pip._internal.download import PipSession + from pip._internal.network.session import PipSession from pip._internal.req import parse_requirements except ImportError: - # Output expected ImportErrors for PIP < 10. - from pip.download import PipSession - from pip.req import parse_requirements + # Output expected ImportErrors for PIP < 20. + try: + from pip._internal.download import PipSession + from pip._internal.req import parse_requirements + except ImportError: + # Output expected ImportErrors for PIP < 10. + from pip.download import PipSession + from pip.req import parse_requirements setup_py_template = """ diff --git a/tests/test_pkgversion.py b/tests/test_pkgversion.py index 43bc940..f35713a 100644 --- a/tests/test_pkgversion.py +++ b/tests/test_pkgversion.py @@ -97,7 +97,7 @@ def test_write_setup_py_with_git_repo(self, tmpdir): Popen(command, stdout=PIPE, cwd=str(tmpdir)).communicate() expected_import = "^from setuptools import setup$" - expected_setup = "^setup\(\*\*(.*)\)$" + expected_setup = "^setup\(\*\*(.*)\)$" # noqa: W605 write_setup_py( install_requires=['test'] diff --git a/tox.ini b/tox.ini index 56ed732..e671bff 100644 --- a/tox.ini +++ b/tox.ini @@ -3,9 +3,7 @@ addopts=--tb=short [tox] envlist = - py27-{pip9,pip10} - py35-{pip9,pip10} - py36-{pip9,pip10} + py{27,35,36}-pip{9,10,20} cov isort-check isort-fix @@ -14,15 +12,6 @@ envlist = skipsdist = true -basepython = - py27-{pip9,pip10}: python2.7 - py35-{pip9,pip10}: python3.5 - py36-{pip9,pip10}: python3.6 - cov: python3.6 -deps = - -rrequirements/requirements-base.txt - -rrequirements/requirements-testing.txt - [testenv:cov] basepython= python3.6 commands = @@ -31,27 +20,16 @@ deps = -rrequirements/requirements-base.txt -rrequirements/requirements-testing.txt -[general] +[testenv] commands = py.test tests deps = + pip9: pip>=9,<10 + pip10: pip>=10,<20 + pip20: pip>=20 -rrequirements/requirements-base.txt -rrequirements/requirements-testing.txt -[testenv:py27-{pip9,pip10}] -basepython = python2.7 -commands = - {[general]commands} - -[testenv:py35-{pip9,pip10}] -basepython = python3.5 -commands = - {[general]commands} - -[testenv:py36-{pip9,pip10}] -basepython = python3.6 -commands = - {[general]commands} ## # Flake8 linting