Skip to content

Commit 6b209f3

Browse files
authored
MNT: CI and Lint (h5netcdf#235)
1 parent b19d4a0 commit 6b209f3

File tree

10 files changed

+103
-66
lines changed

10 files changed

+103
-66
lines changed

.github/workflows/main.yml

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up Python
2121
uses: actions/setup-python@v5
2222
with:
23-
python-version: "3.11"
23+
python-version: "3.12"
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip
@@ -30,34 +30,71 @@ jobs:
3030
black --check .
3131
- name: Lint with ruff
3232
run: |
33-
ruff .
33+
ruff check .
3434
3535
build_0:
36-
name: h5py3 tests
36+
name: h5py3 numpy 1 tests
3737
runs-on: ubuntu-latest
3838
defaults:
3939
run:
4040
shell: bash -l {0}
4141
strategy:
4242
fail-fast: false
4343
matrix:
44-
python-version: ["3.9", "3.10", "3.11"]
45-
h5py-version: ["3.8", "3.9", "3.10"]
44+
python-version: ["3.9", "3.12"]
45+
h5py-version: ["3.10", "3.11"]
46+
numpy-version: ["1"]
4647
steps:
4748
- uses: actions/checkout@v4
4849
- name: Install micromamba
4950
uses: mamba-org/setup-micromamba@v1
5051
with:
5152
environment-name: h5netcdf-tests
5253
cache-environment: true
53-
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-h5py${{matrix.h5py_version}}-${{env.TODAY}}"
54+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-h5py${{matrix.h5py_version}}-numpy${{matrix.numpy_version}}-${{env.TODAY}}"
5455
create-args: >-
5556
python=${{ matrix.python-version }}
5657
pip
5758
pytest
5859
wheel
5960
h5py=${{ matrix.h5py-version }}
6061
netCDF4
62+
numpy=${{ matrix.numpy-version }}
63+
- name: Install h5netcdf
64+
run: |
65+
python -m pip install . --no-deps --ignore-installed --no-cache-dir -vvv
66+
- name: Test with pytest
67+
run: |
68+
pytest -v --durations=0 h5netcdf/tests/
69+
70+
build_0a:
71+
name: h5py3 numpy 2 tests
72+
runs-on: ubuntu-latest
73+
defaults:
74+
run:
75+
shell: bash -l {0}
76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
python-version: ["3.11", "3.12"]
80+
h5py-version: ["3.11"]
81+
numpy-version: ["2"]
82+
steps:
83+
- uses: actions/checkout@v4
84+
- name: Install micromamba
85+
uses: mamba-org/setup-micromamba@v1
86+
with:
87+
environment-name: h5netcdf-tests
88+
cache-environment: true
89+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-h5py${{matrix.h5py_version}}-numpy${{matrix.numpy_version}}-${{env.TODAY}}"
90+
create-args: >-
91+
python=${{ matrix.python-version }}
92+
pip
93+
pytest
94+
wheel
95+
h5py=${{ matrix.h5py-version }}
96+
netCDF4
97+
numpy=${{ matrix.numpy-version }}
6198
- name: Install h5netcdf
6299
run: |
63100
python -m pip install . --no-deps --ignore-installed --no-cache-dir -vvv
@@ -75,22 +112,24 @@ jobs:
75112
strategy:
76113
fail-fast: false
77114
matrix:
78-
python-version: ["3.11"]
115+
python-version: ["3.12"]
116+
numpy-version: ["1", "2"]
79117
steps:
80118
- uses: actions/checkout@v4
81119
- name: Install micromamba
82120
uses: mamba-org/setup-micromamba@v1
83121
with:
84122
environment-name: h5netcdf-tests
85123
cache-environment: true
86-
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-h5pyd-${{env.TODAY}}"
124+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-numpy${{matrix.numpy_version}}-h5pyd-${{env.TODAY}}"
87125
create-args: >-
88126
python=${{ matrix.python-version }}
89127
pip
90128
pytest
91129
wheel
92130
h5py
93131
netCDF4
132+
numpy=${{ matrix.numpy-version }}
94133
- name: Install h5netcdf
95134
run: |
96135
python -m pip install . --no-deps --ignore-installed --no-cache-dir -vvv
@@ -110,15 +149,16 @@ jobs:
110149
strategy:
111150
fail-fast: false
112151
matrix:
113-
python-version: ["3.11"]
152+
python-version: ["3.12"]
153+
numpy-version: ["1", "2"]
114154
steps:
115155
- uses: actions/checkout@v4
116156
- name: Install micromamba
117157
uses: mamba-org/setup-micromamba@v1
118158
with:
119159
environment-name: h5netcdf-tests
120160
cache-environment: true
121-
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-netcdf4_nightly-${{env.TODAY}}"
161+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-numpy${{matrix.numpy_version}}-netcdf4_nightly-${{env.TODAY}}"
122162
create-args: >-
123163
python=${{ matrix.python-version }}
124164
pip
@@ -127,6 +167,7 @@ jobs:
127167
h5py
128168
libnetcdf
129169
cftime
170+
numpy=${{ matrix.numpy-version }}
130171
- name: Install netCDF4 from GitHub
131172
run: python -m pip install git+https://github.com/Unidata/netcdf4-python
132173
- name: Install h5netcdf
@@ -146,7 +187,8 @@ jobs:
146187
strategy:
147188
fail-fast: false
148189
matrix:
149-
python-version: ["3.11"]
190+
python-version: ["3.12"]
191+
numpy-version: ["1", "2"]
150192
steps:
151193
- uses: actions/checkout@v4
152194
with:
@@ -157,7 +199,7 @@ jobs:
157199
with:
158200
environment-name: h5netcdf-tests
159201
cache-environment: true
160-
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-xarray_nightly-${{env.TODAY}}"
202+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-numpy${{matrix.numpy_version}}-xarray_nightly-${{env.TODAY}}"
161203
create-args: >-
162204
python=${{ matrix.python-version }}
163205
dask
@@ -168,6 +210,7 @@ jobs:
168210
pip
169211
pytest
170212
wheel
213+
numpy=${{ matrix.numpy-version }}
171214
- name: Install xarray
172215
run: |
173216
python -m pip install --no-deps .
@@ -195,7 +238,7 @@ jobs:
195238
cache-environment: true
196239
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-docs-${{env.TODAY}}"
197240
create-args: >-
198-
python=3.11
241+
python=3.12
199242
pip
200243
pytest
201244
wheel
@@ -225,7 +268,7 @@ jobs:
225268

226269
upload-pypi:
227270
if: github.event_name == 'release'
228-
needs: [lint, build_0, sphinx_doc]
271+
needs: [lint, build_0, build_0a, sphinx_doc]
229272
name: deploy to pypi
230273
runs-on: ubuntu-latest
231274
defaults:
@@ -238,7 +281,7 @@ jobs:
238281
- name: Set up Python
239282
uses: actions/setup-python@v5
240283
with:
241-
python-version: "3.11"
284+
python-version: "3.12"
242285
- name: Install dependencies
243286
run: |
244287
python -m pip install --upgrade pip

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.6.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
@@ -9,17 +9,17 @@ repos:
99
- id: check-yaml
1010
- id: debug-statements
1111
- id: mixed-line-ending
12-
- repo: https://github.com/charliermarsh/ruff-pre-commit
13-
rev: 'v0.0.291'
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: 'v0.5.0'
1414
hooks:
1515
- id: ruff
1616
args: [ "--fix" ]
1717
- repo: https://github.com/psf/black
18-
rev: 23.9.1
18+
rev: 24.4.2
1919
hooks:
2020
- id: black
2121
- repo: https://github.com/adamchainz/blacken-docs
22-
rev: "1.16.0"
22+
rev: "1.18.0"
2323
hooks:
2424
- id: blacken-docs
2525
additional_dependencies:

CHANGELOG.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ Change Log
33

44
Development Version:
55

6-
- Add UserType class, add EnumType.
6+
- Add UserType class, add EnumType ({pull}`229`).
77
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_
8-
- Refactor fillvalue and dtype handling for user types, enhance sanity checks and tests.
8+
- Refactor fillvalue and dtype handling for user types, enhance sanity checks and tests ({pull}`230`).
99
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_
1010
- Update h5pyd testing.
1111
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_
12+
- CI and lint maintenance ({pull}`235`).
13+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_
1214

1315
Version 1.3.0 (November 7th, 2023):
1416

h5netcdf/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
A Python library for the netCDF4 file-format that directly reads and writes
66
HDF5 files via h5py, without using the Unidata netCDF library.
77
"""
8+
89
try:
910
from ._version import version as __version__
1011
except Exception:

h5netcdf/attrs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __getitem__(self, key):
7676

7777
def __setitem__(self, key, value):
7878
if key in _HIDDEN_ATTRS:
79-
raise AttributeError("cannot write attribute with reserved name %r" % key)
79+
raise AttributeError(f"cannot write attribute with reserved name {key!r}")
8080
if hasattr(value, "dtype"):
8181
dtype = value.dtype
8282
else:
@@ -98,4 +98,4 @@ def __len__(self):
9898
return len(self._h5attrs) - hidden_count
9999

100100
def __repr__(self):
101-
return "\n".join(["%r" % type(self)] + [f"{k}: {v!r}" for k, v in self.items()])
101+
return "\n".join([f"{type(self)!r}"] + [f"{k}: {v!r}" for k, v in self.items()])

h5netcdf/core.py

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ def _transform_1d_boolean_indexers(key):
5454
# return key, if not iterable
5555
try:
5656
key = [
57-
np.asanyarray(k).nonzero()[0]
58-
if isinstance(k, (np.ndarray, list)) and type(k[0]) in (bool, np.bool_)
59-
else k
57+
(
58+
np.asanyarray(k).nonzero()[0]
59+
if isinstance(k, (np.ndarray, list)) and type(k[0]) in (bool, np.bool_)
60+
else k
61+
)
6062
for k in key
6163
]
6264
except TypeError:
@@ -447,14 +449,8 @@ def attrs(self):
447449

448450
def __repr__(self):
449451
if self._parent._root._closed:
450-
return "<Closed %s>" % self._cls_name
451-
header = "<{} {!r}: dimensions {}, shape {}, dtype {}>".format(
452-
self._cls_name,
453-
self.name,
454-
self.dimensions,
455-
self.shape,
456-
self.dtype,
457-
)
452+
return f"<Closed {self._cls_name}>"
453+
header = f"<{self._cls_name} {self.name!r}: dimensions {self.dimensions}, shape {self.shape}, dtype {self.dtype}>"
458454
return "\n".join(
459455
[header]
460456
+ ["Attributes:"]
@@ -799,16 +795,16 @@ def dimensions(self, value):
799795
for k, v in self._all_dimensions.maps[0].items():
800796
if k in value:
801797
if v != value[k]:
802-
raise ValueError("cannot modify existing dimension %r" % k)
798+
raise ValueError(f"cannot modify existing dimension {k:!r}")
803799
else:
804800
raise ValueError(
805-
"new dimensions do not include existing dimension %r" % k
801+
f"new dimensions do not include existing dimension {k:!r}"
806802
)
807803
self._dimensions.update(value)
808804

809805
def _create_child_group(self, name):
810806
if name in self:
811-
raise ValueError("unable to create group %r (name already exists)" % name)
807+
raise ValueError(f"unable to create group {name:!r} (name already exists)")
812808
kwargs = {}
813809
if self._root._h5py.__name__ == "h5py":
814810
kwargs.update(track_order=self._track_order)
@@ -853,7 +849,7 @@ def _create_child_variable(
853849
):
854850
if name in self:
855851
raise ValueError(
856-
"unable to create variable %r " "(name already exists)" % name
852+
f"unable to create variable {name:!r} (name already exists)"
857853
)
858854
if data is not None:
859855
data = np.asarray(data)
@@ -914,8 +910,8 @@ def _create_child_variable(
914910
pass
915911
else:
916912
raise ValueError(
917-
"got unrecognized value %s for chunking_heuristic argument "
918-
'(has to be "h5py" or "h5netcdf")' % chunking_heuristic
913+
f"got unrecognized value {chunking_heuristic} for chunking_heuristic argument "
914+
'(has to be "h5py" or "h5netcdf")'
919915
)
920916

921917
# Clear dummy HDF5 datasets with this name that were created for a
@@ -1130,9 +1126,11 @@ def _repr_body(self):
11301126
+ [
11311127
" {}: {}".format(
11321128
k,
1133-
f"Unlimited (current: {self._dimensions[k].size})"
1134-
if v is None
1135-
else v,
1129+
(
1130+
f"Unlimited (current: {self._dimensions[k].size})"
1131+
if v is None
1132+
else v
1133+
),
11361134
)
11371135
for k, v in self.dimensions.items()
11381136
]
@@ -1340,9 +1338,9 @@ def create_phony_dimensions(grp):
13401338
def _check_valid_netcdf_dtype(self, dtype):
13411339
dtype = np.dtype(dtype)
13421340

1343-
if dtype == bool:
1341+
if dtype == bool: # noqa
13441342
description = "boolean"
1345-
elif dtype == complex:
1343+
elif dtype == complex: # noqa
13461344
description = "complex"
13471345
elif self._h5py.check_dtype(ref=dtype) is not None:
13481346
description = "reference"
@@ -1377,12 +1375,7 @@ def flush(self):
13771375
if self._writable:
13781376
# only write `_NCProperties` in newly created files
13791377
if not self._preexisting_file and not self.invalid_netcdf:
1380-
_NC_PROPERTIES = "version=2,h5netcdf={},hdf5={},{}={}".format(
1381-
__version__,
1382-
self._h5py.version.hdf5_version,
1383-
self._h5py.__name__,
1384-
self._h5py.__version__,
1385-
)
1378+
_NC_PROPERTIES = f"version=2,h5netcdf={__version__},hdf5={self._h5py.version.hdf5_version},{self._h5py.__name__}={self._h5py.__version__}"
13861379
self.attrs._h5attrs["_NCProperties"] = np.array(
13871380
_NC_PROPERTIES,
13881381
dtype=self._h5py.string_dtype(
@@ -1424,7 +1417,7 @@ def __exit__(self, type, value, traceback):
14241417

14251418
def __repr__(self):
14261419
if self._closed:
1427-
return "<Closed %s>" % self._cls_name
1420+
return f"<Closed {self._cls_name}>"
14281421
header = "<{} {!r} (mode {})>".format(
14291422
self._cls_name,
14301423
self.filename.split("/")[-1],

0 commit comments

Comments
 (0)