Skip to content

Commit 294159e

Browse files
Fix complex negative factor filters not working (#2757)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Resolves #2747
1 parent 55a7b66 commit 294159e

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

docs/changelog/2634.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix tox auto-provisioning not working and relax :ref:`min_version` default from ``4.0`` to no version constraint
2+
- by user:`gaborbernat`.

docs/changelog/2720.bugfix.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Fix assertion in ``test_result_json_sequential`` when interpreter
2-
``_base_executable`` is a hardlink (macOS homebrew) - by user:`masenf`
1+
Fix assertion in ``test_result_json_sequential`` when interpreter ``_base_executable`` is a hardlink (macOS homebrew)
2+
- by user:`masenf`.

docs/changelog/2747.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Complex negative factor filters not working - by user:`gaborbernat`.

src/tox/config/loader/ini/factor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def find_factor_groups(value: str) -> Iterator[list[tuple[str, bool]]]:
6767
yield result
6868

6969

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

tests/config/loader/ini/test_factor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ def test_factor_config(tox_ini_conf: ToxIniCreator) -> None:
122122
django15: Django>=1.5,<1.6
123123
django16: Django>=1.6,<1.7
124124
py36: unittest2
125+
!py37,!django16: negation-or
126+
!py37-!django16: negation-and
125127
""",
126128
)
127129
assert list(config) == ["py36-django15", "py36-django16", "py37-django15", "py37-django16"]
@@ -132,10 +134,14 @@ def test_factor_config(tox_ini_conf: ToxIniCreator) -> None:
132134
assert "pytest" in deps
133135
if "py36" in env:
134136
assert "unittest2" in deps
137+
assert "negation-or" in deps
135138
if "django15" in env:
136139
assert "Django>=1.5,<1.6" in deps
140+
assert "negation-or" in deps
137141
if "django16" in env:
138142
assert "Django>=1.6,<1.7" in deps
143+
if "py36-django15" == env_config.name:
144+
assert "negation-and" in deps
139145

140146

141147
def test_factor_config_do_not_replace_unescaped_comma(tox_ini_conf: ToxIniCreator) -> None:

0 commit comments

Comments
 (0)