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

Update pre-commit dependencies #627

Merged
merged 4 commits into from
Oct 14, 2024
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
17 changes: 11 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,29 +13,34 @@ 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

# Can run individually with `pre-commit run flake8 --all-files`
# 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
Comment on lines +43 to +46
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll note that we don't really know if this will do anything useful. It is discussed on the web as a potential equivalent of dependabot for pre-commit but I suspect we may need to do something more than add this chunk of code to get it to actually run.

10 changes: 5 additions & 5 deletions conda/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
6 changes: 3 additions & 3 deletions zppy/e3sm_diags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion zppy/mpas_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
49 changes: 31 additions & 18 deletions zppy/templates/coupled_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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],),
Expand Down
11 changes: 7 additions & 4 deletions zppy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ---
Expand All @@ -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.
Expand Down Expand Up @@ -149,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
Expand Down Expand Up @@ -240,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:
Expand Down Expand Up @@ -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],
Expand Down
Loading