From 2536bf991041de841b52901073dcaa5b1577a696 Mon Sep 17 00:00:00 2001 From: Julius Busecke Date: Mon, 24 Jun 2024 23:32:16 -0400 Subject: [PATCH] Update Linters (#359) * Update Linters * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update conf.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update conf.py * Update __init__.py * Update whats-new.rst --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 65 +++++++++++++---------------------------- docs/conf.py | 4 +-- docs/whats-new.rst | 9 ++++++ xmip/__init__.py | 14 +++------ xmip/drift_removal.py | 2 +- xmip/postprocessing.py | 4 +-- 6 files changed, 38 insertions(+), 60 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0f4e3b06..dcbafe55 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,45 +1,22 @@ -repos: - -# Ill leave this for later. This will take a while to get up to speed. -# - repo: https://github.com/econchick/interrogate -# rev: 1.3.2 -# hooks: -# - id: interrogate -# exclude: ^(docs|setup.py|tests|xmip/_version.py|xmip/__init__.py) -# args: [--config=pyproject.toml] - -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: trailing-whitespace - exclude: tests/data - - id: check-ast - - id: debug-statements - - id: end-of-file-fixer - - id: check-docstring-first - - id: requirements-txt-fixer - - id: file-contents-sorter - files: requirements-dev.txt - -- repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 - hooks: - - id: flake8 +ci: + autoupdate_schedule: quarterly + autofix_prs: true -- repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - additional_dependencies: [toml] - args: [--project=xmip, --multi-line=3, --lines-after-imports=2, --lines-between-types=1, --trailing-comma, --force-grid-wrap=0, --use-parentheses, --line-width=88] - -- repo: https://github.com/asottile/seed-isort-config - rev: v2.2.0 - hooks: - - id: seed-isort-config - -- repo: https://github.com/psf/black - rev: 24.3.0 - hooks: - - id: black - language_version: python3 +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-added-large-files + - id: check-toml + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: debug-statements + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.5 + hooks: + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format diff --git a/docs/conf.py b/docs/conf.py index 37b0d5bb..8f404be1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,8 +22,8 @@ os.environ["PYTHONPATH"] = str(root) sys.path.insert(0, str(root)) -import xmip # isort:skip -from importlib.metadata import version # isort:skip +import xmip # noqa +from importlib.metadata import version # noqa release = version("xmip") # for example take major/minor/patch diff --git a/docs/whats-new.rst b/docs/whats-new.rst index 0168e682..48fbcb6f 100644 --- a/docs/whats-new.rst +++ b/docs/whats-new.rst @@ -2,6 +2,15 @@ What's New =========== +.. _whats-new.0.8.0: + +v0.8.0 (unreleased) +------------------- + +Internal Changes +~~~~~~~~~~~~~~~~ +- Updated pre-commit linting to use ruff (:pull:`359`). By `Julius Busecke ` + .. _whats-new.0.7.2: v0.7.2 (unreleased) diff --git a/xmip/__init__.py b/xmip/__init__.py index 328591d5..b2a8cd80 100644 --- a/xmip/__init__.py +++ b/xmip/__init__.py @@ -1,13 +1,7 @@ -try: - from importlib.metadata import ( # only works for python 3.8 and upwards - PackageNotFoundError, - version, - ) -except: - from importlib_metadata import ( # works for python <3.8 - PackageNotFoundError, - version, - ) +from importlib.metadata import ( # only works for python 3.8 and upwards + PackageNotFoundError, + version, +) try: __version__ = version("xmip") diff --git a/xmip/drift_removal.py b/xmip/drift_removal.py index c1a919cd..53aa6991 100644 --- a/xmip/drift_removal.py +++ b/xmip/drift_removal.py @@ -185,7 +185,7 @@ def calculate_drift( # Check if the parent member id matches match_attrs = ["source_id", "variant_label"] for ma in match_attrs: - if not ds.attrs[f"parent_{ma}"] in reference.attrs[ma]: + if ds.attrs[f"parent_{ma}"] not in reference.attrs[ma]: raise ValueError( f'`ds_parent` {ma} ({reference.attrs[ma]}) not compatible with `ds` parent_{ma} ({ds.attrs[f"parent_{ma}"]})' ) diff --git a/xmip/postprocessing.py b/xmip/postprocessing.py index 704d7476..94e855db 100644 --- a/xmip/postprocessing.py +++ b/xmip/postprocessing.py @@ -446,9 +446,7 @@ def _interpolate_combine_func( print(gl) source_grid = [ dss for dss in ds_list if dss.attrs["grid_label"] == gl - ][ - 0 - ] # again just take the first one available + ][0] # again just take the first one available regridder_dict[gl] = _clean_regridder( source_grid, target_grid, method, **xesmf_kwargs )