From d22686dc50cf8731887b04474ff4b1f0e92a85dc Mon Sep 17 00:00:00 2001 From: Michiel Holtkamp Date: Mon, 30 Mar 2020 15:07:07 +0200 Subject: [PATCH] FIX: Pip 20+ support and fix tests Apparently, the tests did not run since the testenv did not match, so the builds were green no matter the code. I changed the tox.ini and added py38-pip20 and made sure it failed before fixing the imports in pkgversion.py. On another note, we should probably not use internals like this because it will randomly break (like now). Fixing it now so we are unblocked at least. --- Makefile | 2 +- pkgversion/pkgversion.py | 10 ++++++--- tox.ini | 48 ++++++++++++++-------------------------- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 21fdc7b..7ff54e9 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ clean: pyclean docsclean @rm -rf venv venv: - @python3.6 -m venv venv + @python3.8 -m venv venv @$(PIP) install -U "pip>=7.0" -q @$(PIP) install -r $(DEPS) diff --git a/pkgversion/pkgversion.py b/pkgversion/pkgversion.py index e781977..eb7fb41 100755 --- a/pkgversion/pkgversion.py +++ b/pkgversion/pkgversion.py @@ -5,9 +5,13 @@ from subprocess import PIPE, Popen try: - from pip._internal.download import PipSession - from pip._internal.req import parse_requirements -except ImportError: + try: # pip20+ + from pip._internal.network.session import PipSession + from pip._internal.req import parse_requirements + except: # pip10+ + from pip._internal.download import PipSession + from pip._internal.req import parse_requirements +except ImportError: # pip<10 # Output expected ImportErrors for PIP < 10. from pip.download import PipSession from pip.req import parse_requirements diff --git a/tox.ini b/tox.ini index 56ed732..f5605c2 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ envlist = py27-{pip9,pip10} py35-{pip9,pip10} py36-{pip9,pip10} + py38-pip20 cov isort-check isort-fix @@ -14,68 +15,53 @@ envlist = skipsdist = true +[testenv] basepython = - py27-{pip9,pip10}: python2.7 - py35-{pip9,pip10}: python3.5 - py36-{pip9,pip10}: python3.6 - cov: python3.6 + py27: python2.7 + py35: python3.5 + py36: python3.6 + py38: python3.8 + cov: python3.8 deps = -rrequirements/requirements-base.txt -rrequirements/requirements-testing.txt + pip9: pip<10.0 + pip10: pip<11.0 + pip20: pip<21.0 +commands = + py.test tests [testenv:cov] -basepython= python3.6 +basepython= python3.8 commands = py.test tests --cov-report=term-missing --cov-append --cov=pkgversion --cov-report xml {posargs} deps = -rrequirements/requirements-base.txt -rrequirements/requirements-testing.txt -[general] -commands = - py.test tests -deps = - -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 ## [testenv:lint] -basepython = python3.6 +basepython = python3.8 commands = flake8 pkgversion tests --exclude=pkgversion/__init__.py deps = flake8 [testenv:docs] -basepython = python3.6 +basepython = python3.8 commands = sphinx-build -W -b html {toxinidir}/docs {toxinidir}/docs/_build/html deps = -rrequirements/requirements-testing.txt [testenv:isort-check] -basepython = python3.6 +basepython = python3.8 commands = isort -rc -c pkgversion tests deps = isort [testenv:isort-fix] -basepython = python3.6 +basepython = python3.8 commands = isort -rc pkgversion tests deps = isort