Skip to content

Commit 470ad94

Browse files
authored
Parse [tox:testenv] sections in setup.cfg (#1724)
1 parent b5ff4dc commit 470ad94

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Matt Good
7171
Matt Jeffery
7272
Matthew Kenigsberg
7373
Mattieu Agopian
74+
Mauricio Villegas
7475
Mehdi Abaakouk
7576
Michael Manganiello
7677
Mickaël Schoentgen

docs/changelog/1724.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support parsing [tox:testenv*] sections in setup.cfg. - by :user:`mauvilsa`

docs/config.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ At the moment tox supports three configuration locations prioritized in the foll
1515
As far as the configuration format at the moment we only support standard ConfigParser_ "ini-style" format
1616
(there is a plan to add a pure TOML one soon).
1717
``tox.ini`` and ``setup.cfg`` are such files. Note that ``setup.cfg`` requires the content to be under the
18-
``tox:tox`` section and is otherwise ignored. ``pyproject.toml`` on the other hand is in TOML format. However, one can inline
19-
the *ini-style* format under the ``tool.tox.legacy_tox_ini`` key as a multi-line string.
18+
``tox:tox`` and ``tox:testenv`` sections and is otherwise ignored. ``pyproject.toml`` on the other hand is
19+
in TOML format. However, one can inline the *ini-style* format under the ``tool.tox.legacy_tox_ini`` key
20+
as a multi-line string.
2021

2122
Below you find the specification for the *ini-style* format, but you might want to skim some
2223
:doc:`examples` first and use this page as a reference.

src/tox/config/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,15 +1246,16 @@ def line_of_default_to_zero(section, name=None):
12461246
results = {}
12471247
cur_self = self
12481248

1249-
def run(name, section, subs, config):
1249+
def run(name, section, subs, config, prefix):
12501250
try:
1251-
results[name] = cur_self.make_envconfig(name, section, subs, config)
1251+
results[name] = cur_self.make_envconfig(name, section, subs, config, prefix=prefix)
12521252
except Exception as exception:
12531253
failures[name] = (exception, traceback.format_exc())
12541254

12551255
order = []
1256+
prefix = "tox:" if ini_path.basename == "setup.cfg" else ""
12561257
for name in all_envs:
1257-
section = "{}{}".format(testenvprefix, name)
1258+
section = "{}{}".format(prefix + testenvprefix, name)
12581259
factors = set(name.split("-"))
12591260
if (
12601261
section in self._cfg
@@ -1264,7 +1265,7 @@ def run(name, section, subs, config):
12641265
)
12651266
):
12661267
order.append(name)
1267-
thread = Thread(target=run, args=(name, section, reader._subs, config))
1268+
thread = Thread(target=run, args=(name, section, reader._subs, config, prefix))
12681269
thread.daemon = True
12691270
thread.start()
12701271
to_do.append(thread)
@@ -1377,9 +1378,14 @@ def _list_section_factors(self, section):
13771378
factors.update(*mapcat(_split_factor_expr_all, exprs))
13781379
return factors
13791380

1380-
def make_envconfig(self, name, section, subs, config, replace=True):
1381+
def make_envconfig(self, name, section, subs, config, replace=True, prefix=""):
13811382
factors = set(name.split("-"))
1382-
reader = SectionReader(section, self._cfg, fallbacksections=["testenv"], factors=factors)
1383+
reader = SectionReader(
1384+
section,
1385+
self._cfg,
1386+
fallbacksections=[prefix + "testenv"],
1387+
factors=factors,
1388+
)
13831389
tc = TestenvConfig(name, config, factors, reader)
13841390
reader.addsubstitutions(
13851391
envname=name,

tests/unit/config/test_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ def test_envdir_set_manually_with_substitutions(self, newconfig):
9191
envconfig = config.envconfigs["dev"]
9292
assert envconfig.envdir == config.toxworkdir.join("foobar")
9393

94+
def test_envdir_set_manually_setup_cfg(self, tmpdir, newconfig):
95+
config = newconfig(
96+
[],
97+
"""
98+
[tox:tox]
99+
envlist = py36,py37
100+
[tox:testenv]
101+
envdir = dev
102+
[tox:testenv:py36]
103+
envdir = dev36
104+
""",
105+
filename="setup.cfg",
106+
)
107+
envconfig = config.envconfigs["py36"]
108+
assert envconfig.envdir == tmpdir.join("dev36")
109+
envconfig = config.envconfigs["py37"]
110+
assert envconfig.envdir == tmpdir.join("dev")
111+
94112
def test_force_dep_version(self, initproj):
95113
"""
96114
Make sure we can override dependencies configured in tox.ini when using the command line

0 commit comments

Comments
 (0)