|
5 | 5 | Allows selection of a different tox envlist. |
6 | 6 | """ |
7 | 7 | # |
8 | | -# Copyright © 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk> |
| 8 | +# Copyright © 2020-2021 Dominic Davis-Foster <dominic@davis-foster.co.uk> |
9 | 9 | # |
10 | 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
11 | 11 | # of this software and associated documentation files (the "Software"), to deal |
|
27 | 27 | # |
28 | 28 |
|
29 | 29 | # stdlib |
| 30 | +import itertools |
30 | 31 | import re |
31 | 32 | import warnings |
32 | 33 | from itertools import chain |
33 | 34 | from typing import Dict, List |
34 | 35 |
|
35 | 36 | # 3rd party |
36 | 37 | import pluggy # type: ignore |
37 | | -from tox.config import Config, Parser # type: ignore |
| 38 | +from tox.config import Config, ParseIni, Parser # type: ignore |
38 | 39 |
|
39 | 40 | try: |
40 | 41 | # 3rd party |
@@ -119,3 +120,29 @@ def tox_configure(config: Config): |
119 | 120 | config.args = list(chain.from_iterable(args)) |
120 | 121 |
|
121 | 122 | return config |
| 123 | + |
| 124 | + |
| 125 | +def expand_section_names(self, config): # noqa: D103 |
| 126 | + # From tox |
| 127 | + # https://github.com/tox-dev |
| 128 | + |
| 129 | + factor_re = re.compile(r"\{\s*([\w\s.,-]+)\s*\}") |
| 130 | + split_re = re.compile(r"\s*,\s*") |
| 131 | + |
| 132 | + to_remove = set() |
| 133 | + |
| 134 | + for section in list(config.sections): |
| 135 | + split_section = factor_re.split(section) |
| 136 | + print(section, split_section, list(itertools.product(*map(split_re.split, split_section)))) |
| 137 | + |
| 138 | + for parts in itertools.product(*map(split_re.split, split_section)): |
| 139 | + section_name = ''.join(parts) |
| 140 | + if section_name not in config.sections: |
| 141 | + config.sections[section_name] = config.sections[section] |
| 142 | + to_remove.add(section) |
| 143 | + |
| 144 | + for section in to_remove: |
| 145 | + del config.sections[section] |
| 146 | + |
| 147 | + |
| 148 | +ParseIni.expand_section_names = expand_section_names |
0 commit comments