Avoid modifying caller `phases` (`kw` is shallow copy)

This commit is contained in:
Etan Kissling 2022-12-11 23:41:08 +01:00
parent 0649e0662c
commit 0c3853e959
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
1 changed files with 13 additions and 7 deletions

View File

@ -604,20 +604,26 @@ def with_config_overrides(config_overrides, emitted_fork=None, emit=True):
""" """
def decorator(fn): def decorator(fn):
def wrapper(*args, spec: Spec, **kw): def wrapper(*args, spec: Spec, **kw):
# Apply config overrides to spec
spec, output_config = spec_with_config_overrides(_get_copy_of_spec(spec), config_overrides) spec, output_config = spec_with_config_overrides(_get_copy_of_spec(spec), config_overrides)
if emit and emitted_fork is None:
yield 'config', 'cfg', output_config
# Apply config overrides to additional phases, if present
if 'phases' in kw: if 'phases' in kw:
phases = {}
for fork in kw['phases']: for fork in kw['phases']:
if is_post_fork(fork, spec.fork): phases[fork], output = \
kw['phases'][fork], output_config = \
spec_with_config_overrides(_get_copy_of_spec(kw['phases'][fork]), config_overrides) spec_with_config_overrides(_get_copy_of_spec(kw['phases'][fork]), config_overrides)
if emit and emitted_fork == fork: if emitted_fork == fork:
yield 'config', 'cfg', output_config output_config = output
kw['phases'] = phases
# Run the function # Run the function
out = fn(*args, spec=spec, **kw) out = fn(*args, spec=spec, **kw)
# Emit requested spec (with overrides)
if emit:
yield 'config', 'cfg', output_config
# If it's not returning None like a normal test function, # If it's not returning None like a normal test function,
# it's generating things, and we need to complete it before setting back the config. # it's generating things, and we need to complete it before setting back the config.
if out is not None: if out is not None: