Skip to content

Commit

Permalink
Fix steps_to_run for shared config files
Browse files Browse the repository at this point in the history
With this merge, each task that uses a shared config file used
by a task to be set up has its configure() method called and
then `steps_to_run` is added to the shared config options.  This
prevents a situation where `steps_to_run` is missing when a
task is set up later that overwrites the shared config file.
  • Loading branch information
xylar committed Oct 12, 2023
1 parent df86670 commit 2c6adfd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions polaris/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class PolarisConfigParser(MpasConfigParser):
A list of filepaths within the component's work directory where
symlinks to ``filepath`` will be created
symlinks : set of polaris.Task
A list of tasks that use this config
"""

def __init__(self, filepath=None):
Expand All @@ -40,6 +42,7 @@ def __init__(self, filepath=None):
super().__init__()
self.filepath: Union[str, None] = filepath
self.symlinks = list()
self.tasks = set()

def setup(self):
"""
Expand Down
15 changes: 8 additions & 7 deletions polaris/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,14 @@ def _configure_tasks_and_add_step_configs(tasks, component, initial_configs,
Call the configure() method for each task and add configs to "owned" steps
"""

for task in tasks.values():
task.configure()
task.config.set(section=f'{task.name}',
option='steps_to_run',
value=' '.join(task.steps_to_run),
comment=f'A list of steps to include when running the '
f'{task.name} task')
for config in initial_configs.values():
for task in config.tasks:
task.configure()
task.config.set(section=f'{task.name}',
option='steps_to_run',
value=' '.join(task.steps_to_run),
comment=f'A list of steps to include when running '
f'the {task.name} task')

# add configs to steps after calling task.configure() on all tasks in case
# new steps were added
Expand Down
2 changes: 2 additions & 0 deletions polaris/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self, component, name, subdir=None, indir=None):
self.path = os.path.join(self.component.name, self.subdir)
self.config = PolarisConfigParser()
self.config_filename = ''
self.config.tasks.add(self)

# steps will be added by calling add_step()
self.steps = dict()
Expand Down Expand Up @@ -219,6 +220,7 @@ def set_shared_config(self, config, link=None):
self.component.add_config(config)

self.config = config
config.tasks.add(self)
if link is None:
directory, basename = os.path.split(config.filepath)
if directory != self.subdir:
Expand Down

0 comments on commit 2c6adfd

Please sign in to comment.