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 complex negative factor filters not working #2757

Merged
merged 2 commits into from Dec 19, 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
2 changes: 2 additions & 0 deletions docs/changelog/2634.bugfix.rst
@@ -0,0 +1,2 @@
Fix tox auto-provisioning not working and relax :ref:`min_version` default from ``4.0`` to no version constraint
- by user:`gaborbernat`.
4 changes: 2 additions & 2 deletions docs/changelog/2720.bugfix.rst
@@ -1,2 +1,2 @@
Fix assertion in ``test_result_json_sequential`` when interpreter
``_base_executable`` is a hardlink (macOS homebrew) - by user:`masenf`
Fix assertion in ``test_result_json_sequential`` when interpreter ``_base_executable`` is a hardlink (macOS homebrew)
- by user:`masenf`.
1 change: 1 addition & 0 deletions docs/changelog/2747.bugfix.rst
@@ -0,0 +1 @@
Complex negative factor filters not working - by user:`gaborbernat`.
5 changes: 4 additions & 1 deletion src/tox/config/loader/ini/factor.py
Expand Up @@ -67,6 +67,9 @@ def find_factor_groups(value: str) -> Iterator[list[tuple[str, bool]]]:
yield result


_FACTOR_RE = re.compile(r"!?[\w._][\w._-]*")


def expand_env_with_negation(value: str) -> Iterator[str]:
"""transform '{py,!pi}-{a,b},c' to ['py-a', 'py-b', '!pi-a', '!pi-b', 'c']"""
for key, group in groupby(re.split(r"((?:{[^}]+})+)|,", value), key=bool):
Expand All @@ -76,7 +79,7 @@ def expand_env_with_negation(value: str) -> Iterator[str]:
parts = [[i.strip() for i in elem.split(",")] for elem in elements]
for variant in product(*parts):
variant_str = "".join(variant)
if not re.fullmatch(r"!?[\w._][\w._-]*", variant_str):
if not all(_FACTOR_RE.fullmatch(i) for i in variant_str.split("-")):
raise ValueError(variant_str)
yield variant_str

Expand Down
6 changes: 6 additions & 0 deletions tests/config/loader/ini/test_factor.py
Expand Up @@ -122,6 +122,8 @@ def test_factor_config(tox_ini_conf: ToxIniCreator) -> None:
django15: Django>=1.5,<1.6
django16: Django>=1.6,<1.7
py36: unittest2
!py37,!django16: negation-or
!py37-!django16: negation-and
""",
)
assert list(config) == ["py36-django15", "py36-django16", "py37-django15", "py37-django16"]
Expand All @@ -132,10 +134,14 @@ def test_factor_config(tox_ini_conf: ToxIniCreator) -> None:
assert "pytest" in deps
if "py36" in env:
assert "unittest2" in deps
assert "negation-or" in deps
if "django15" in env:
assert "Django>=1.5,<1.6" in deps
assert "negation-or" in deps
if "django16" in env:
assert "Django>=1.6,<1.7" in deps
if "py36-django15" == env_config.name:
assert "negation-and" in deps


def test_factor_config_do_not_replace_unescaped_comma(tox_ini_conf: ToxIniCreator) -> None:
Expand Down