1
0
mirror of https://github.com/fedora-python/tox-current-env.git synced 2025-01-25 22:36:14 +01:00

Drop tox < 3.24, add Python 3.11, fix tox 4 compatibility

This commit is contained in:
Lumir Balhar 2022-11-30 12:24:38 +01:00 committed by Miro Hrončok
parent 463c745f6e
commit 5d5286d4f0
9 changed files with 44 additions and 51 deletions

View File

@ -22,19 +22,23 @@ jobs:
# This information is repeated in tox.ini # This information is repeated in tox.ini
# (see https://github.com/fedora-python/tox-github-action/issues/8) # (see https://github.com/fedora-python/tox-github-action/issues/8)
# Generate it by: tox -l | sed "s/^/- /" # Generate it by: tox -l | sed "s/^/- /"
- py36-tox324
- py36-tox3 - py36-tox3
- py36-toxmaster - py36-tox4
- py37-tox324
- py37-tox3 - py37-tox3
- py37-toxmaster
- py38-tox3
- py38-toxmaster
- py39-tox3
- py39-toxmaster
- py310-tox3
- py310-toxmaster
- py37-tox4 - py37-tox4
- py38-tox324
- py38-tox3
- py38-tox4 - py38-tox4
- py39-tox324
- py39-tox3
- py39-tox4 - py39-tox4
- py310-tox324
- py310-tox3
- py310-tox4 - py310-tox4
- py311-tox324
- py311-tox3
- py311-tox4
# Use GitHub's Linux Docker host # Use GitHub's Linux Docker host
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -232,20 +232,20 @@ installs (a newer version of) ``tox`` and the missing packages
into that environment and proxies all ``tox`` invocations trough that. into that environment and proxies all ``tox`` invocations trough that.
Unfortunately, this is undesired for ``tox-current-env``. Unfortunately, this is undesired for ``tox-current-env``.
1. Starting with ``tox`` 3.23, it is possible to invoke it as 1. It is possible to invoke ``tox`` with ``--no-provision``
``tox --no-provision`` to prevent the provision entirely. to prevent the provision entirely.
When requirements are missing, ``tox`` fails instead of provisioning. When requirements are missing, ``tox`` fails instead of provisioning.
If a path is passed as a value for ``--no-provision``, If a path is passed as a value for ``--no-provision``,
the requirements will be serialized to the file, as JSON. the requirements will be serialized to the file, as JSON.
2. Starting with ``tox`` 3.22, the requires, if specified, are included in the 2. The requires, if specified, are included in the
results of ``tox --print-deps-to``. results of ``tox --print-deps-to``.
This only works when they are installed (otherwise see the first point). This only works when they are installed (otherwise see the first point).
3. The minimal tox version, if specified, is included in the results of 3. The minimal tox version, if specified, is included in the results of
``tox --print-deps-to`` (as ``tox >= X.Y.Z``). ``tox --print-deps-to``.
This only works when the version requirement is satisfied This only works when the version requirement is satisfied
(otherwise see the first point). (otherwise see the first point).
With ``tox >= 3.23``, the recommend way to handle this is: The recommend way to handle this is:
1. Run ``tox --no-provision provision.json --print-deps-to=...`` or similar. 1. Run ``tox --no-provision provision.json --print-deps-to=...`` or similar.
2. If the command fails, install requirements from ``provision.json`` to the 2. If the command fails, install requirements from ``provision.json`` to the

View File

