diff options
author | Bernát Gábor <bgabor8@bloomberg.net> | 2020-10-04 18:17:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-04 18:17:24 +0100 |
commit | 06dba77aa1e798c20c1d001734ba3442f85f15da (patch) | |
tree | 30342ac7fb6882b83e502655a7011e1b23f6d009 | |
parent | adcf327ee507498a613dc6f235c24c8f2576b6c6 (diff) | |
download | virtualenv-06dba77aa1e798c20c1d001734ba3442f85f15da.tar.gz |
Restore python3.4 support (add it back to CI) (#1965)
-rw-r--r-- | .coveragerc | 4 | ||||
-rw-r--r-- | .github/workflows/check.yml | 3 | ||||
-rw-r--r-- | docs/changelog/1962.bugfix.rst | 2 | ||||
-rw-r--r-- | docs/changelog/1963.bugfix.rst | 1 | ||||
-rw-r--r-- | setup.cfg | 2 | ||||
-rw-r--r-- | src/virtualenv/seed/embed/via_app_data/via_app_data.py | 4 | ||||
-rw-r--r-- | src/virtualenv/seed/wheels/acquire.py | 4 | ||||
-rw-r--r-- | src/virtualenv/util/path/_pathlib/__init__.py | 24 | ||||
-rw-r--r-- | tasks/__main__zipapp.py | 2 | ||||
-rw-r--r-- | tests/integration/test_run_int.py | 7 | ||||
-rw-r--r-- | tests/unit/create/test_creator.py | 2 | ||||
-rw-r--r-- | tests/unit/seed/embed/test_boostrap_link_via_app_data.py | 1 | ||||
-rw-r--r-- | tests/unit/seed/embed/test_pip_invoke.py | 2 | ||||
-rw-r--r-- | tests/unit/seed/wheels/test_acquire.py | 3 | ||||
-rw-r--r-- | tests/unit/seed/wheels/test_periodic_update.py | 3 | ||||
-rw-r--r-- | tox.ini | 8 |
16 files changed, 46 insertions, 26 deletions
diff --git a/.coveragerc b/.coveragerc index 2b79b26..2d64afd 100644 --- a/.coveragerc +++ b/.coveragerc @@ -25,9 +25,5 @@ source = [coverage:run] branch = false parallel = true -dynamic_context = test_function source = ${_COVERAGE_SRC} - -[coverage:html] -show_contexts = true diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index fb1c605..ab12a42 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -33,7 +33,8 @@ jobs: - 2.7 - pypy2 include: - - { os: MacOs, py: brew@py3 } + - { os: macos, py: brew@py3 } + - { os: ubuntu, py: 3.4.10 } steps: - name: Install OS dependencies run: | diff --git a/docs/changelog/1962.bugfix.rst b/docs/changelog/1962.bugfix.rst index 8dd3eba..1832ccb 100644 --- a/docs/changelog/1962.bugfix.rst +++ b/docs/changelog/1962.bugfix.rst @@ -1 +1 @@ -Fix Nonetype error in cygwin if POSIX path in dest - by :user:`danyeaw`. +Fix ``None`` type error in cygwin if POSIX path in dest - by :user:`danyeaw`. diff --git a/docs/changelog/1963.bugfix.rst b/docs/changelog/1963.bugfix.rst new file mode 100644 index 0000000..27027cf --- /dev/null +++ b/docs/changelog/1963.bugfix.rst @@ -0,0 +1 @@ +Fix Python 3.4 incompatibilities (added back to the CI) - by :user:`gaborbernat`. @@ -88,7 +88,7 @@ docs = sphinx-rtd-theme>=0.4.3 towncrier>=19.9.0rc1 testing = - coverage>=5 + coverage>=4 coverage_enable_subprocess>=1 flaky>=3 pytest>=4 diff --git a/src/virtualenv/seed/embed/via_app_data/via_app_data.py b/src/virtualenv/seed/embed/via_app_data/via_app_data.py index e595128..1c60719 100644 --- a/src/virtualenv/seed/embed/via_app_data/via_app_data.py +++ b/src/virtualenv/seed/embed/via_app_data/via_app_data.py @@ -8,8 +8,6 @@ from contextlib import contextmanager from subprocess import CalledProcessError from threading import Lock, Thread -import six - from virtualenv.info import fs_supports_symlink from virtualenv.seed.embed.base_embed import BaseEmbed from virtualenv.seed.wheels import get_wheel @@ -104,7 +102,7 @@ class FromAppData(BaseEmbed): if version is not None: msg += " version {}".format(version) msg += ", pip download exit code {}".format(failure.returncode) - output = failure.output if six.PY2 else (failure.output + failure.stderr) + output = failure.output if sys.version_info < (3, 5) else (failure.output + failure.stderr) if output: msg += "\n" msg += output diff --git a/src/virtualenv/seed/wheels/acquire.py b/src/virtualenv/seed/wheels/acquire.py index 823d348..e63ecb6 100644 --- a/src/virtualenv/seed/wheels/acquire.py +++ b/src/virtualenv/seed/wheels/acquire.py @@ -6,8 +6,6 @@ import os import sys from operator import eq, lt -import six - from virtualenv.util.path import Path from virtualenv.util.six import ensure_str from virtualenv.util.subprocess import Popen, subprocess @@ -62,7 +60,7 @@ def download_wheel(distribution, version_spec, for_py_version, search_dirs, app_ out, err = process.communicate() if process.returncode != 0: kwargs = {"output": out} - if six.PY2: + if sys.version_info < (3, 5): kwargs["output"] += err else: kwargs["stderr"] = err diff --git a/src/virtualenv/util/path/_pathlib/__init__.py b/src/virtualenv/util/path/_pathlib/__init__.py index 29a8c6b..6bb045c 100644 --- a/src/virtualenv/util/path/_pathlib/__init__.py +++ b/src/virtualenv/util/path/_pathlib/__init__.py @@ -19,6 +19,13 @@ if six.PY3: with self.open(mode="r", encoding=encoding, errors=errors) as f: return f.read() + def read_bytes(self): + """ + Open the file in bytes mode, read it, and close the file. + """ + with self.open(mode="rb") as f: + return f.read() + def write_text(self, data, encoding=None, errors=None): """ Open the file in text mode, write to it, and close the file. @@ -28,10 +35,21 @@ if six.PY3: with self.open(mode="w", encoding=encoding, errors=errors) as f: return f.write(data) + def write_bytes(self, data): + """ + Open the file in bytes mode, write to it, and close the file. + """ + # type-check for the buffer interface before truncating the file + view = memoryview(data) + with self.open(mode="wb") as f: + return f.write(view) + def mkdir(self, mode=0o777, parents=False, exist_ok=False): - if exist_ok and self.exists(): - return - super(type(BuiltinPath()), self).mkdir(mode, parents) + try: + super(type(BuiltinPath()), self).mkdir(mode, parents) + except FileExistsError as exception: + if not exist_ok: + raise exception else: diff --git a/tasks/__main__zipapp.py b/tasks/__main__zipapp.py index 26825cd..abf90c7 100644 --- a/tasks/__main__zipapp.py +++ b/tasks/__main__zipapp.py @@ -4,7 +4,7 @@ import sys import zipfile ABS_HERE = os.path.abspath(os.path.dirname(__file__)) -NEW_IMPORT_SYSTEM = sys.version_info[0:2] > (3, 4) +NEW_IMPORT_SYSTEM = sys.version_info[0] == 3 class VersionPlatformSelect(object): diff --git a/tests/integration/test_run_int.py b/tests/integration/test_run_int.py index bf818ba..26a6583 100644 --- a/tests/integration/test_run_int.py +++ b/tests/integration/test_run_int.py @@ -1,19 +1,22 @@ from __future__ import absolute_import, unicode_literals +import sys + from virtualenv import cli_run from virtualenv.util.six import ensure_text from virtualenv.util.subprocess import run_cmd def test_app_data_pinning(tmp_path): - result = cli_run([ensure_text(str(tmp_path)), "--pip", "19.3.1", "--activators", "", "--seeder", "app-data"]) + version = "19.1.1" if sys.version_info[0:2] == (3, 4) else "19.3.1" + result = cli_run([ensure_text(str(tmp_path)), "--pip", version, "--activators", "", "--seeder", "app-data"]) code, out, err = run_cmd([str(result.creator.script("pip")), "list", "--disable-pip-version-check"]) assert not code assert not err for line in out.splitlines(): parts = line.split() if parts and parts[0] == "pip": - assert parts[1] == "19.3.1" + assert parts[1] == version break else: assert not out diff --git a/tests/unit/create/test_creator.py b/tests/unit/create/test_creator.py index 97ab88c..747d793 100644 --- a/tests/unit/create/test_creator.py +++ b/tests/unit/create/test_creator.py @@ -127,6 +127,8 @@ _VENV_BUG_ON = ( ids=lambda i: "-".join(i) if isinstance(i, tuple) else i, ) def test_create_no_seed(python, creator, isolated, system, coverage_env, special_name_dir): + if creator[0] == "venv" and sys.version_info[0:2] == (3, 4): # venv on python3.4 only supports ascii chars + special_name_dir = special_name_dir.with_name(special_name_dir.name.encode("ascii", errors="ignore").decode()) dest = special_name_dir creator_key, method = creator cmd = [ diff --git a/tests/unit/seed/embed/test_boostrap_link_via_app_data.py b/tests/unit/seed/embed/test_boostrap_link_via_app_data.py index 934e007..d98f8dd 100644 --- a/tests/unit/seed/embed/test_boostrap_link_via_app_data.py +++ b/tests/unit/seed/embed/test_boostrap_link_via_app_data.py @@ -22,6 +22,7 @@ def test_seed_link_via_app_data(tmp_path, coverage_env, current_fastest, copies) bundle_ver = BUNDLE_SUPPORT[current.version_release_str] create_cmd = [ ensure_text(str(tmp_path / "en v")), # space in the name to ensure generated scripts work when path has space + "--no-periodic-update", "--seeder", "app-data", "--extra-search-dir", diff --git a/tests/unit/seed/embed/test_pip_invoke.py b/tests/unit/seed/embed/test_pip_invoke.py index 4c478df..c033aa1 100644 --- a/tests/unit/seed/embed/test_pip_invoke.py +++ b/tests/unit/seed/embed/test_pip_invoke.py @@ -41,7 +41,7 @@ def test_base_bootstrap_via_pip_invoke(tmp_path, coverage_env, mocker, current_f expected_list = list( itertools.chain.from_iterable(["--find-links", str(e)] for e in sorted(expected, key=lambda x: str(x))), ) - found = cmd[-len(expected_list) :] + found = cmd[-len(expected_list) :] if expected_list else [] assert "--no-index" not in cmd cmd.append("--no-index") assert found == expected_list diff --git a/tests/unit/seed/wheels/test_acquire.py b/tests/unit/seed/wheels/test_acquire.py index 7918c60..5e2e9b6 100644 --- a/tests/unit/seed/wheels/test_acquire.py +++ b/tests/unit/seed/wheels/test_acquire.py @@ -5,7 +5,6 @@ from subprocess import CalledProcessError import pytest -from virtualenv.info import PY2 from virtualenv.seed.wheels.acquire import download_wheel, pip_wheel_env_run from virtualenv.seed.wheels.embed import BUNDLE_FOLDER, get_embed_wheel from virtualenv.seed.wheels.util import discover_wheels @@ -44,7 +43,7 @@ def test_download_fails(mocker, for_py_version, session_app_data): with pytest.raises(CalledProcessError) as context: download_wheel("pip", "==1", for_py_version, [], session_app_data, as_path), exc = context.value - if PY2: + if sys.version_info < (3, 5): assert exc.output == "outerr" else: assert exc.output == "out" diff --git a/tests/unit/seed/wheels/test_periodic_update.py b/tests/unit/seed/wheels/test_periodic_update.py index 96f2429..1172981 100644 --- a/tests/unit/seed/wheels/test_periodic_update.py +++ b/tests/unit/seed/wheels/test_periodic_update.py @@ -53,8 +53,9 @@ def test_manual_upgrade(session_app_data, caplog, mocker, for_py_version): assert "upgrade pip" in caplog.text assert "upgraded pip" in caplog.text - assert " new entries found:\n\tNewVersion" in caplog.text assert " no new versions found" in caplog.text + assert " new entries found:\n" in caplog.text + assert "\tNewVersion(" in caplog.text packages = defaultdict(list) for i in do_update_mock.call_args_list: packages[i[1]["distribution"]].append(i[1]["for_py_version"]) @@ -14,7 +14,7 @@ envlist = docs isolated_build = true skip_missing_interpreters = true -minversion = 3.14.0 +minversion = 3.14 [testenv] description = run tests with {basepython} @@ -33,7 +33,7 @@ setenv = PYTHONIOENCODING = utf-8 _COVERAGE_SRC = {envsitepackagesdir}/virtualenv {py34,py27,pypy, upgrade}: PYTHONWARNINGS = ignore:DEPRECATION::pip._internal.cli.base_command - {pypy,py27}: PYTEST_XDIST = 0 + {py34,pypy,py27}: PYTEST_XDIST = 0 extras = testing commands = @@ -44,7 +44,9 @@ commands = python -m coverage combine python -m coverage report --skip-covered --show-missing python -m coverage xml -o {toxworkdir}/coverage.{envname}.xml - python -m coverage html -d {envtmpdir}/htmlcov + python -m coverage html -d {envtmpdir}/htmlcov \ + !py34: --show-contexts \ + --title virtualenv-{envname}-coverage install_command = python -m pip install {opts} {packages} --disable-pip-version-check [testenv:fix_lint] |