diff --git a/.ruff.toml b/.ruff.toml deleted file mode 100644 index a976ca9f..00000000 --- a/.ruff.toml +++ /dev/null @@ -1,207 +0,0 @@ -extend = "pyproject.toml" - -lint.ignore = [ - # pydocstyle (D) - # https://docs.astral.sh/ruff/rules/#pydocstyle-d - "D100", # Missing docstring in public module - "D101", # Missing docstring in public class - "D102", # Missing docstring in public method - "D103", # Missing docstring in public function - "D105", # Missing docstring in magic method - "D200", # One-line docstring should fit on one line - "D202", # No blank lines allowed after function docstring - "D205", # 1 blank line required between summary line and description - "D212", # Multi-line docstring summary should start at the second line - "D300", # Use triple double quotes """ - "D301", # Use r""" if any backslashes in a docstring - "D400", # First line should end with a period - "D401", # First line of docstring should be in imperative mood - "D406", # Section name should end with a newline - "D407", # Missing dashed underline after section - - # isort (I) - # https://docs.astral.sh/ruff/rules/#isort-i - "I001", # Import block is un-sorted or un-formatted - - # Numpy-specific rules (NPY) - # https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy - "NPY002", - - # flake8-builtins (A) - # https://docs.astral.sh/ruff/rules/#flake8-builtins-a - "A001", - "A002", - - # flake8-annotations (ANN) - "ANN001", - "ANN002", - "ANN003", - "ANN101", - "ANN102", - "ANN201", - "ANN202", - "ANN204", - "ANN205", - "ANN206", - - # flake8-unused-arguments (ARG) - # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg - "ARG001", - "ARG002", - "ARG005", - - # flake8-bugbear (B) - # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b - "B007", - "B018", - "B028", - "B904", - - # flake8-blind-except (BLE) - # https://docs.astral.sh/ruff/rules/#flake8-blind-except-ble - "BLE001", - - # flake8-comprehensions (C4) - # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 - "C408", - "C901", - - # flake8-datetimez (DTZ) - # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz - "DTZ001", - "DTZ006", - - # flake8-errmsg (EM) - "EM101", - "EM102", - "EM103", - - # eradicate (ERA) - # https://docs.astral.sh/ruff/rules/#eradicate-era - "ERA001", - - # flake8-boolean-trap (FBT) - # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt - "FBT001", - "FBT002", - "FBT003", - - # flake8-fixme (FIX) - # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix - "FIX002", - "FIX003", - - # pep8-naming (N) - # https://docs.astral.sh/ruff/rules/#pep8-naming-n - "N801", - "N802", - "N803", - "N806", - "N999", - - # Perflint (PERF) - # https://docs.astral.sh/ruff/rules/#perflint-perf - "PERF203", - "PERF401", - - # Refactor (R) - # https://docs.astral.sh/ruff/rules/#refactor-r - "PLR0402", - "PLR0912", - "PLR0913", - "PLR0915", - "PLR1714", - "PLR1722", - "PLR2004", - "PLR5501", - - # Warning (W) - # https://docs.astral.sh/ruff/rules/#warning-w - "PLW0602", - "PLW2901", - - # flake8-pytest-style (PT) - "PT009", - "PT027", - - # flake8-use-pathlib (PTH) - # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth - "PTH100", - "PTH107", - "PTH110", - "PTH111", - "PTH112", - "PTH113", - "PTH118", - "PTH120", - "PTH122", - "PTH123", - - # flake8-pyi (PYI) - # https://docs.astral.sh/ruff/rules/#flake8-pyi-pyi - "PYI024", - - # flake8-return (RET) - # https://docs.astral.sh/ruff/rules/#flake8-return-ret - "RET503", - "RET504", - "RET505", - "RET506", - - # flake8-raise (RSE) - # https://docs.astral.sh/ruff/rules/#flake8-raise-rse - "RSE102", - - # Ruff-specific rules (RUF) - # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf - "RUF005", - "RUF012", - "RUF015", - - # flake8-bandit (S) - # https://docs.astral.sh/ruff/rules/#flake8-bandit-s - "S101", - "S110", - "S603", - "S607", - - # flake8-simplify (SIM) - # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim - "SIM102", - "SIM108", - "SIM115", - "SIM117", - "SIM118", - - # flake8-self (SLF) - # https://docs.astral.sh/ruff/rules/#flake8-self-slf - "SLF001", - - # flake8-print (T20) - # https://docs.astral.sh/ruff/rules/#flake8-print-t20 - "T201", - - # flake8-todos (TD) - # https://docs.astral.sh/ruff/rules/#flake8-todos-td - "TD001", - "TD002", - "TD003", - "TD004", - "TD005", - "TD006", - - # tryceratops (TRY) - # https://docs.astral.sh/ruff/rules/#tryceratops-try - "TRY003", - "TRY004", - "TRY301", - - # pyupgrade (UP) - # https://docs.astral.sh/ruff/rules/#pyupgrade-up - "UP008", - "UP009", - "UP018", - "UP027", - "UP031", - "UP032", -] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d663a8b4..bdb2a577 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,5 @@ # See https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html +# See https://github.com/SciTools/.github/wiki/Linting for common linter rules [build-system] # Defined by PEP 518 @@ -179,7 +180,8 @@ preview = false [tool.ruff.lint] ignore = [ - # NOTE: Non-permanent exclusions should be added to the ".ruff.toml" file. + # The following ruff checks are intended to be *permanently* ignored (by design). + # NOTE: *temporary* ignores are listed separately, below. # flake8-commas (COM) # https://docs.astral.sh/ruff/rules/#flake8-commas-com @@ -190,14 +192,222 @@ ignore = [ # https://docs.astral.sh/ruff/rules/single-line-implicit-string-concatenation/ # NOTE: This rule may cause conflicts when used with "ruff format". "ISC001", # Implicitly concatenate string literals on one line. + + # ============================================== + # From here on, we list the *temporary* check disables + # TODO: eventually, remove all these by either + # 1. fixing all code + # 2. adding per-occurence ignores (#qa comments) where needed + # 3. promote the check to the "permanent disables" list above + + # flake8-builtins (A) + # https://docs.astral.sh/ruff/rules/#flake8-builtins-a + "A001", + "A002", + + # flake8-annotations (ANN) + "ANN001", + "ANN002", + "ANN003", + "ANN101", + "ANN102", + "ANN201", + "ANN202", + "ANN204", + "ANN205", + + # flake8-unused-arguments (ARG) + # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg + "ARG001", + "ARG002", + "ARG005", + + # flake8-bugbear (B) + # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B007", + "B018", + "B028", + "B904", + + # flake8-blind-except (BLE) + # https://docs.astral.sh/ruff/rules/#flake8-blind-except-ble + "BLE001", + + # flake8-comprehensions (C4) + # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 + "C408", + "C901", + + # pydocstyle (D) + # https://docs.astral.sh/ruff/rules/#pydocstyle-d + "D100", # Missing docstring in public module + "D101", # Missing docstring in public class + "D102", # Missing docstring in public method + "D103", # Missing docstring in public function + "D105", # Missing docstring in magic method + "D200", # One-line docstring should fit on one line + "D202", # No blank lines allowed after function docstring + "D205", # 1 blank line required between summary line and description + "D212", # Multi-line docstring summary should start at the second line + "D300", # Use triple double quotes """ + "D301", # Use r""" if any backslashes in a docstring + "D400", # First line should end with a period + "D401", # First line of docstring should be in imperative mood + "D406", # Section name should end with a newline + "D407", # Missing dashed underline after section + + # flake8-datetimez (DTZ) + # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz + "DTZ001", + "DTZ006", + + # flake8-errmsg (EM) + "EM101", + "EM102", + "EM103", + + # eradicate (ERA) + # https://docs.astral.sh/ruff/rules/#eradicate-era + "ERA001", + + # flake8-boolean-trap (FBT) + # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt + "FBT001", + "FBT002", + "FBT003", + + # flake8-fixme (FIX) + # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix + "FIX002", + "FIX003", + + # isort (I) + # https://docs.astral.sh/ruff/rules/#isort-i + "I001", # Import block is un-sorted or un-formatted + + # pep8-naming (N) + # https://docs.astral.sh/ruff/rules/#pep8-naming-n + "N801", + "N802", + "N803", + "N806", + "N999", + + # Numpy-specific rules (NPY) + # https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy + "NPY002", + + # Perflint (PERF) + # https://docs.astral.sh/ruff/rules/#perflint-perf + "PERF203", + "PERF401", + + # Refactor (R) + # https://docs.astral.sh/ruff/rules/#refactor-r + "PLR0402", + "PLR0912", + "PLR0913", + "PLR0915", + "PLR1714", + "PLR2004", + "PLR5501", + + # Warning (W) + # https://docs.astral.sh/ruff/rules/#warning-w + "PLW0602", + "PLW2901", + + # flake8-pytest-style (PT) + "PT009", + "PT027", + + # flake8-use-pathlib (PTH) + # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth + "PTH100", + "PTH107", + "PTH110", + "PTH111", + "PTH112", + "PTH113", + "PTH118", + "PTH120", + "PTH122", + "PTH123", + + # flake8-pyi (PYI) + # https://docs.astral.sh/ruff/rules/#flake8-pyi-pyi + "PYI024", + + # flake8-return (RET) + # https://docs.astral.sh/ruff/rules/#flake8-return-ret + "RET503", + "RET504", + "RET505", + "RET506", + + # flake8-raise (RSE) + # https://docs.astral.sh/ruff/rules/#flake8-raise-rse + "RSE102", + + # Ruff-specific rules (RUF) + # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf + "RUF005", + "RUF012", + "RUF015", + + # flake8-bandit (S) + # https://docs.astral.sh/ruff/rules/#flake8-bandit-s + "S101", + "S110", + "S603", + "S607", + + # flake8-simplify (SIM) + # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim + "SIM102", + "SIM108", + "SIM115", + "SIM117", + "SIM118", + + # flake8-self (SLF) + # https://docs.astral.sh/ruff/rules/#flake8-self-slf + "SLF001", + + # flake8-print (T20) + # https://docs.astral.sh/ruff/rules/#flake8-print-t20 + "T201", + + # flake8-todos (TD) + # https://docs.astral.sh/ruff/rules/#flake8-todos-td + "TD001", + "TD002", + "TD003", + "TD004", + "TD005", + "TD006", + + # tryceratops (TRY) + # https://docs.astral.sh/ruff/rules/#tryceratops-try + "TRY003", + "TRY004", + "TRY301", + + # pyupgrade (UP) + # https://docs.astral.sh/ruff/rules/#pyupgrade-up + "UP009", + "UP018", + "UP027", + "UP031", + "UP032", ] preview = false select = [ "ALL", - # pydocstyle (D) - # https://docs.astral.sh/ruff/rules/multi-line-summary-first-line/ - "D212", # Multi-line docstring summary should start at the first line + # Note: the above "all" disables conflicting rules, if you want that + # rule it needs to be explicitly enabled below: + "D212", # conflicts with D213 : this one is our choice, so enforce it ] [tool.ruff.lint.isort] diff --git a/src/iris_grib/__init__.py b/src/iris_grib/__init__.py index 2304d984..6bd0c9d0 100644 --- a/src/iris_grib/__init__.py +++ b/src/iris_grib/__init__.py @@ -2,8 +2,7 @@ # # This file is part of iris-grib and is released under the BSD license. # See LICENSE in the root of the repository for full licensing details. -""" -Conversion of cubes to/from GRIB. +"""Conversion of cubes to/from GRIB. See: `ECMWF GRIB API `_. @@ -155,8 +154,7 @@ def __setstate__(self, state): # Utility routines for the use of dask 'meta' in wrapping proxies def _aslazydata_has_meta(): - """ - Work out whether 'iris._lazy_data.as_lazy_data' takes a "meta" kwarg. + """Work out whether 'iris._lazy_data.as_lazy_data' takes a "meta" kwarg. Up to Iris 3.8.0, "as_lazy_data" did not have a 'meta' keyword, but since https://github.com/SciTools/iris/pull/5801, it now *requires* one, @@ -174,8 +172,7 @@ def _aslazydata_has_meta(): def _make_dask_meta(shape, dtype, is_masked=True): - """ - Construct a dask 'meta' object for use in 'dask.array.from_array'. + """Construct a dask 'meta' object for use in 'dask.array.from_array'. A "meta" array is made from the dtype and shape of the array-like to be wrapped, plus whether it will return masked or unmasked data. @@ -187,8 +184,7 @@ def _make_dask_meta(shape, dtype, is_masked=True): class GribWrapper: - """ - Contains a pygrib object plus some extra keys of our own. + """Contains a pygrib object plus some extra keys of our own. The class :class:`iris_grib.message.GribMessage` provides alternative means of working with GRIB message instances. @@ -691,8 +687,7 @@ def core_data(self): return data def phenomenon_points(self, time_unit): - """ - Return the phenomenon time points. + """Return the phenomenon time points. As offsets from the epoch time reference, measured in appropriate time units. @@ -705,8 +700,7 @@ def phenomenon_points(self, time_unit): ) def phenomenon_bounds(self, time_unit): - """ - Return the phenomenon time bounds. + """Return the phenomenon time bounds. As offsets from the epoch time reference, measured in appropriate time units. @@ -763,8 +757,7 @@ def _load_generate(filename): def load_cubes(filenames, callback=None): - """ - Return an iterator over cubes from the given list of filenames. + """Return an iterator over cubes from the given list of filenames. Args: @@ -787,8 +780,7 @@ def load_cubes(filenames, callback=None): def load_pairs_from_fields(grib_messages): - """ - Convert an GRIB messages into (Cube, Grib message) tuples. + """Convert an GRIB messages into (Cube, Grib message) tuples. Parameters ---------- @@ -851,8 +843,7 @@ def load_pairs_from_fields(grib_messages): def save_grib2(cube, target, append=False): - """ - Save a cube or iterable of cubes to a GRIB2 file. + """Save a cube or iterable of cubes to a GRIB2 file. Args: @@ -876,8 +867,7 @@ def save_grib2(cube, target, append=False): def save_pairs_from_cube(cube): - """ - Convert one or more cubes to (2D cube, GRIB-message-id) pairs. + """Convert one or more cubes to (2D cube, GRIB-message-id) pairs. Produces pairs of 2D cubes and GRIB messages, the result of the 2D cube being processed by the GRIB save rules. @@ -906,8 +896,7 @@ def save_pairs_from_cube(cube): def save_messages(messages, target, append=False): - """ - Save messages to a GRIB2 file. + """Save messages to a GRIB2 file. The messages will be released as part of the save.