Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/3571.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Expand braced range syntax in all internal sections of ``tox.ini`` (e.g. ``deps``, ``testenv``). Syntax like py3{10-14} can be used in those sections now.
- by :user:`marcosboger`
6 changes: 6 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,12 @@ Both enumerations (``{1,2,3}``) and numerical ranges (``{1-3}``) are supported,
[tox]
env_list = py3{8-10, 11, 13-14}

[testenv]
deps =
py{310,311-314}: urllib3
setenv =
py{310,311-314}: FOO=bar

will create the following envs:

.. code-block:: shell
Expand Down
1 change: 1 addition & 0 deletions src/tox/config/loader/ini/factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def expand_factors(value: str) -> Iterator[tuple[list[list[tuple[str, bool]]] |

def find_factor_groups(value: str) -> Iterator[list[tuple[str, bool]]]:
"""Transform '{py,!pi}-{a,b},c' to [{'py', 'a'}, {'py', 'b'}, {'pi', 'a'}, {'pi', 'b'}, {'c'}]."""
value = expand_ranges(value)
for env in expand_env_with_negation(value):
result = [name_with_negate(f) for f in env.split("-")]
yield result
Expand Down
2 changes: 0 additions & 2 deletions src/tox/config/loader/str_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import TYPE_CHECKING, Any

from tox.config.loader.convert import Convert
from tox.config.loader.ini.factor import expand_ranges
from tox.config.types import Command, EnvList

if TYPE_CHECKING:
Expand Down Expand Up @@ -115,7 +114,6 @@ def to_command(value: str) -> Command | None:
def to_env_list(value: str) -> EnvList:
from tox.config.loader.ini.factor import extend_factors # noqa: PLC0415

value = expand_ranges(value)
elements = list(chain.from_iterable(extend_factors(expr) for expr in value.split("\n")))
return EnvList(elements)

Expand Down
4 changes: 2 additions & 2 deletions src/tox/config/source/ini_section.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from tox.config.loader.ini.factor import expand_ranges, extend_factors
from tox.config.loader.ini.factor import extend_factors
from tox.config.loader.section import Section


Expand All @@ -15,7 +15,7 @@ def is_test_env(self) -> bool:

@property
def names(self) -> list[str]:
return list(extend_factors(expand_ranges(self.name)))
return list(extend_factors(self.name))


TEST_ENV_PREFIX = "testenv"
Expand Down
34 changes: 34 additions & 0 deletions tests/config/loader/ini/test_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,40 @@ def test_ini_loader_raw_with_factors(
assert outcome == result


def test_generative_ranges_in_deps(tox_ini_conf: ToxIniCreator) -> None:
config = tox_ini_conf(
"""
[testenv]
deps-x =
py{310-314}: black
""",
)
assert list(config) == ["py310", "py311", "py312", "py313", "py314"]


def test_generative_ranges_in_deps_with_mixed_approach(tox_ini_conf: ToxIniCreator) -> None:
config = tox_ini_conf(
"""
[testenv]
deps-x =
py3{10-14}: black
""",
)
assert list(config) == ["py310", "py311", "py312", "py313", "py314"]


def test_generative_ranges_in_setenv(tox_ini_conf: ToxIniCreator) -> None:
config = tox_ini_conf(
"""
[testenv]
setenv =
foo{1,2}: FOO=bar
foo{3-5}: FOO=baz
""",
)
assert list(config) == ["foo1", "foo2", "foo3", "foo4", "foo5"]


def test_generative_section_name_with_ranges(tox_ini_conf: ToxIniCreator) -> None:
config = tox_ini_conf(
"""
Expand Down