Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a check for duplicate analysis tasks and subtasks #908

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions mpas_analysis/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,52 @@ def build_analysis_list(config, controlConfig):
config=config, mpasClimatologyTask=seaIceClimatolgyTask,
hemisphere='SH', controlConfig=controlConfig))

check_for_duplicate_names(analyses)

return analyses


def check_for_duplicate_names(analyses):
"""
Check for duplicate taskName and subtaskName in the list of analysis tasks
and their subtasks

Parameters
----------
analyses : list of mpas_analysis.shared.AnalysisTask
A list of all analysis tasks
"""
all_task_names = []
errors = []
for analysis in analyses:
mainTaskName = analysis.taskName
assert(analysis.subtaskName is None)
fullName = (mainTaskName, None)
if fullName in all_task_names:
errors.append(
f'A task named {mainTaskName} has been added more than once')
all_task_names.append(fullName)
for subtask in analysis.subtasks:
taskName = subtask.taskName
subtaskName = subtask.subtaskName
if taskName != mainTaskName:
errors.append(
f'A subtask named {taskName}: {subtaskName} has a '
f'different task name than its parent task: \n'
f' {mainTaskName}')
fullName = (taskName, subtaskName)
if fullName in all_task_names:
errors.append(
f'A subtask named {taskName}: {subtaskName} has been '
f'added more than once')
all_task_names.append(fullName)

if len(errors) > 0:
all_errors = '\n '.join(errors)
raise ValueError(f'Analysis tasks failed these checks:\n'
f' {all_errors}')


def determine_analyses_to_generate(analyses, verbose):
"""
Build a list of analysis tasks to run based on the 'generate' config
Expand Down
4 changes: 2 additions & 2 deletions mpas_analysis/shared/analysis_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class AnalysisTask(Process):
runAfterTasks : list of ``AnalysisTasks``
tasks that must be complete before this task can run

subtasks : ``OrderedDict`` of ``AnalysisTasks``
Subtasks of this task, with subtask names as keys
subtasks : list of mpas_analysis.shared.AnalysisTask
Subtasks of this task
Comment on lines -79 to +80
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An incorrect docstring I noticed in the process of writing the function above.


xmlFileNames : list of strings
The XML file associated with each plot produced by this analysis, empty
Expand Down