Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plain section shadows env config #2742

Merged
merged 1 commit into from Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions 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`.
4 changes: 2 additions & 2 deletions pyproject.toml
Expand Up @@ -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",
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/tox/config/source/ini.py
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions src/tox/tox_env/python/virtual_env/package/cmd_builder.py
Expand Up @@ -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
Expand All @@ -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


Expand Down
13 changes: 13 additions & 0 deletions tests/session/cmd/test_show_config.py
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/test_provision.py
Expand Up @@ -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)
Expand Down
Expand Up @@ -25,15 +25,19 @@ 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)


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"),
Expand Down
6 changes: 2 additions & 4 deletions tox.ini
Expand Up @@ -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 \
Expand All @@ -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
Expand Down