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

👁 TEMPLATE DEVIATIONS: synced file(s) with SciTools/.github #34

Merged
merged 2 commits into from
Jun 28, 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
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ updates:
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
groups:
dependencies:
patterns:
- "*"
labels:
- "new: pull request"
- "bot"
136 changes: 94 additions & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,105 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# See https://pre-commit.ci/#configuration
# See https://github.com/scientific-python/cookie#sp-repo-review

ci:
autofix_prs: false
autoupdate_commit_msg: "chore: update pre-commit hooks"


# Alphabetised, for lack of a better order.
files: |
(?x)(
benchmarks\/.+\.py|
docs\/.+\.py|
lib\/.+\.py|
noxfile\.py|
pyproject\.toml|
setup\.py|
src\/.+\.py
)
minimum_pre_commit_version: 1.21.0

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0"
hooks:
# Prevent giant files from being committed.
- id: check-added-large-files
# Check whether files parse as valid Python.
- id: check-ast
# Check for file name conflicts on case-insensitive file-systems.
- id: check-case-conflict
# Check for files that contain merge conflict strings.
- id: check-merge-conflict
# Check for debugger imports and py37+ `breakpoint()` calls in Python source.
- id: debug-statements
# Check TOML file syntax.
- id: check-toml
# Check YAML file syntax.
- id: check-yaml
# Makes sure files end in a newline and only a newline
- id: end-of-file-fixer
exclude: nae.20100104-06_0001_0001.pp
# Replaces or checks mixed line ending
- id: mixed-line-ending
exclude: nae.20100104-06_0001_0001.pp
# Don't commit to main branch.
#- id: no-commit-to-branch
# Trims trailing whitespace
- id: trailing-whitespace
exclude: nae.20100104-06_0001_0001.pp

- repo: https://github.com/codespell-project/codespell
rev: "v2.3.0"
hooks:
- id: codespell
types_or: [python, markdown]
additional_dependencies: [tomli]

- repo: https://github.com/aio-libs/sort-all
rev: "v1.2.0"
hooks:
- id: sort-all
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
# Prevent giant files from being committed.
- id: check-added-large-files
# Check whether files parse as valid Python.
- id: check-ast
# Check for file name conflicts on case-insensitive filesystems.
- id: check-case-conflict
# Check for files that contain merge conflict strings.
- id: check-merge-conflict
# Check for debugger imports and py37+ `breakpoint()` calls in Python source.
- id: debug-statements
# Check TOML file syntax.
- id: check-toml
# Check YAML file syntax.
- id: check-yaml
# Makes sure files end in a newline and only a newline.
# Duplicates Ruff W292 but also works on non-Python files.
- id: end-of-file-fixer
# Replaces or checks mixed line ending.
- id: mixed-line-ending
# Don't commit to main branch.
- id: no-commit-to-branch
# Trims trailing whitespace.
# Duplicates Ruff W291 but also works on non-Python files.
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.4"
hooks:
- id: ruff
types: [file, python]
args: [--fix, --show-fixes]
- id: ruff-format
types: [file, python]

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
- id: codespell
types_or: [asciidoc, python, markdown, rst]
additional_dependencies: [tomli]

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
types: [file, rst]

- repo: https://github.com/abravalheri/validate-pyproject
- repo: https://github.com/aio-libs/sort-all
rev: v1.2.0
hooks:
- id: sort-all
types: [file, python]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0'
hooks:
- id: mypy
exclude: 'src\/mo_pack\/tests'

- repo: https://github.com/abravalheri/validate-pyproject
# More exhaustive than Ruff RUF200.
rev: "v0.18"
hooks:
- id: validate-pyproject
- id: validate-pyproject

- repo: https://github.com/scientific-python/cookie
rev: 2024.04.23
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
args: ["--show=errskip"]

