Skip to content

Commit dd9f5eb

Browse files
committed
Monkeypatch tox to permit fullstop/period in factors.
e.g [py36-attrs{19.3, 20.1}] -> [py36-attrs19.3] and [py36-attrs20.1]
1 parent cbd5097 commit dd9f5eb

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

tox_envlist/__init__.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Allows selection of a different tox envlist.
66
"""
77
#
8-
# Copyright © 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
8+
# Copyright © 2020-2021 Dominic Davis-Foster <dominic@davis-foster.co.uk>
99
#
1010
# Permission is hereby granted, free of charge, to any person obtaining a copy
1111
# of this software and associated documentation files (the "Software"), to deal
@@ -27,14 +27,15 @@
2727
#
2828

2929
# stdlib
30+
import itertools
3031
import re
3132
import warnings
3233
from itertools import chain
3334
from typing import Dict, List
3435

3536
# 3rd party
3637
import pluggy # type: ignore
37-
from tox.config import Config, Parser # type: ignore
38+
from tox.config import Config, ParseIni, Parser # type: ignore
3839

3940
try:
4041
# 3rd party
@@ -119,3 +120,29 @@ def tox_configure(config: Config):
119120
config.args = list(chain.from_iterable(args))
120121

121122
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

Comments
 (0)