From 78fef53a7ca4f48a85c00a12975dfae4d2e91571 Mon Sep 17 00:00:00 2001 From: Althea Denlinger Date: Wed, 2 Oct 2024 11:11:56 -0700 Subject: [PATCH 1/4] Update pre-commit dependencies --- .pre-commit-config.yaml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 177692ed..e5c62ff2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ fail_fast: true repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -13,13 +13,13 @@ repos: # Can run individually with `pre-commit run black --all-files` - repo: https://github.com/psf/black - rev: 22.8.0 + rev: 24.10.0 hooks: - id: black # Can run individually with `pre-commit run isort --all-files` - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort @@ -27,15 +27,20 @@ repos: # Need to use flake8 GitHub mirror due to CentOS git issue with GitLab # https://github.com/pre-commit/pre-commit/issues/1206 - repo: https://github.com/pycqa/flake8 - rev: 5.0.4 + rev: 7.1.1 hooks: - id: flake8 args: ["--config=setup.cfg"] - additional_dependencies: [flake8-isort] + additional_dependencies: [flake8-isort==6.1.1] # Can run individually with `pre-commit run mypy --all-files` - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v1.11.2 hooks: - id: mypy args: ["--config=setup.cfg"] + +# https://pre-commit.ci/#configuration +ci: + autofix_prs: false + autoupdate_schedule: monthly From c209c457aad9090a0083849048829b08927075ad Mon Sep 17 00:00:00 2001 From: Althea Denlinger Date: Wed, 9 Oct 2024 10:27:18 -0700 Subject: [PATCH 2/4] Update pre-commit deps in `conda/dev.yml` --- conda/dev.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/conda/dev.yml b/conda/dev.yml index 565fe235..f5c5df11 100644 --- a/conda/dev.yml +++ b/conda/dev.yml @@ -15,12 +15,12 @@ dependencies: # Developer Tools # ================= # If versions are updated, also update 'rev' in `.pre-commit-config.yaml` - - black=22.8.0 # version from https://anaconda.org/conda-forge/black - - flake8=5.0.4 # version from https://anaconda.org/conda-forge/flake8 + - black=24.10.0 # version from https://anaconda.org/conda-forge/black + - flake8=7.1.1 # version from https://anaconda.org/conda-forge/flake8 # This line also implicitly installs isort - - flake8-isort=4.2.0 # version from https://anaconda.org/conda-forge/flake8-isort - - mypy=0.982 # version from https://anaconda.org/conda-forge/mypy - - pre-commit=2.20.0 # version from https://anaconda.org/conda-forge/pre-commit + - flake8-isort=6.1.1 # version from https://anaconda.org/conda-forge/flake8-isort + - mypy=1.11.2 # version from https://anaconda.org/conda-forge/mypy + - pre-commit=4.0.1 # version from https://anaconda.org/conda-forge/pre-commit - tbump=6.9.0 # Documentation # If versions are updated, also update in `.github/workflows/build_workflow.yml` From 7bd5218c0ed5b58c6f610d1eb9a0d17cc0fc4ae9 Mon Sep 17 00:00:00 2001 From: Althea Denlinger Date: Mon, 14 Oct 2024 09:06:08 -0700 Subject: [PATCH 3/4] Fix `black` formatting errors --- setup.py | 2 +- zppy/e3sm_diags.py | 6 ++-- zppy/mpas_analysis.py | 4 ++- zppy/templates/coupled_global.py | 49 ++++++++++++++++++++------------ zppy/utils.py | 3 ++ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/setup.py b/setup.py index 3f5c80c0..44dac4e2 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def package_files(directory, prefixes, extensions): """based on https://stackoverflow.com/a/36693250/7728169""" paths = [] - for (path, directories, filenames) in os.walk(directory): + for path, directories, filenames in os.walk(directory): for filename in filenames: parts = filename.split(".") prefix = parts[0] diff --git a/zppy/e3sm_diags.py b/zppy/e3sm_diags.py index 2ae1607e..1dbb9bbb 100644 --- a/zppy/e3sm_diags.py +++ b/zppy/e3sm_diags.py @@ -200,9 +200,9 @@ def check_and_define_parameters(c: Dict[str, Any]) -> None: if ("tc_analysis" in c["sets"]) and (c["reference_data_path_tc"] == ""): # We have to guess parameters here, # because multiple year sets are defined in a single subtask. - c[ - "reference_data_path_tc" - ] = f"{reference_data_path}/atm/tc-analysis_{c['ref_year1']}_{c['ref_year2']}" + c["reference_data_path_tc"] = ( + f"{reference_data_path}/atm/tc-analysis_{c['ref_year1']}_{c['ref_year2']}" + ) if set(["enso_diags", "qbo", "area_mean_time_series"]) & set(c["sets"]): define_or_guess2( c, diff --git a/zppy/mpas_analysis.py b/zppy/mpas_analysis.py index 003d2ded..17cbe507 100644 --- a/zppy/mpas_analysis.py +++ b/zppy/mpas_analysis.py @@ -60,7 +60,9 @@ def mpas_analysis(config: ConfigObj, script_dir: str, existing_bundles, job_ids_ if ("last_year" in c.keys()) and (c["enso_year2"] > c["last_year"]): continue # Skip this year set c["scriptDir"] = script_dir - prefix_suffix: str = f"_ts_{c['ts_year1']:04d}-{c['ts_year2']:04d}_climo_{c['climo_year1']:04d}-{c['climo_year2']:04d}" + prefix_suffix: str = ( + f"_ts_{c['ts_year1']:04d}-{c['ts_year2']:04d}_climo_{c['climo_year1']:04d}-{c['climo_year2']:04d}" + ) prefix: str if c["subsection"]: prefix = f"mpas_analysis_{c['subsection']}{prefix_suffix}" diff --git a/zppy/templates/coupled_global.py b/zppy/templates/coupled_global.py index 762e7724..9fc41401 100644 --- a/zppy/templates/coupled_global.py +++ b/zppy/templates/coupled_global.py @@ -156,6 +156,7 @@ def get_ylim(standard_range, extreme_values): # ----------------------------------------------------------------------------- # Plotting functions + # 1 def plot_net_toa_flux_restom(ax, xlim, exps, rgn): print("Plot 1: plot_net_toa_flux_restom") @@ -748,24 +749,36 @@ def run(parameters, rgn): # noqa: C901 use_ocn = plots_ocn or (not atmosphere_only and has_original_ocn_plots) exps: List[Dict[str, Any]] = [ { - "atmos": f"{case_dir}/post/atm/glb/ts/monthly/{ts_num_years}yr/" - if use_atmos - else None, - "ice": f"{case_dir}/post/ice/glb/ts/monthly/{ts_num_years}yr/" - if plots_ice - else None, - "land": f"{case_dir}/post/lnd/glb/ts/monthly/{ts_num_years}yr/" - if plots_lnd - else None, - "ocean": f"{case_dir}/post/ocn/glb/ts/monthly/{ts_num_years}yr/" - if use_ocn - else None, - "moc": f"{case_dir}/post/ocn/glb/ts/monthly/{ts_num_years}yr/" - if use_ocn - else None, - "vol": f"{case_dir}/post/ocn/glb/ts/monthly/{ts_num_years}yr/" - if use_ocn - else None, + "atmos": ( + f"{case_dir}/post/atm/glb/ts/monthly/{ts_num_years}yr/" + if use_atmos + else None + ), + "ice": ( + f"{case_dir}/post/ice/glb/ts/monthly/{ts_num_years}yr/" + if plots_ice + else None + ), + "land": ( + f"{case_dir}/post/lnd/glb/ts/monthly/{ts_num_years}yr/" + if plots_lnd + else None + ), + "ocean": ( + f"{case_dir}/post/ocn/glb/ts/monthly/{ts_num_years}yr/" + if use_ocn + else None + ), + "moc": ( + f"{case_dir}/post/ocn/glb/ts/monthly/{ts_num_years}yr/" + if use_ocn + else None + ), + "vol": ( + f"{case_dir}/post/ocn/glb/ts/monthly/{ts_num_years}yr/" + if use_ocn + else None + ), "name": experiment_name, "yoffset": 0.0, "yr": ([year1, year2],), diff --git a/zppy/utils.py b/zppy/utils.py index 7b8b204a..6dd78fc1 100644 --- a/zppy/utils.py +++ b/zppy/utils.py @@ -73,6 +73,7 @@ def get_url_message(c: Dict[str, Any], task: str) -> str: # Beginning steps ############################################################# + # TODO: determine return type def initialize_template(config: ConfigObj, template_name: str) -> Tuple[Any, Any]: # --- Initialize jinja2 template engine --- @@ -87,6 +88,7 @@ def initialize_template(config: ConfigObj, template_name: str) -> Tuple[Any, Any # TODO: type aliases require python 3.12 or higher # type TaskDict = Dict[str, Any] + # Process specified section and its sub-sections to build the list of tasks. # If the section includes sub-sections, one task will be created for each # sub-section and no task will be created for the main section. @@ -272,6 +274,7 @@ def get_years(years_input) -> List[Tuple[int, int]]: # `for s in year_sets` steps ################################################## + # This returns a value def define_or_guess( c: Dict[str, Any], From 4d0d9857fa5d01fb87c9e27c9864619365004c30 Mon Sep 17 00:00:00 2001 From: Althea Denlinger Date: Mon, 14 Oct 2024 09:11:30 -0700 Subject: [PATCH 4/4] Fix `flake8` programming errors --- tests/test_sections.py | 2 +- zppy/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_sections.py b/tests/test_sections.py index 76266b66..434cfdfb 100644 --- a/tests/test_sections.py +++ b/tests/test_sections.py @@ -21,7 +21,7 @@ def compare(tester, actual, expected): tester.assertEqual(only_in_expected, set()) incorrect_values = [] for key in actual_keys: - if type(actual[key]) == Section: + if isinstance(actual[key], Section): print("Calling `compare` again on {}".format(key)) compare(tester, actual[key], expected[key]) elif actual[key] != expected[key]: diff --git a/zppy/utils.py b/zppy/utils.py index 6dd78fc1..06b27b76 100644 --- a/zppy/utils.py +++ b/zppy/utils.py @@ -32,9 +32,9 @@ class DependencySkipError(RuntimeError): def get_active_status(task: Dict[str, Any]) -> bool: active: Any = task["active"] - if type(active) == bool: + if isinstance(active, bool): return active - elif type(active) == str: + elif isinstance(active, str): active_lower_case: str = active.lower() if active_lower_case == "true": return True @@ -151,7 +151,7 @@ def get_tasks(config: ConfigObj, section_name: str) -> List[Dict[str, Any]]: username = os.environ.get("USER") for c in tasks: for key in c: - if (type(c[key]) == str) and ("$USER" in c[key]): + if (isinstance(c[key], str)) and ("$USER" in c[key]): c[key] = c[key].replace("$USER", username) return tasks @@ -242,7 +242,7 @@ def check_required_parameters( # "year_begin-year_end" def get_years(years_input) -> List[Tuple[int, int]]: years_list: List[str] - if type(years_input) == str: + if isinstance(years_input, str): # This will be the case if years_list is missing a trailing comma years_list = [years_input] else: