diff options
author | Charles Brunet <charles.brunet@optelgroup.com> | 2020-04-17 13:34:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 18:34:38 +0100 |
commit | 1343f3dc8c30cfe001cf3abf1cc9a139952056ea (patch) | |
tree | 709fa0756efcdc0e9bee5edf9d8d658606e2b3fb /src | |
parent | c102714b9c18b8109e128843fb73cc106b44a4c2 (diff) | |
download | tox-git-1343f3dc8c30cfe001cf3abf1cc9a139952056ea.tar.gz |
expand section names (#1545)
* expand section names
* fix linting
* Added changelog
* trim whitespaces around factor names
* added docs
Diffstat (limited to 'src')
-rw-r--r-- | src/tox/config/__init__.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 85e99185..b33dbc39 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -1015,6 +1015,8 @@ class ParseIni(object): self._cfg = py.iniconfig.IniConfig(config.toxinipath, ini_data) previous_line_of = self._cfg.lineof + self.expand_section_names(self._cfg) + def line_of_default_to_zero(section, name=None): at = previous_line_of(section, name=name) if at is None: @@ -1353,6 +1355,28 @@ class ParseIni(object): raise tox.exception.ConfigError(msg) return env_list, all_envs, _split_env(from_config), envlist_explicit + @staticmethod + def expand_section_names(config): + """Generative section names. + + Allow writing section as [testenv:py{36,37}-cov] + The parser will see it as two different sections: [testenv:py36-cov], [testenv:py37-cov] + + """ + factor_re = re.compile(r"\{\s*([\w\s,]+)\s*\}") + split_re = re.compile(r"\s*,\s*") + to_remove = set() + for section in list(config.sections): + split_section = factor_re.split(section) + for parts in itertools.product(*map(split_re.split, split_section)): + section_name = "".join(parts) + if section_name not in config.sections: + config.sections[section_name] = config.sections[section] + to_remove.add(section) + + for section in to_remove: + del config.sections[section] + def _split_env(env): """if handed a list, action="append" was used for -e """ |