From 5e6f7e6b250eef02d51afa976ef4ac1ef8e9b30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Sat, 17 Dec 2022 11:52:34 -0800 Subject: [PATCH] Fix plain section shadows env config (#2742) Resolves https://github.com/tox-dev/tox/issues/2636 --- .pre-commit-config.yaml | 8 ++++---- docs/changelog/2636.bugfix.rst | 2 ++ pyproject.toml | 4 ++-- src/tox/config/source/ini.py | 2 +- .../python/virtual_env/package/cmd_builder.py | 4 ++-- tests/session/cmd/test_show_config.py | 13 +++++++++++++ tests/test_provision.py | 1 + .../virtual_env/package/test_python_package_util.py | 8 ++++++-- tox.ini | 6 ++---- 9 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 docs/changelog/2636.bugfix.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a532af789..277015e94 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/asottile/add-trailing-comma - rev: v2.3.0 + rev: v2.4.0 hooks: - id: add-trailing-comma args: [--py36-plus] @@ -25,7 +25,7 @@ repos: - id: pyupgrade files: "^(tests/demo_pkg_inline/build.py)$" - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: v5.11.3 hooks: - id: isort - repo: https://github.com/psf/black @@ -37,7 +37,7 @@ repos: rev: v1.12.1 hooks: - id: blacken-docs - additional_dependencies: [black==22.10] + additional_dependencies: [black==22.12] - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.9.0 hooks: @@ -61,7 +61,7 @@ repos: - pep8-naming==0.13.2 - flake8-pyproject==1.2.2 - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.0.0-alpha.4" + rev: "v2.7.1" hooks: - id: prettier additional_dependencies: diff --git a/docs/changelog/2636.bugfix.rst b/docs/changelog/2636.bugfix.rst new file mode 100644 index 000000000..3362adb05 --- /dev/null +++ b/docs/changelog/2636.bugfix.rst @@ -0,0 +1,2 @@ +A plain section in INI configuration matching a tox environment name shadowed the laters configuration - by +:user:`gaborbernat`. diff --git a/pyproject.toml b/pyproject.toml index 3bf5ca996..7ffb8baef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ optional-dependencies.testing = [ "build[virtualenv]>=0.9", "covdefaults>=2.2.2", "devpi-process>=0.3", - "diff-cover>=7.2", + "diff-cover>=7.3", "distlib>=0.3.6", "flaky>=3.7", "hatch-vcs>=0.2.1", @@ -114,7 +114,7 @@ profile = "black" line_length = 120 [tool.mypy] -python_version = "3.7" +python_version = "3.11" show_error_codes = true strict = true overrides = [ diff --git a/src/tox/config/source/ini.py b/src/tox/config/source/ini.py index d28ae083f..ee3ed77c0 100644 --- a/src/tox/config/source/ini.py +++ b/src/tox/config/source/ini.py @@ -85,8 +85,8 @@ def register_factors(envs: Iterable[str]) -> None: for section in self.sections(): register_factors(section.names) for name in section.names: - self._section_mapping[name].append(section.key) if section.is_test_env: + self._section_mapping[name].append(section.key) yield name # add all conditional markers that are not part of the explicitly defined sections for section in self.sections(): diff --git a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py index fc3005ead..9140a9361 100644 --- a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py +++ b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py @@ -134,7 +134,7 @@ def child_pkg_envs(self, run_conf: EnvConfigSet) -> Iterator[PackageToxEnv]: # yield self._sdist_meta_tox_env -class WheelDistribution(Distribution): # type: ignore # cannot subclass has type Any +class WheelDistribution(Distribution): # cannot subclass has type Any def __init__(self, wheel: Path) -> None: self._wheel = wheel self._dist_name: str | None = None @@ -160,7 +160,7 @@ def read_text(self, filename: str) -> str | None: except KeyError: return None - def locate_file(self, path: str) -> PathLike[str]: + def locate_file(self, path: str | PathLike[str]) -> PathLike[str]: return self._wheel / path # pragma: no cover # not used by us, but part of the ABC diff --git a/tests/session/cmd/test_show_config.py b/tests/session/cmd/test_show_config.py index d4fa3b378..33c4fc487 100644 --- a/tests/session/cmd/test_show_config.py +++ b/tests/session/cmd/test_show_config.py @@ -233,3 +233,16 @@ def test_show_config_core_host_python(tox_project: ToxProjectCreator) -> None: outcome = project.run("c", "--core", "-e", "py", "-k", "host_python") outcome.assert_success() assert f"host_python = {sys.executable}" in outcome.out + + +def test_show_config_matching_env_section(tox_project: ToxProjectCreator) -> None: + ini = """ + [a] + [testenv:a] + deps = c>=1 + [testenv:b] + deps = {[testenv:a]deps}""" + project = tox_project({"tox.ini": ini}) + outcome = project.run("c", "-e", "a,b", "-k", "deps") + outcome.assert_success() + assert outcome.out.count("c>=1") == 2, outcome.out diff --git a/tests/test_provision.py b/tests/test_provision.py index 56952a184..cc9591531 100644 --- a/tests/test_provision.py +++ b/tests/test_provision.py @@ -83,6 +83,7 @@ def tox_wheels(tox_wheel: Path, tmp_path_factory: TempPathFactory) -> list[Path] wheel_cache = ROOT / ".wheel_cache" / f"{sys.version_info.major}.{sys.version_info.minor}" wheel_cache.mkdir(parents=True, exist_ok=True) cmd = [sys.executable, "-I", "-m", "pip", "download", "-d", str(wheel_cache)] + assert distribution.requires is not None for req in distribution.requires: requirement = Requirement(req) if not requirement.extras: # pragma: no branch # we don't need to install any extras (tests/docs/etc) diff --git a/tests/tox_env/python/virtual_env/package/test_python_package_util.py b/tests/tox_env/python/virtual_env/package/test_python_package_util.py index 25d84283e..bac77d8f7 100644 --- a/tests/tox_env/python/virtual_env/package/test_python_package_util.py +++ b/tests/tox_env/python/virtual_env/package/test_python_package_util.py @@ -25,7 +25,9 @@ def pkg_with_extras(pkg_with_extras_project: Path) -> PathDistribution: def test_load_dependency_no_extra(pkg_with_extras: PathDistribution) -> None: - result = dependencies_with_extras([Requirement(i) for i in pkg_with_extras.requires], set(), "") + requires = pkg_with_extras.requires + assert requires is not None + result = dependencies_with_extras([Requirement(i) for i in requires], set(), "") for left, right in zip_longest(result, (Requirement("platformdirs>=2.1"), Requirement("colorama>=0.4.3"))): assert isinstance(right, Requirement) assert str(left) == str(right) @@ -33,7 +35,9 @@ def test_load_dependency_no_extra(pkg_with_extras: PathDistribution) -> None: def test_load_dependency_many_extra(pkg_with_extras: PathDistribution) -> None: py_ver = ".".join(str(i) for i in sys.version_info[0:2]) - result = dependencies_with_extras([Requirement(i) for i in pkg_with_extras.requires], {"docs", "testing"}, "") + requires = pkg_with_extras.requires + assert requires is not None + result = dependencies_with_extras([Requirement(i) for i in requires], {"docs", "testing"}, "") exp = [ Requirement("platformdirs>=2.1"), Requirement("colorama>=0.4.3"), diff --git a/tox.ini b/tox.ini index f24f218d5..24b5fa32c 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ setenv = extras = testing commands = - pytest {tty:--color=yes} {posargs: \ + pytest {posargs: \ --junitxml {toxworkdir}{/}junit.{envname}.xml --cov {envsitepackagesdir}{/}tox --cov {toxinidir}{/}tests \ --cov-config={toxinidir}{/}pyproject.toml --no-cov-on-fail --cov-report term-missing:skip-covered --cov-context=test \ --cov-report html:{envtmpdir}{/}htmlcov \ @@ -45,13 +45,11 @@ skip_install = true deps = pre-commit>=2.20 commands = - pre-commit run --all-files --show-diff-on-failure {tty:--color=always} {posargs} + pre-commit run --all-files --show-diff-on-failure {posargs} python -c 'print(r"hint: run {envbindir}{/}pre-commit install to add checks as pre-commit hook")' [testenv:type] description = run type check on code base -setenv = - {tty:MYPY_FORCE_COLOR = 1} deps = mypy==0.991 types-cachetools>=5.2.1