@ -19,7 +19,7 @@ setup(
packages=find_packages("src"), packages=find_packages("src"),
entry_points={"tox": ["current-env = tox_current_env.hooks"]}, entry_points={"tox": ["current-env = tox_current_env.hooks"]},
install_requires=[ install_requires=[
"tox>=3.15", "tox>=3.24",
"importlib_metadata; python_version < '3.8'" "importlib_metadata; python_version < '3.8'"
], ],
extras_require={ extras_require={
@ -42,6 +42,7 @@ setup(
"Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Testing", "Topic :: Software Development :: Testing",
], ],

View File

@ -61,13 +61,9 @@ def _allow_all_externals(envconfig):
setattr(envconfig, option, "*") setattr(envconfig, option, "*")
break break
else: else:
# If none was set, we set one of them, preferably the new one: # If none was set, we set the new one
if hasattr(envconfig, "allowlist_externals"):
envconfig.allowlist_externals = "*" envconfig.allowlist_externals = "*"
else:
# unless we need to fallback to the old and deprecated
# TODO, drop this when we drop support for tox < 3.18
envconfig.whitelist_externals = "*"
@tox.hookimpl @tox.hookimpl
def tox_configure(config): def tox_configure(config):
@ -225,8 +221,7 @@ def tox_dependencies(config):
"""Get dependencies of tox itself, 'minversion' and 'requires' config options""" """Get dependencies of tox itself, 'minversion' and 'requires' config options"""
if config.minversion is not None: if config.minversion is not None:
yield f"tox >= {config.minversion}" yield f"tox >= {config.minversion}"
# config does not have the "requires" attribute until tox 3.22: yield from config.requires
yield from getattr(config, "requires", [])
@tox.hookimpl @tox.hookimpl

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py36,py37,py38,py39,py310 envlist = py36,py37,py38,py39,py310,py311
[testenv] [testenv]
deps = deps =

View File

@ -6,7 +6,6 @@ import sys
import textwrap import textwrap
import pytest import pytest
from packaging.version import parse as ver
from utils import ( from utils import (
DOT_TOX, DOT_TOX,
@ -14,7 +13,6 @@ from utils import (
NATIVE_EXECUTABLE, NATIVE_EXECUTABLE,
NATIVE_SITE_PACKAGES, NATIVE_SITE_PACKAGES,
NATIVE_TOXENV, NATIVE_TOXENV,
TOX_VERSION,
envs_from_tox_ini, envs_from_tox_ini,
is_available, is_available,
modify_config, modify_config,
@ -107,7 +105,6 @@ def test_print_deps_with_tox_minversion(projdir, toxenv, print_deps_stdout_arg):
assert result.stdout == expected assert result.stdout == expected
@pytest.mark.xfail(TOX_VERSION < ver("3.22"), reason="No support in old tox")
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) @pytest.mark.parametrize("toxenv", envs_from_tox_ini())
def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg): def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg):
with modify_config(projdir / "tox.ini") as config: with modify_config(projdir / "tox.ini") as config:
@ -125,7 +122,6 @@ def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg):
assert result.stdout == expected assert result.stdout == expected
@pytest.mark.xfail(TOX_VERSION < ver("3.22"), reason="No support in old tox")
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) @pytest.mark.parametrize("toxenv", envs_from_tox_ini())
def test_print_deps_with_tox_minversion_and_requires( def test_print_deps_with_tox_minversion_and_requires(
projdir, toxenv, print_deps_stdout_arg projdir, toxenv, print_deps_stdout_arg
@ -547,8 +543,6 @@ def test_self_is_not_installed(projdir, flag, usedevelop):
@pytest.mark.parametrize("externals", [None, "allowlist_externals", "whitelist_externals"]) @pytest.mark.parametrize("externals", [None, "allowlist_externals", "whitelist_externals"])
def test_externals(projdir, externals): def test_externals(projdir, externals):
if externals == "allowlist_externals" and TOX_VERSION < ver("3.18"):
pytest.xfail("No support in old tox")
with modify_config(projdir / 'tox.ini') as config: with modify_config(projdir / 'tox.ini') as config:
config['testenv']['commands'] = "echo assertme" config['testenv']['commands'] = "echo assertme"
if externals is not None: if externals is not None:

View File

@ -4,14 +4,13 @@ import shutil
import textwrap import textwrap
import pytest import pytest
from packaging.version import parse as ver
from utils import ( from utils import (
DOT_TOX, DOT_TOX,
NATIVE_EXEC_PREFIX_MSG, NATIVE_EXEC_PREFIX_MSG,
NATIVE_SITE_PACKAGES, NATIVE_SITE_PACKAGES,
NATIVE_TOXENV, NATIVE_TOXENV,
TOX_VERSION, TOX_MIN_VERSION,
envs_from_tox_ini, envs_from_tox_ini,
modify_config, modify_config,
needs_all_pythons, needs_all_pythons,
@ -32,7 +31,7 @@ def test_print_deps(toxenv, print_deps_stdout_arg):
result = tox("-e", toxenv, print_deps_stdout_arg) result = tox("-e", toxenv, print_deps_stdout_arg)
expected = textwrap.dedent( expected = textwrap.dedent(
f""" f"""
tox>={TOX_VERSION} tox>={TOX_MIN_VERSION}
six six
py py
{tox_footer(toxenv)} {tox_footer(toxenv)}
@ -57,7 +56,6 @@ def test_print_deps_with_tox_minversion(projdir, toxenv, print_deps_stdout_arg):
assert prep_tox_output(result.stdout) == expected assert prep_tox_output(result.stdout) == expected
@pytest.mark.xfail(TOX_VERSION < ver("3.22"), reason="No support in old tox")
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) @pytest.mark.parametrize("toxenv", envs_from_tox_ini())
def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg): def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg):
with modify_config(projdir / "tox.ini") as config: with modify_config(projdir / "tox.ini") as config:
@ -67,7 +65,7 @@ def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg):
f""" f"""
setuptools>30 setuptools>30
pluggy pluggy
tox>={TOX_VERSION} tox>={TOX_MIN_VERSION}
six six
py py
{tox_footer(toxenv)} {tox_footer(toxenv)}
@ -76,7 +74,6 @@ def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg):
assert prep_tox_output(result.stdout) == expected assert prep_tox_output(result.stdout) == expected
@pytest.mark.xfail(TOX_VERSION < ver("3.22"), reason="No support in old tox")
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) @pytest.mark.parametrize("toxenv", envs_from_tox_ini())
def test_print_deps_with_tox_minversion_and_requires( def test_print_deps_with_tox_minversion_and_requires(
projdir, toxenv, print_deps_stdout_arg projdir, toxenv, print_deps_stdout_arg
@ -117,7 +114,7 @@ def test_allenvs_print_deps(print_deps_stdout_arg):
result = tox(print_deps_stdout_arg) result = tox(print_deps_stdout_arg)
expected = [] expected = []
for env in envs_from_tox_ini(): for env in envs_from_tox_ini():
expected.extend((f"tox>={TOX_VERSION}", "six", "py", f"{env}: OK")) expected.extend((f"tox>={TOX_MIN_VERSION}", "six", "py", f"{env}: OK"))
expected.pop() # The last "py310: OK" is not there expected.pop() # The last "py310: OK" is not there
expected.append(tox_footer(spaces=0)) expected.append(tox_footer(spaces=0))
expected = ("\n".join(expected)).splitlines() expected = ("\n".join(expected)).splitlines()
@ -140,7 +137,7 @@ def test_print_deps_to_file(toxenv, tmp_path):
depspath = tmp_path / "deps" depspath = tmp_path / "deps"
result = tox("-e", toxenv, "--print-deps-to", str(depspath)) result = tox("-e", toxenv, "--print-deps-to", str(depspath))
assert sorted(depspath.read_text().splitlines()) == sorted( assert sorted(depspath.read_text().splitlines()) == sorted(
[f"tox>={TOX_VERSION}", "six", "py"] [f"tox>={TOX_MIN_VERSION}", "six", "py"]
) )
expected = tox_footer(toxenv, spaces=0) + "\n" expected = tox_footer(toxenv, spaces=0) + "\n"
assert prep_tox_output(result.stdout) == expected assert prep_tox_output(result.stdout) == expected
@ -160,7 +157,7 @@ def test_allenvs_print_deps_to_file(tmp_path, option):
depspath = tmp_path / "deps" depspath = tmp_path / "deps"
result = tox(option, str(depspath)) result = tox(option, str(depspath))
assert sorted(depspath.read_text().splitlines()) == sorted( assert sorted(depspath.read_text().splitlines()) == sorted(
[f"tox>={TOX_VERSION}", "six", "py"] * len(envs_from_tox_ini()) [f"tox>={TOX_MIN_VERSION}", "six", "py"] * len(envs_from_tox_ini())
) )
expected = "" expected = ""
for env in envs_from_tox_ini()[:-1]: for env in envs_from_tox_ini()[:-1]:
@ -303,7 +300,7 @@ def test_print_deps_without_python_command(tmp_path, print_deps_stdout_arg):
result = tox("-e", NATIVE_TOXENV, print_deps_stdout_arg, env=env) result = tox("-e", NATIVE_TOXENV, print_deps_stdout_arg, env=env)
expected = textwrap.dedent( expected = textwrap.dedent(
f""" f"""
tox>={TOX_VERSION} tox>={TOX_MIN_VERSION}
six six
py py
{tox_footer(NATIVE_TOXENV)} {tox_footer(NATIVE_TOXENV)}
@ -342,10 +339,7 @@ def test_self_is_not_installed(projdir, flag, usedevelop):
def test_self_is_installed_with_regular_tox(projdir, usedevelop): def test_self_is_installed_with_regular_tox(projdir, usedevelop):
with modify_config(projdir / "tox.ini") as config: with modify_config(projdir / "tox.ini") as config:
config["testenv"]["usedevelop"] = str(usedevelop) config["testenv"]["usedevelop"] = str(usedevelop)
_ = tox("-e", NATIVE_TOXENV, "-v", quiet=False) result = tox("-e", NATIVE_TOXENV, "-v", quiet=False)
egg_link = DOT_TOX / f"{NATIVE_TOXENV}/{NATIVE_SITE_PACKAGES}" / "test.egg-link" assert "test-0.0.0" in result.stdout
dist_info = ( if usedevelop:
DOT_TOX / f"{NATIVE_TOXENV}/{NATIVE_SITE_PACKAGES}" / "test-0.0.0.dist-info" assert "test-0.0.0-0.editable" in result.stdout
)
to_test = egg_link if usedevelop else dist_info
assert to_test.exists()

View File

@ -52,7 +52,12 @@ def tox(*args, quiet=True, **kwargs):
return cp return cp
TOX_VERSION = ver(tox("--version").stdout.split(" ")[0].split("+")[0]) TOX_MIN_VERSION = TOX_VERSION = ver(tox("--version").stdout.split(" ")[0].split("+")[0])
# TOX_MIN_VERSION follows the same logic as tox itself
# see: https://github.com/tox-dev/tox/blob/6cf388db53402c2595ca8b673ddabece46f4d06e/src/tox/provision.py#L76-L84
if TOX_MIN_VERSION.is_devrelease or TOX_MIN_VERSION.is_prerelease:
TOX_MIN_VERSION = ver(f"{TOX_VERSION.base_version}a0")
TOX4 = TOX_VERSION.major == 4 TOX4 = TOX_VERSION.major == 4
# if TOX4: # if TOX4:
# DOT_TOX /= "4" # DOT_TOX /= "4"

View File

@ -2,15 +2,15 @@
# This information is repeated in .github/workflows/main.yaml # This information is repeated in .github/workflows/main.yaml
# (see https://github.com/fedora-python/tox-github-action/issues/8) # (see https://github.com/fedora-python/tox-github-action/issues/8)
envlist = {py36,py37,py38,py39,py310}-tox{3,master},{py37,py38,py39,py310}-tox4 envlist = {py36,py37,py38,py39,py310,py311}-tox{324,3,4}
[testenv] [testenv]
extras = extras =
tests tests
deps= deps=
tox324: tox >=3.24,<3.25
tox3: tox < 4 tox3: tox < 4
toxmaster: git+https://github.com/tox-dev/tox.git@legacy tox4: tox >=4,< 5
tox4: git+https://github.com/tox-dev/tox.git@rewrite
commands = commands =
!tox4: pytest -v {posargs} tests/test_integration.py !tox4: pytest -v {posargs} tests/test_integration.py
tox4: pytest -v {posargs} tests/test_integration_tox4.py tox4: pytest -v {posargs} tests/test_integration_tox4.py