Skip to content

Commit a1714e0

Browse files
authored
Merge pull request #439 from observingClouds/maint/precommit
Setup pre-commit hooks and apply linters
2 parents 44ecc62 + c572173 commit a1714e0

18 files changed

+70
-25
lines changed

.github/workflows/cd-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ on:
88
jobs:
99
deploy:
1010
uses: ecmwf/reusable-workflows/.github/workflows/cd-pypi.yml@v2
11-
secrets: inherit
11+
secrets: inherit
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Manage labels of pull requests that originate from forks
22
name: label-public-pr
3-
3+
44
on:
55
pull_request_target:
66
types: [opened, synchronize]
7-
7+
88
jobs:
99
label:
1010
uses: ecmwf/reusable-workflows/.github/workflows/label-pr.yml@v2

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ tests/sample-data/cds*.nc
8282
_dev
8383

8484
# mac
85-
.DS_Store
85+
.DS_Store

.pre-commit-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
repos:
2+
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v6.0.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: end-of-file-fixer
8+
- id: check-docstring-first
9+
- id: check-json
10+
- id: check-yaml
11+
- repo: https://github.com/pre-commit/mirrors-mypy
12+
rev: v1.18.2
13+
hooks:
14+
- id: mypy
15+
additional_dependencies:
16+
- attrs
17+
- repo: https://github.com/psf/black-pre-commit-mirror
18+
rev: 25.11.0
19+
hooks:
20+
- id: black
21+
- repo: https://github.com/PyCQA/isort
22+
rev: 7.0.0
23+
hooks:
24+
- id: isort

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Changelog for cfgrib
33
====================
44

5+
unreleased
6+
----------
7+
8+
- Setup and apply linters via pre-commit.
9+
See `#439 <https://github.com/ecmwf/cfgrib/pull/439>`_.
10+
11+
512
0.9.15.1 (2025-09-30)
613
---------------------
714

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Contributing
88
Contributions are welcome, and they are greatly appreciated! Every
99
little bit helps, and credit will always be given.
1010

11-
Please note, that we have hooked a CLA assistant to this GitHub Repo. Please accept the contributors license agreement to allow us to keep a legal track of contributions and keep this package open source for the future.
11+
Please note, that we have hooked a CLA assistant to this GitHub Repo. Please accept the contributors license agreement to allow us to keep a legal track of contributions and keep this package open source for the future.
1212

1313
You can contribute in many ways:
1414

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ install:
1414
build: false
1515

1616
test_script:
17-
- "echo Pass"
17+
- "echo Pass"

cfgrib/abc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Abstract Base Classes for GRIB fields and fieldsets"""
2+
23
import abc
34
import typing as T
45

cfgrib/cfmessage.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def from_grib_step(message, step_key="endStep:int", step_unit_key="stepUnits:int
9797
return int(message[step_key]) * to_seconds / 3600.0
9898

9999

100-
def to_grib_step(message, step_ns, step_unit=1, step_key="endStep:int", step_unit_key="stepUnits:int"):
100+
def to_grib_step(
101+
message, step_ns, step_unit=1, step_key="endStep:int", step_unit_key="stepUnits:int"
102+
):
101103
# type: (abc.MutableField, int, int, str, str) -> None
102104
step_s = step_ns * 1e-9
103105
to_seconds = GRIB_STEP_UNITS_TO_SECONDS[step_unit]
@@ -172,8 +174,12 @@ def build_valid_time(time, step):
172174
functools.partial(to_grib_date_time, date_key="indexingDate", time_key="indexingTime"),
173175
),
174176
"valid_month": (
175-
functools.partial(from_grib_date_time, date_key="monthlyVerificationDate", time_key="validityTime"),
176-
functools.partial(to_grib_date_time, date_key="monthlyVerificationDate", time_key="validityTime"),
177+
functools.partial(
178+
from_grib_date_time, date_key="monthlyVerificationDate", time_key="validityTime"
179+
),
180+
functools.partial(
181+
to_grib_date_time, date_key="monthlyVerificationDate", time_key="validityTime"
182+
),
177183
),
178184
} # type: messages.ComputedKeysType
179185

cfgrib/dataset.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"stepUnits",
4646
"stepType",
4747
"gridType",
48-
"uvRelativeToGrid"
48+
"uvRelativeToGrid",
4949
]
5050

5151
EXTRA_DATA_ATTRIBUTES_KEYS = [
@@ -507,7 +507,9 @@ def build_variable_components(
507507
extra_attrs = read_data_var_attrs(first, extra_keys)
508508
data_var_attrs.update(**extra_attrs)
509509
coords_map = encode_cf_first(
510-
data_var_attrs, encode_cf, time_dims,
510+
data_var_attrs,
511+
encode_cf,
512+
time_dims,
511513
)
512514
coord_name_key_map = {}
513515
coord_vars = {}
@@ -689,7 +691,7 @@ def build_dataset_components(
689691
" be decoded as datetime objects:\n"
690692
f"{ALL_REF_TIME_KEYS}"
691693
)
692-
694+
693695
for param_id in index.get("paramId", []):
694696
var_index = index.subindex(paramId=param_id)
695697
try:
@@ -825,5 +827,7 @@ def open_file(
825827
path = os.fspath(path)
826828
stream = messages.FileStream(path, errors=errors)
827829
index_keys = compute_index_keys(time_dims, extra_coords)
828-
index = open_fileindex(stream, indexpath, index_keys, ignore_keys=ignore_keys, filter_by_keys=filter_by_keys)
830+
index = open_fileindex(
831+
stream, indexpath, index_keys, ignore_keys=ignore_keys, filter_by_keys=filter_by_keys
832+
)
829833
return open_from_index(index, read_keys, time_dims, extra_coords, errors=errors, **kwargs)

0 commit comments

Comments
 (0)