Skip to content

Commit 8f086c8

Browse files
committed
fixup! feat(config): Allow ranges in envlist
1 parent d535b70 commit 8f086c8

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,22 @@ def name_with_negate(factor: str) -> tuple[str, bool]:
9292
def is_negated(factor: str) -> bool:
9393
return factor.startswith("!")
9494

95+
def expand_ranges(value: str) -> str:
96+
"""Expand ranges in env expressions, eg py3{10-13} -> "py3{10,11,12,13}"""
97+
matches = re.findall(r"((\d+)-(\d+)|\d+)(?:,|})", value)
98+
for src, start_, end_ in matches:
99+
if src and start_ and end_:
100+
start = int(start_)
101+
end = int(end_)
102+
direction = 1 if start < end else -1
103+
expansion = ",".join(str(x) for x in range(start, end + direction, direction))
104+
value = value.replace(src, expansion, 1)
105+
return value
95106

96107
__all__ = (
97108
"expand_factors",
98109
"extend_factors",
99110
"filter_for_env",
100111
"find_envs",
112+
"expand_ranges",
101113
)

src/tox/config/loader/replacer.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,9 @@ def replace_env(conf: Config | None, args: list[str], conf_args: ConfigLoadArgs)
287287
def replace_tty(args: list[str]) -> str:
288288
return (args[0] if len(args) > 0 else "") if sys.stdout.isatty() else args[1] if len(args) > 1 else ""
289289

290-
291-
def expand_ranges(value: str) -> str:
292-
"""Expand ranges in env expressions, eg py3{10-13} -> "py3{10,11,12,13}"""
293-
matches = re.findall(r"((\d+)-(\d+)|\d+)(?:,|})", value)
294-
for src, start_, end_ in matches:
295-
if src and start_ and end_:
296-
start = int(start_)
297-
end = int(end_)
298-
direction = 1 if start < end else -1
299-
expansion = ",".join(str(x) for x in range(start, end + direction, direction))
300-
value = value.replace(src, expansion, 1)
301-
return value
302-
303-
304290
__all__ = [
305291
"MatchExpression",
306292
"MatchRecursionError",
307-
"expand_ranges",
308293
"find_replace_expr",
309294
"load_posargs",
310295
"replace",

src/tox/config/loader/str_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import TYPE_CHECKING, Any, Iterator
1111

1212
from tox.config.loader.convert import Convert
13-
from tox.config.loader.replacer import expand_ranges
13+
from tox.config.loader.ini.factor import expand_ranges
1414
from tox.config.types import Command, EnvList
1515

1616
if TYPE_CHECKING:

src/tox/config/source/ini_section.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

3-
from tox.config.loader.ini.factor import extend_factors
4-
from tox.config.loader.replacer import expand_ranges
3+
from tox.config.loader.ini.factor import extend_factors, expand_ranges
54
from tox.config.loader.section import Section
65

76

0 commit comments

Comments
 (0)