Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8a88c1

Browse files
authored
Allow braced range syntax in internal sections of tox.ini file (#3631)
1 parent6432872 commitf8a88c1

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

‎docs/changelog/3571.bugfix.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
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.
2+
- by:user:`marcosboger`

‎docs/config.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,12 @@ Both enumerations (``{1,2,3}``) and numerical ranges (``{1-3}``) are supported,
16631663
[tox]
16641664
env_list = py3{8-10, 11, 13-14}
16651665
1666+
[testenv]
1667+
deps =
1668+
py{310,311-314}: urllib3
1669+
setenv =
1670+
py{310,311-314}:FOO=bar
1671+
16661672
will create the following envs:
16671673

16681674
..code-block::shell

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def expand_factors(value: str) -> Iterator[tuple[list[list[tuple[str, bool]]] |
6464

6565
deffind_factor_groups(value:str)->Iterator[list[tuple[str,bool]]]:
6666
"""Transform '{py,!pi}-{a,b},c' to [{'py', 'a'}, {'py', 'b'}, {'pi', 'a'}, {'pi', 'b'}, {'c'}]."""
67+
value=expand_ranges(value)
6768
forenvinexpand_env_with_negation(value):
6869
result= [name_with_negate(f)forfinenv.split("-")]
6970
yieldresult

‎src/tox/config/loader/str_convert.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
fromtypingimportTYPE_CHECKING,Any
1111

1212
fromtox.config.loader.convertimportConvert
13-
fromtox.config.loader.ini.factorimportexpand_ranges
1413
fromtox.config.typesimportCommand,EnvList
1514

1615
ifTYPE_CHECKING:
@@ -115,7 +114,6 @@ def to_command(value: str) -> Command | None:
115114
defto_env_list(value:str)->EnvList:
116115
fromtox.config.loader.ini.factorimportextend_factors# noqa: PLC0415
117116

118-
value=expand_ranges(value)
119117
elements=list(chain.from_iterable(extend_factors(expr)forexprinvalue.split("\n")))
120118
returnEnvList(elements)
121119

‎src/tox/config/source/ini_section.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__importannotations
22

3-
fromtox.config.loader.ini.factorimportexpand_ranges,extend_factors
3+
fromtox.config.loader.ini.factorimportextend_factors
44
fromtox.config.loader.sectionimportSection
55

66

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

1616
@property
1717
defnames(self)->list[str]:
18-
returnlist(extend_factors(expand_ranges(self.name)))
18+
returnlist(extend_factors(self.name))
1919

2020

2121
TEST_ENV_PREFIX="testenv"

‎tests/config/loader/ini/test_factor.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,40 @@ def test_ini_loader_raw_with_factors(
273273
assertoutcome==result
274274

275275

276+
deftest_generative_ranges_in_deps(tox_ini_conf:ToxIniCreator)->None:
277+
config=tox_ini_conf(
278+
"""
279+
[testenv]
280+
deps-x =
281+
py{310-314}: black
282+
""",
283+
)
284+
assertlist(config)== ["py310","py311","py312","py313","py314"]
285+
286+
287+
deftest_generative_ranges_in_deps_with_mixed_approach(tox_ini_conf:ToxIniCreator)->None:
288+
config=tox_ini_conf(
289+
"""
290+
[testenv]
291+
deps-x =
292+
py3{10-14}: black
293+
""",
294+
)
295+
assertlist(config)== ["py310","py311","py312","py313","py314"]
296+
297+
298+
deftest_generative_ranges_in_setenv(tox_ini_conf:ToxIniCreator)->None:
299+
config=tox_ini_conf(
300+
"""
301+
[testenv]
302+
setenv =
303+
foo{1,2}: FOO=bar
304+
foo{3-5}: FOO=baz
305+
""",
306+
)
307+
assertlist(config)== ["foo1","foo2","foo3","foo4","foo5"]
308+
309+
276310
deftest_generative_section_name_with_ranges(tox_ini_conf:ToxIniCreator)->None:
277311
config=tox_ini_conf(
278312
"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp