Skip to content

Commit

Permalink
Convert legacy archive config to dict in fsops.py. Simplify its parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
blimlim committed Dec 5, 2024
1 parent d110cae commit c111d6b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
3 changes: 2 additions & 1 deletion docs/source/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,11 @@ section for details.
Archiving
---------

``archiving``
``archive``
On completion of a model run, payu moves model output, restart, and log
files from the temporary work area to the experiment archive directory.
The following settings control the steps taken during the archive step:

``enable`` (*Default:* ``True``)
Flag to enable/disable the archive step. If ``False`` all output, restart,
and log files will remain in the work directory, and any collation, post-processing,
Expand Down
11 changes: 1 addition & 10 deletions payu/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,16 +775,7 @@ def archiving(self):
Default to True when archive settings are absent.
"""
archive_config = self.config.get('archive', {})
if isinstance(archive_config, dict):
return archive_config.get('enable', True)

# Backwards compatibility for configs with boolean archive setting
elif isinstance(archive_config, bool):
return archive_config

else:
msg = "Incorrect format for archive settings in config.yaml"
raise RuntimeError(msg)
return archive_config.get('enable', True)

def archive(self, force_prune_restarts=False):
if not self.archiving():
Expand Down
6 changes: 6 additions & 0 deletions payu/fsops.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def read_config(config_fname=None):

config['collate'] = collate_config

# Transform legacy archive config options
archive_config = config.pop('archive', {})
if type(archive_config) is bool:
archive_config = {'enable': archive_config}
config['archive'] = archive_config

# Transform legacy modules config options
modules_config = config.pop('modules', {})
if type(modules_config) is list:
Expand Down
15 changes: 3 additions & 12 deletions payu/models/cice.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,10 @@ def archive(self, **kwargs):
else:
shutil.rmtree(self.work_input_path)

if self.compression_enabled():
self.compress_log_files()

def compression_enabled(self):
"""
Determine whether to run log compression based on config.yaml settings.
Default to True when 'compress_logs' setting is absent.
"""
archive_config = self.expt.config.get('archive', {})
if isinstance(archive_config, dict):
return archive_config.get('compress_logs', True)
else:
return True
compressing_logs = archive_config.get('compress_logs', True)
if compressing_logs:
self.compress_log_files()

def get_log_files(self):
"""
Expand Down
1 change: 1 addition & 0 deletions test/test_payu.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def test_read_config():
assert(config.pop('collate') == {})
assert(config.pop('control_path') == os.getcwd())
assert(config.pop('modules') == {})
assert(config.pop('archive') == {})
assert(config == {})

os.remove(config_tmp)
Expand Down

0 comments on commit c111d6b

Please sign in to comment.