Skip to content

Commit

Permalink
Merge pull request #138 from xylar/fix-config-filepath
Browse files Browse the repository at this point in the history
Set config.filepath after loading new config options
  • Loading branch information
xylar authored Oct 17, 2023
2 parents 519e63c + 04227f1 commit ac187a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
16 changes: 13 additions & 3 deletions polaris/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,32 @@ def unpickle_suite(suite_name):
return test_suite


def setup_config(config_filename):
def setup_config(base_work_dir, component_name, config_filepath):
"""
Set up the config object from the config file
Parameters
----------
config_filename : str
The config filename
base_work_dir : str
The base work directory where suites and tasks are being set up
component_name : str
The component the config belongs to
config_filepath : str
The path to the config file within the component's work directory
Returns
-------
config : polaris.config.PolarisConfigParser
The config object
"""
config_filename = os.path.join(base_work_dir, component_name,
config_filepath)
config = PolarisConfigParser()
config.add_from_file(config_filename)
config.filepath = config_filepath
return config


Expand Down
28 changes: 12 additions & 16 deletions polaris/run/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def run_tasks(suite_name, quiet=False, is_task=False, steps_to_run=None,
# get the config file for the first task in the suite
task = next(iter(suite['tasks'].values()))
component = task.component
config_filename = \
f'{task.base_work_dir}/{component.name}/{component.name}.cfg'
common_config = setup_config(config_filename)
common_config = setup_config(task.base_work_dir,
component.name,
f'{component.name}.cfg')
available_resources = get_available_parallel_resources(common_config)

# start logging to stdout/stderr
Expand Down Expand Up @@ -140,10 +140,9 @@ def run_single_step(step_is_subprocess=False, quiet=False):
if step_is_subprocess:
step.run_as_subprocess = False

config_filename = os.path.join(step.base_work_dir,
step.component.name,
step.config.filepath)
config = setup_config(config_filename)
config = setup_config(step.base_work_dir,
step.component.name,
step.config.filepath)
task.config = config
available_resources = get_available_parallel_resources(config)
set_cores_per_node(task.config, available_resources['cores_per_node'])
Expand Down Expand Up @@ -302,10 +301,9 @@ def _log_and_run_task(task, stdout_logger, task_logger, quiet,

os.chdir(task.work_dir)

config_filename = os.path.join(task.base_work_dir,
task.component.name,
task.config.filepath)
config = setup_config(config_filename)
config = setup_config(task.base_work_dir,
task.component.name,
task.config.filepath)
task.config = config
set_cores_per_node(task.config,
available_resources['cores_per_node'])
Expand Down Expand Up @@ -389,11 +387,9 @@ def _run_task(task, available_resources):

step_start = time.time()

config_filename = os.path.join(step.base_work_dir,
step.component.name,
step.config.filepath)

step.config = setup_config(config_filename)
step.config = setup_config(step.base_work_dir,
step.component.name,
step.config.filepath)
if task.log_filename is not None:
step_log_filename = task.log_filename
else:
Expand Down

0 comments on commit ac187a8

Please sign in to comment.