Skip to content

Commit

Permalink
Pep8 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
Whyborn committed Nov 12, 2024
1 parent 1218e2a commit b69b26d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 43 deletions.
40 changes: 3 additions & 37 deletions payu/models/staged_cable.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, expt, name, config):

# We want people to be able to use payu during testing, which
# often means additions of new namelists due to new science
# modules. I would like to set
# modules. I would like to set
# optional_config_files = glob.glob("*.nml")
# but this feels like a bit of an abuse of feature.
self.config_files = ['stage_config.yaml']
Expand Down Expand Up @@ -128,39 +128,6 @@ def _prepare_configuration(self):
# Finish handling of single step stage
return cable_stages

def _get_further_restarts(self):
"""Get the restarts from stages further in the past where necessary."""

# Often we take restarts from runs which are not the most recent run as
# inputs for particular science modules, which means we have to extend
# the existing functionality around retrieving restarts.

# We can't supercede the parent get_prior_restart_files, since the
# files returned by said function are prepended by
# self.prior_restart_path, which is not desirable in this instance.

num_completed_stages = len(self.configuration_log['completed_stages'])

for stage_number in reversed(range(num_completed_stages - 1)):
respath = os.path.join(
self.expt.archive_path,
f'restart{stage_number:03d}'
)
for f_name in os.listdir(respath):
if os.path.isfile(os.path.join(respath, f_name)):
f_orig = os.path.join(respath, f_name)
f_link = os.path.join(self.work_init_path_local, f_name)
# Check whether a given link already exists in the
# manifest, so we don't write over a newer version of a
# restart
if f_link not in self.expt.manifest.manifests['restart']:
self.expt.manifest.add_filepath(
'restart',
f_link,
f_orig,
self.copy_restarts
)

def set_model_pathnames(self):
super(StagedCable, self).set_model_pathnames()

Expand Down Expand Up @@ -228,7 +195,7 @@ def _set_current_stage(self):
slot, then copy the configuration log to the working directory."""

self.configuration_log['current_stage'] = \
self.configuration_log['queued_stages'].pop(0)
self.configuration_log['queued_stages'].pop(0)

self._save_configuration_log()
conf_log_p = os.path.join(self.control_path, 'configuration_log.yaml')
Expand Down Expand Up @@ -277,8 +244,7 @@ def _collect_restarts(self):
for f in os.listdir(prior_restart_path):
if f not in generated_restarts:
shutil.copy(os.path.join(prior_restart_path, f),
self.work_restart_path)

self.work_restart_path)

# Move the files in work_path/restart first
for f in os.listdir(self.work_restart_path):
Expand Down
12 changes: 6 additions & 6 deletions test/models/test_staged_cable.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_staged_cable():

# Since we've called the initialiser, we should be able to inspect the
# stages immediately (through the configuration log)
expected_queued_stages = [
expected_q_stages = [
'stage_2',
'stage_3',
'stage_4',
Expand All @@ -141,7 +141,7 @@ def test_staged_cable():
'stage_6',
'stage_6',
'stage_7']
assert model.configuration_log['queued_stages'] == expected_queued_stages
assert model.configuration_log['queued_stages'] == expected_q_stages
assert model.configuration_log['current_stage'] == 'stage_1'

# Now check the namelist
Expand All @@ -165,7 +165,7 @@ def test_staged_cable():

# Archive the stage and make sure the configuration log is correct
model.archive()
expected_comp_stages = ['stage_1']
expected_current_stage = ''
assert model.configuration_log['completed_stages'] == expected_comp_stages
assert model.configuration_log['current_stage'] == expected_current_stage
ex_comp_stages = ['stage_1']
ex_curr_stage = ''
assert model.configuration_log['completed_stages'] == ex_comp_stages
assert model.configuration_log['current_stage'] == ex_curr_stage

0 comments on commit b69b26d

Please sign in to comment.