From e9a3d783b24073ebdcd874b26ca3a5447958aa25 Mon Sep 17 00:00:00 2001 From: Ryan Forsyth Date: Mon, 3 Feb 2025 21:32:26 -0600 Subject: [PATCH] Deprecated parameter alerts --- tests/test_zppy_utils.py | 17 +++++++++++++++++ zppy/global_time_series.py | 8 ++++++++ zppy/tc_analysis.py | 6 ++++++ zppy/ts.py | 7 +++++++ zppy/utils.py | 15 +++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/tests/test_zppy_utils.py b/tests/test_zppy_utils.py index e2d76d5e..1900bd2f 100644 --- a/tests/test_zppy_utils.py +++ b/tests/test_zppy_utils.py @@ -3,9 +3,11 @@ import pytest from zppy.utils import ( + DeprecatedParameterError, ParameterGuessType, ParameterNotProvidedError, add_dependencies, + check_for_deprecated_parameters, check_parameter_defined, check_required_parameters, define_or_guess, @@ -486,6 +488,21 @@ def test_check_parameter_defined(): check_parameter_defined(c, "d") +def test_check_for_deprecated_parameters(): + deprecated_parameters = [ + # Removed in https://github.com/E3SM-Project/zppy/pull/650 + "e3sm_to_cmip_environment_commands", + "ts_fmt", + # Removed in https://github.com/E3SM-Project/zppy/pull/654 + "scratch", + "atmosphere_only", + "plot_names", + ] + c = {"scratch": "xyz", "plot_names": "a,b,c"} + with pytest.raises(DeprecatedParameterError): + check_for_deprecated_parameters(c, deprecated_parameters) + + def test_get_file_names(): bash, settings, status = get_file_names("script_dir", "prefix") assert bash == "script_dir/prefix.bash" diff --git a/zppy/global_time_series.py b/zppy/global_time_series.py index 296f1ead..ab64a3ea 100644 --- a/zppy/global_time_series.py +++ b/zppy/global_time_series.py @@ -5,6 +5,7 @@ from zppy.logger import _setup_custom_logger from zppy.utils import ( add_dependencies, + check_for_deprecated_parameters, check_status, get_file_names, get_tasks, @@ -31,6 +32,13 @@ def global_time_series(config, script_dir, existing_bundles, job_ids_file): # --- Generate and submit global_time_series scripts --- for c in tasks: + deprecated_parameters = [ + # Removed in https://github.com/E3SM-Project/zppy/pull/654 + "atmosphere_only", + "plot_names", + ] + check_for_deprecated_parameters(c, deprecated_parameters) + c["ts_num_years"] = int(c["ts_num_years"]) # Loop over year sets year_sets = get_years(c["years"]) diff --git a/zppy/tc_analysis.py b/zppy/tc_analysis.py index 652989d1..075e3495 100644 --- a/zppy/tc_analysis.py +++ b/zppy/tc_analysis.py @@ -4,6 +4,7 @@ from zppy.bundle import handle_bundles from zppy.utils import ( + check_for_deprecated_parameters, check_status, get_file_names, get_tasks, @@ -27,6 +28,11 @@ def tc_analysis(config: ConfigObj, script_dir: str, existing_bundles, job_ids_fi # --- Generate and submit scripts --- for c in tasks: + deprecated_parameters = [ + # Removed in https://github.com/E3SM-Project/zppy/pull/654 + "scratch", + ] + check_for_deprecated_parameters(c, deprecated_parameters) dependencies: List[str] = [] diff --git a/zppy/ts.py b/zppy/ts.py index b9976057..d58371cb 100644 --- a/zppy/ts.py +++ b/zppy/ts.py @@ -5,6 +5,7 @@ from zppy.bundle import handle_bundles from zppy.utils import ( ParameterGuessType, + check_for_deprecated_parameters, check_status, define_or_guess, get_file_names, @@ -32,6 +33,12 @@ def ts(config: ConfigObj, script_dir: str, existing_bundles, job_ids_file): # --- Generate and submit ts scripts --- for c in tasks: + deprecated_parameters = [ + # Removed in https://github.com/E3SM-Project/zppy/pull/650 + "e3sm_to_cmip_environment_commands", + "ts_fmt", + ] + check_for_deprecated_parameters(c, deprecated_parameters) set_mapping_file(c) set_grid(c) set_component_and_prc_typ(c) diff --git a/zppy/utils.py b/zppy/utils.py index 8b5fb51b..416c91e9 100644 --- a/zppy/utils.py +++ b/zppy/utils.py @@ -31,6 +31,10 @@ class DependencySkipError(RuntimeError): pass +class DeprecatedParameterError(RuntimeError): + pass + + # Utitlities for this file #################################################### @@ -323,6 +327,17 @@ def check_parameter_defined(c: Dict[str, Any], relevant_parameter: str) -> None: raise ParameterNotProvidedError(relevant_parameter) +def check_for_deprecated_parameters( + c: Dict[str, Any], deprecated_parameters: List[str] +) -> None: + present_parameters = [] + for parameter in deprecated_parameters: + if parameter in c.keys(): + present_parameters.append(parameter) + if present_parameters: + raise DeprecatedParameterError(present_parameters) + + def get_file_names(script_dir: str, prefix: str): return tuple( [