- repo: https://github.com/numpy/numpydoc
rev: v1.7.0
hooks:
- id: numpydoc-validation
types: [file, python]
exclude: 'src\/mo_pack\/tests'
119 changes: 117 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ requires = [
"oldest-supported-numpy",
"setuptools>=64",
"setuptools_scm[toml]>=8",
"wheel",
]
# defined by PEP-517
build-backend = "setuptools.build_meta"
Expand Down Expand Up @@ -52,9 +51,12 @@ ignore = [


[tool.pytest.ini_options]
addopts = ["-ra"]
addopts = ["-ra", "--strict-config", "--strict-markers"]
filterwarnings = ["error"]
log_cli_level = "INFO"
minversion = "6.0"
testpaths = "src/mo_pack"
xfail_strict = true


[tool.setuptools]
Expand All @@ -79,3 +81,116 @@ mo_pack = ["tests/test_data/*.pp"]
write_to = "src/mo_pack/_version.py"
local_scheme = "dirty-tag"
version_scheme = "release-branch-semver"


[tool.numpydoc_validation]
checks = [
"all", # Enable all numpydoc validation rules, apart from the following:

# -> Docstring text (summary) should start in the line immediately
# after the opening quotes (not in the same line, or leaving a
# blank line in between)
"GL01", # Permit summary line on same line as docstring opening quotes.

# -> Closing quotes should be placed in the line after the last text
# in the docstring (do not close the quotes in the same line as
# the text, or leave a blank line between the last text and the
# quotes)
"GL02", # Permit a blank line before docstring closing quotes.

# -> Double line break found; please use only one blank line to
# separate sections or paragraphs, and do not leave blank lines
# at the end of docstrings
"GL03", # Ignoring.

# -> See Also section not found
"SA01", # Not all docstrings require a "See Also" section.

# -> No extended summary found
"ES01", # Not all docstrings require an "Extended Summary" section.

# -> No examples section found
"EX01", # Not all docstrings require an "Examples" section.

# -> No Yields section found
"YD01", # Not all docstrings require a "Yields" section.
]
exclude = [
'\.__eq__$',
'\.__ne__$',
'\.__repr__$',
]

[tool.repo-review]
ignore = [
# https://learn.scientific-python.org/development/guides/style/#PC170
"PC170", # Uses PyGrep hooks
# https://learn.scientific-python.org/development/guides/style/#PC180
"PC180", # Uses prettier
# https://learn.scientific-python.org/development/guides/packaging-simple/#PY004
"PY004", # Has docs folder
# https://learn.scientific-python.org/development/guides/docs/#readthedocsyaml
"RTD", # ReadTheDocs

"PY007", # TODO: Tox adoption blocked by SciTools/iris#5184.
]

[tool.mypy]
# See https://mypy.readthedocs.io/en/stable/config_file.html
ignore_missing_imports = true
warn_unused_configs = true
warn_unreachable = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
exclude = [
"src\\/mo_pack\\/tests$",
]
strict = true

[tool.ruff]
line-length = 88
src = ["src"]

[tool.ruff.format]
preview = false

[tool.ruff.lint]
ignore = [
# NOTE: Non-permanent exclusions should be added to the ".ruff.toml" file.

# flake8-commas (COM)
# https://docs.astral.sh/ruff/rules/#flake8-commas-com
"COM812", # Trailing comma missing.
"COM819", # Trailing comma prohibited.

# flake8-implicit-str-concat (ISC)
# 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.
]
preview = false
select = [
"ALL",
# list specific rules to include that is skipped using numpy convention.
"D212", # Multi-line docstring summary should start at the first line
]

[tool.ruff.lint.isort]
force-sort-within-sections = true

[tool.ruff.lint.per-file-ignores]
# All test scripts.

"src/mo_pack/tests/*.py" = [
# https://docs.astral.sh/ruff/rules/undocumented-public-module/
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D205", # 1 blank line required between summary line and description
"D401", # 1 First line of docstring should be in imperative mood

"ANN", # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
"S101", # Use of assert detected
]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
25 changes: 16 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
from setuptools import Command, Extension, setup
"""Register the Cython extension."""

from __future__ import annotations

from pathlib import Path
from typing import ClassVar

from Cython.Build import cythonize
import numpy as np
from setuptools import Command, Extension, setup

BASE_DIR = Path(__file__).resolve().parent
PACKAGE_NAME = "mo_pack"
SRC_DIR = BASE_DIR / "src"
PACKAGE_DIR = SRC_DIR / PACKAGE_NAME


class CleanCython(Command):
class CleanCython(Command): # type: ignore[misc]
"""Command for purging artifacts built by Cython."""

description = "Purge artifacts built by Cython"
user_options = []
user_options: ClassVar[list[tuple[str, str, str]]] = []

def initialize_options(self):
pass
def initialize_options(self: CleanCython) -> None:
"""Set options/attributes/caches used by the command to default values."""

def finalize_options(self):
pass
def finalize_options(self: CleanCython) -> None:
"""Set final values for all options/attributes used by the command."""

def run(self):
def run(self: CleanCython) -> None:
"""Execute the actions intended by the command."""
for path in PACKAGE_DIR.rglob("*"):
if path.suffix in (".pyc", ".pyo", ".c", ".so"):
msg = f"clean: removing file {path}"
print(msg)
print(msg) # noqa: T201
path.unlink()


Expand Down
22 changes: 20 additions & 2 deletions src/mo_pack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@
#
# This file is part of mo_pack and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
from ._packing import (compress_rle, compress_wgdos,
decompress_rle, decompress_wgdos)
"""Python bindings for the C library **libmo_unpack**.

Provides Python bindings to the C library
`libmo_unpack <https://github.com/SciTools/libmo_unpack>`_ , which contains
packing methods used to encode and decode the data payloads of Met Office UM
Post-Processing and Fields files.

Supports both RLE and WGDOS encoding methods.

"""

from ._packing import compress_rle, compress_wgdos, decompress_rle, decompress_wgdos

try:
from ._version import version as __version__
except ModuleNotFoundError:
__version__ = "unknown"

__all__ = [
"__version__",
"compress_rle",
"compress_wgdos",
"decompress_rle",
"decompress_wgdos",
]
Loading