Skip to content

Commit 5e6f7e6

Browse files
authored
Fix plain section shadows env config (#2742)
Resolves #2636
1 parent 9553e4f commit 5e6f7e6

File tree

9 files changed

+33
-15
lines changed

9 files changed

+33
-15
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
- id: end-of-file-fixer
1313
- id: trailing-whitespace
1414
- repo: https://github.com/asottile/add-trailing-comma
15-
rev: v2.3.0
15+
rev: v2.4.0
1616
hooks:
1717
- id: add-trailing-comma
1818
args: [--py36-plus]
@@ -25,7 +25,7 @@ repos:
2525
- id: pyupgrade
2626
files: "^(tests/demo_pkg_inline/build.py)$"
2727
- repo: https://github.com/PyCQA/isort
28-
rev: 5.10.1
28+
rev: v5.11.3
2929
hooks:
3030
- id: isort
3131
- repo: https://github.com/psf/black
@@ -37,7 +37,7 @@ repos:
3737
rev: v1.12.1
3838
hooks:
3939
- id: blacken-docs
40-
additional_dependencies: [black==22.10]
40+
additional_dependencies: [black==22.12]
4141
- repo: https://github.com/pre-commit/pygrep-hooks
4242
rev: v1.9.0
4343
hooks:
@@ -61,7 +61,7 @@ repos:
6161
- pep8-naming==0.13.2
6262
- flake8-pyproject==1.2.2
6363
- repo: https://github.com/pre-commit/mirrors-prettier
64-
rev: "v3.0.0-alpha.4"
64+
rev: "v2.7.1"
6565
hooks:
6666
- id: prettier
6767
additional_dependencies:

docs/changelog/2636.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A plain section in INI configuration matching a tox environment name shadowed the laters configuration - by
2+
:user:`gaborbernat`.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ optional-dependencies.testing = [
4848
"build[virtualenv]>=0.9",
4949
"covdefaults>=2.2.2",
5050
"devpi-process>=0.3",
51-
"diff-cover>=7.2",
51+
"diff-cover>=7.3",
5252
"distlib>=0.3.6",
5353
"flaky>=3.7",
5454
"hatch-vcs>=0.2.1",
@@ -114,7 +114,7 @@ profile = "black"
114114
line_length = 120
115115

116116
[tool.mypy]
117-
python_version = "3.7"
117+
python_version = "3.11"
118118
show_error_codes = true
119119
strict = true
120120
overrides = [

src/tox/config/source/ini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def register_factors(envs: Iterable[str]) -> None:
8585
for section in self.sections():
8686
register_factors(section.names)
8787
for name in section.names:
88-
self._section_mapping[name].append(section.key)
8988
if section.is_test_env:
89+
self._section_mapping[name].append(section.key)
9090
yield name
9191
# add all conditional markers that are not part of the explicitly defined sections
9292
for section in self.sections():

src/tox/tox_env/python/virtual_env/package/cmd_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def child_pkg_envs(self, run_conf: EnvConfigSet) -> Iterator[PackageToxEnv]: #
134134
yield self._sdist_meta_tox_env
135135

136136

137-
class WheelDistribution(Distribution): # type: ignore # cannot subclass has type Any
137+
class WheelDistribution(Distribution): # cannot subclass has type Any
138138
def __init__(self, wheel: Path) -> None:
139139
self._wheel = wheel
140140
self._dist_name: str | None = None
@@ -160,7 +160,7 @@ def read_text(self, filename: str) -> str | None:
160160
except KeyError:
161161
return None
162162

163-
def locate_file(self, path: str) -> PathLike[str]:
163+
def locate_file(self, path: str | PathLike[str]) -> PathLike[str]:
164164
return self._wheel / path # pragma: no cover # not used by us, but part of the ABC
165165

166166

tests/session/cmd/test_show_config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,16 @@ def test_show_config_core_host_python(tox_project: ToxProjectCreator) -> None:
233233
outcome = project.run("c", "--core", "-e", "py", "-k", "host_python")
234234
outcome.assert_success()
235235
assert f"host_python = {sys.executable}" in outcome.out
236+
237+
238+
def test_show_config_matching_env_section(tox_project: ToxProjectCreator) -> None:
239+
ini = """
240+
[a]
241+
[testenv:a]
242+
deps = c>=1
243+
[testenv:b]
244+
deps = {[testenv:a]deps}"""
245+
project = tox_project({"tox.ini": ini})
246+
outcome = project.run("c", "-e", "a,b", "-k", "deps")
247+
outcome.assert_success()
248+
assert outcome.out.count("c>=1") == 2, outcome.out

tests/test_provision.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def tox_wheels(tox_wheel: Path, tmp_path_factory: TempPathFactory) -> list[Path]
8383
wheel_cache = ROOT / ".wheel_cache" / f"{sys.version_info.major}.{sys.version_info.minor}"
8484
wheel_cache.mkdir(parents=True, exist_ok=True)
8585
cmd = [sys.executable, "-I", "-m", "pip", "download", "-d", str(wheel_cache)]
86+
assert distribution.requires is not None
8687
for req in distribution.requires:
8788
requirement = Requirement(req)
8889
if not requirement.extras: # pragma: no branch # we don't need to install any extras (tests/docs/etc)

tests/tox_env/python/virtual_env/package/test_python_package_util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ def pkg_with_extras(pkg_with_extras_project: Path) -> PathDistribution:
2525

2626

2727
def test_load_dependency_no_extra(pkg_with_extras: PathDistribution) -> None:
28-
result = dependencies_with_extras([Requirement(i) for i in pkg_with_extras.requires], set(), "")
28+
requires = pkg_with_extras.requires
29+
assert requires is not None
30+
result = dependencies_with_extras([Requirement(i) for i in requires], set(), "")
2931
for left, right in zip_longest(result, (Requirement("platformdirs>=2.1"), Requirement("colorama>=0.4.3"))):
3032
assert isinstance(right, Requirement)
3133
assert str(left) == str(right)
3234

3335

3436
def test_load_dependency_many_extra(pkg_with_extras: PathDistribution) -> None:
3537
py_ver = ".".join(str(i) for i in sys.version_info[0:2])
36-
result = dependencies_with_extras([Requirement(i) for i in pkg_with_extras.requires], {"docs", "testing"}, "")
38+
requires = pkg_with_extras.requires
39+
assert requires is not None
40+
result = dependencies_with_extras([Requirement(i) for i in requires], {"docs", "testing"}, "")
3741
exp = [
3842
Requirement("platformdirs>=2.1"),
3943
Requirement("colorama>=0.4.3"),

tox.ini

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ setenv =
2525
extras =
2626
testing
2727
commands =
28-
pytest {tty:--color=yes} {posargs: \
28+
pytest {posargs: \
2929
--junitxml {toxworkdir}{/}junit.{envname}.xml --cov {envsitepackagesdir}{/}tox --cov {toxinidir}{/}tests \
3030
--cov-config={toxinidir}{/}pyproject.toml --no-cov-on-fail --cov-report term-missing:skip-covered --cov-context=test \
3131
--cov-report html:{envtmpdir}{/}htmlcov \
@@ -45,13 +45,11 @@ skip_install = true
4545
deps =
4646
pre-commit>=2.20
4747
commands =
48-
pre-commit run --all-files --show-diff-on-failure {tty:--color=always} {posargs}
48+
pre-commit run --all-files --show-diff-on-failure {posargs}
4949
python -c 'print(r"hint: run {envbindir}{/}pre-commit install to add checks as pre-commit hook")'
5050

5151
[testenv:type]
5252
description = run type check on code base
53-
setenv =
54-
{tty:MYPY_FORCE_COLOR = 1}
5553
deps =
5654
mypy==0.991
5755
types-cachetools>=5.2.1

0 commit comments

Comments
 (0)