|
13 | 13 |
|
14 | 14 |
|
15 | 15 | from collections import namedtuple
|
16 |
| -from copy import copy |
17 | 16 |
|
18 | 17 | try:
|
19 | 18 | # Python 3
|
|
37 | 36 |
|
38 | 37 | # -----------------------------------------------------------------------------
|
39 | 38 |
|
40 |
| -_RawPreset = namedtuple('_RawPreset', ['name', 'mixins', 'args']) |
| 39 | +_Mixin = namedtuple('_Mixin', ['name']) |
| 40 | +_Argument = namedtuple('_Argument', ['name', 'value']) |
| 41 | +_RawPreset = namedtuple('_RawPreset', ['name', 'options']) |
41 | 42 |
|
42 | 43 |
|
43 | 44 | def _interpolate_string(string, values):
|
@@ -128,25 +129,29 @@ def _parse_raw_preset(self, section):
|
128 | 129 | except configparser.InterpolationMissingOptionError as e:
|
129 | 130 | raise MissingOptionError(e)
|
130 | 131 |
|
131 |
| - args, mixins = [], [] |
| 132 | + args = [] |
132 | 133 | for (name, value) in section_items:
|
133 | 134 | # Ignore the '--' separator, it's no longer necessary
|
134 | 135 | if name == 'dash-dash':
|
135 | 136 | continue
|
136 | 137 |
|
137 | 138 | # Parse out mixin names
|
138 | 139 | if name == 'mixin-preset':
|
139 |
| - mixins = list(map(lambda name: name.strip(), |
140 |
| - value.strip().splitlines())) |
| 140 | + lines = value.strip().splitlines() |
| 141 | + args += [_Mixin(name.strip()) for name in lines] |
141 | 142 | continue
|
142 | 143 |
|
143 | 144 | name = '--' + name # Format as an option name
|
144 |
| - args.append((name, value)) |
| 145 | + args.append(_Argument(name, value)) |
145 | 146 |
|
146 |
| - return _RawPreset(preset_name, mixins, args) |
| 147 | + return _RawPreset(preset_name, args) |
147 | 148 |
|
148 | 149 | def _parse_raw_presets(self):
|
149 | 150 | for section in self._parser.sections():
|
| 151 | + # Skip all non-preset sections |
| 152 | + if not section.startswith(PresetParser._PRESET_PREFIX): |
| 153 | + continue |
| 154 | + |
150 | 155 | raw_preset = self._parse_raw_preset(section)
|
151 | 156 | self._presets[raw_preset.name] = raw_preset
|
152 | 157 |
|
@@ -203,11 +208,14 @@ def _resolve_preset_mixins(self, raw_preset):
|
203 | 208 | assert isinstance(raw_preset, _RawPreset)
|
204 | 209 |
|
205 | 210 | # Expand mixin arguments
|
206 |
| - args = copy(raw_preset.args) |
207 |
| - for mixin_name in raw_preset.mixins: |
208 |
| - mixin = self._get_preset(mixin_name) |
209 |
| - |
210 |
| - args += mixin.args |
| 211 | + args = [] |
| 212 | + for option in raw_preset.options: |
| 213 | + if isinstance(option, _Mixin): |
| 214 | + args += self._get_preset(option.name).args |
| 215 | + elif isinstance(option, _Argument): |
| 216 | + args.append((option.name, option.value)) |
| 217 | + else: |
| 218 | + raise ValueError('invalid argument type: {}', option.__class__) |
211 | 219 |
|
212 | 220 | return Preset(raw_preset.name, args)
|
213 | 221 |
|
|
0 commit comments