Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

notify_on normalized #58

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions autosubmitconfigparser/config/configcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,20 @@ def _normalize_wrappers_section(data_fixed: dict) -> None:
data_fixed["WRAPPERS"][wrapper]["JOBS_IN_WRAPPER"] = jobs_in_wrapper.upper()
data_fixed["WRAPPERS"][wrapper]["TYPE"] = str(wrapper_data.get("TYPE", "vertical")).lower()

@staticmethod
def _normalize_notify_on(data_fixed: dict, job_section) -> None:
"""
Normalize the NOTIFY_ON section to a consistent format.
"""
if "NOTIFY_ON" in data_fixed["JOBS"][job_section]:
if type(data_fixed["JOBS"][job_section]["NOTIFY_ON"]) is str:
if "," in data_fixed["JOBS"][job_section]["NOTIFY_ON"]:
data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"].split(",")]
else:
data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"].split()]
else:
data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"]]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if "NOTIFY_ON" in data_fixed["JOBS"][job_section]:
if type(data_fixed["JOBS"][job_section]["NOTIFY_ON"]) is str:
if "," in data_fixed["JOBS"][job_section]["NOTIFY_ON"]:
data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"].split(",")]
else:
data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"].split()]
else:
data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"]]
notify_on = data_fixed["JOBS"][job_section].get("NOTIFY_ON", "")
if notify_on:
if type(notify_on) is str:
if "," in notify_on:
notify_on = notify_on.split(",")
else:
notify_on = notify_on.split()
data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in notify_on]

I think the test should pass with this one too. The previous code has 166 lines of bytecode on godbolt, while the alternative has 78 lines. But I think it doesn't matter unless this function is called a lot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks added! Merging...


def _normalize_jobs_section(self, data_fixed: dict, must_exists: bool ) -> None:
for job, job_data in data_fixed.get("JOBS", {}).items():
if "DEPENDENCIES" in job_data or must_exists:
Expand All @@ -575,6 +589,8 @@ def _normalize_jobs_section(self, data_fixed: dict, must_exists: bool ) -> None:
if "ADDITIONAL_FILES" not in data_fixed["JOBS"][job] and must_exists:
data_fixed["JOBS"][job]["ADDITIONAL_FILES"] = []

self._normalize_notify_on(data_fixed, job)

@staticmethod
def _normalize_dependencies(dependencies: Union[str, dict]) -> dict:
"""
Expand Down
88 changes: 88 additions & 0 deletions test/unit/test_normalize_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,94 @@
True,
id="dependencies_status"
),
pytest.param(
{
"JOBS": {
"job1": {
"FILE": "FILE1",
"NOTIFY_ON": ["running", "COmpLETED"]
}
}
},
{
'JOBS': {
'JOB1': {
'FILE': 'FILE1',
'ADDITIONAL_FILES': [],
'DEPENDENCIES': {},
'NOTIFY_ON': ['RUNNING', 'COMPLETED'],
},
}
},
True,
id="notify_on_list"
),
pytest.param(
{
"JOBS": {
"job1": {
"FILE": "FILE1",
"NOTIFY_ON": "running, COmpLETED"
}
}
},
{
'JOBS': {
'JOB1': {
'FILE': 'FILE1',
'ADDITIONAL_FILES': [],
'DEPENDENCIES': {},
'NOTIFY_ON': ['RUNNING', 'COMPLETED'],
},
}
},
True,
id="notify_on_string_with_,"
),
pytest.param(
{
"JOBS": {
"job1": {
"FILE": "FILE1",
"NOTIFY_ON": "running COmpLETED"
}
}
},
{
'JOBS': {
'JOB1': {
'FILE': 'FILE1',
'ADDITIONAL_FILES': [],
'DEPENDENCIES': {},
'NOTIFY_ON': ['RUNNING', 'COMPLETED'],
},
}
},
True,
id="notify_on_string_without_,"
),
pytest.param(
{
"JOBS": {
"job1": {
"FILE": "FILE1",
"NOTIFY_ON": "running"
}
}
},
{
'JOBS': {
'JOB1': {
'FILE': 'FILE1',
'ADDITIONAL_FILES': [],
'DEPENDENCIES': {},
'NOTIFY_ON': ['RUNNING'],
},
}
},
True,
id="notify_on_string_single"
),
])
def test_normalize_variables(autosubmit_config, data, expected_data, must_exists):
as_conf = autosubmit_config(expid='t000', experiment_data=data)
Expand Down
Loading