Skip to content

Commit

Permalink
Fix complex negative factor filters not working
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Dec 19, 2022
1 parent 55a7b66 commit f22e3bb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
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

0 comments on commit f22e3bb

Please sign in to comment.