From 8edd3f96d2703df070f70bd224b3707ec4d68c4e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:56:15 +0200 Subject: [PATCH] Apply repo-review suggestions (#559) * Apply repo-review rule PP304 PP304: Sets the log level in pytest log_cli_level should be set. This will allow logs to be displayed on failures. * Apply repo-review rule PP305 PP305: Specifies xfail_strict xfail_strict should be set. You can manually specify if a check should be strict when setting each xfail. * Apply repo-review rules PP306, PP307, PP308 PP306: Specifies strict config --strict-config should be in addopts = [...]. This forces an error if a config setting is misspelled. PP307: Specifies strict markers --strict-markers should be in addopts = [...]. This forces all markers to be specified in config, avoiding misspellings. PP308: Specifies useful pytest summary An explicit summary flag like -ra should be in addopts = [...] (print summary of all fails/errors). * Apply ruff/pygrep-hooks rule PGH004 PGH004 Use specific rule codes when using `noqa` PGH004 Use specific rule codes when using `ruff: noqa` * Apply and enforce ruff rules (RUF) Apply ruff rule RUF012: RUF012 Mutable class attributes should be annotated with `typing.ClassVar` Disable ruff rule RUF001 * Apply and enforce ruff/flake8-bugbear rules (B) B007 Loop control variable not used within loop body B028 No explicit `stacklevel` keyword argument found B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling B905 `zip()` without an explicit `strict=` parameter Co-authored-by: David Stansby * Apply and enforce ruff/isort rules (I) * Apply repo-review rule PC100 PC100: Has pre-commit-hooks Must have https://github.com/pre-commit/pre-commit-hooks repo in .pre-commit-config.yaml * Enforce repo-review rules * Apply ruff/flake8-implicit-str-concat rules (ISC) ISC001 Implicitly concatenated string literals on one line ISC003 Explicitly concatenated string should be implicitly concatenated * Apply ruff/refurb rules (FURB) FURB163 Prefer `math.log10`/`math.log2` over `math.log` with a redundant base * Fix DeprecationWarning 'pkgutil.find_loader' is deprecated and slated for removal in Python 3.14; use importlib.util.find_spec() instead --------- Co-authored-by: David Stansby --- .pre-commit-config.yaml | 15 ++++- .pyup.yml | 2 +- README.rst | 2 +- adhoc/blosc_memleak_check.py | 4 +- docs/conf.py | 3 +- notebooks/benchmark_vlen.ipynb | 1 + numcodecs/__init__.py | 10 ++- numcodecs/astype.py | 2 +- numcodecs/bitround.py | 1 - numcodecs/blosc.pyx | 2 +- numcodecs/bz2.py | 3 +- numcodecs/categorize.py | 9 ++- numcodecs/checksum32.py | 4 +- numcodecs/compat.py | 6 +- numcodecs/delta.py | 1 - numcodecs/fixedscaleoffset.py | 1 - numcodecs/jenkins.pyx | 8 +-- numcodecs/json.py | 2 - numcodecs/lzma.py | 2 +- numcodecs/msgpacks.py | 3 +- numcodecs/ndarray_like.py | 4 +- numcodecs/packbits.py | 1 - numcodecs/pcodec.py | 4 +- numcodecs/quantize.py | 6 +- numcodecs/registry.py | 2 +- numcodecs/shuffle.py | 5 +- numcodecs/tests/common.py | 12 ++-- numcodecs/tests/test_astype.py | 6 +- numcodecs/tests/test_base64.py | 7 +-- numcodecs/tests/test_bitround.py | 1 - numcodecs/tests/test_blosc.py | 7 +-- numcodecs/tests/test_bz2.py | 9 +-- numcodecs/tests/test_categorize.py | 8 +-- numcodecs/tests/test_checksum32.py | 9 +-- numcodecs/tests/test_compat.py | 4 +- numcodecs/tests/test_delta.py | 8 +-- numcodecs/tests/test_entrypoints.py | 1 - numcodecs/tests/test_entrypoints_backport.py | 7 +-- numcodecs/tests/test_fixedscaleoffset.py | 9 +-- numcodecs/tests/test_gzip.py | 9 +-- numcodecs/tests/test_jenkins.py | 66 ++++++++++---------- numcodecs/tests/test_json.py | 4 +- numcodecs/tests/test_lz4.py | 9 +-- numcodecs/tests/test_lzma.py | 13 ++-- numcodecs/tests/test_msgpacks.py | 11 ++-- numcodecs/tests/test_packbits.py | 6 +- numcodecs/tests/test_pcodec.py | 9 ++- numcodecs/tests/test_pickles.py | 5 +- numcodecs/tests/test_quantize.py | 9 +-- numcodecs/tests/test_registry.py | 8 +-- numcodecs/tests/test_shuffle.py | 7 +-- numcodecs/tests/test_vlen_array.py | 11 ++-- numcodecs/tests/test_vlen_bytes.py | 11 ++-- numcodecs/tests/test_vlen_utf8.py | 13 ++-- numcodecs/tests/test_zfpy.py | 12 ++-- numcodecs/tests/test_zlib.py | 11 ++-- numcodecs/tests/test_zstd.py | 9 +-- numcodecs/zfpy.py | 8 ++- numcodecs/zlib.py | 3 +- pyproject.toml | 13 ++-- setup.py | 10 +-- 61 files changed, 194 insertions(+), 254 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 80ec6a54..dd04f38a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +exclude: ^fixture/ # files with trailing whitespaces on purpose ci: autoupdate_commit_msg: "chore: update pre-commit hooks" autofix_commit_msg: "style: pre-commit fixes" @@ -6,9 +7,21 @@ default_stages: [commit, push] default_language_version: python: python3 repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: check-yaml + - id: debug-statements + - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.6.9' + rev: v0.6.9 hooks: - id: ruff args: ["--fix", "--show-fixes"] - id: ruff-format + + - repo: https://github.com/scientific-python/cookie + rev: 2024.04.23 + hooks: + - id: sp-repo-review diff --git a/.pyup.yml b/.pyup.yml index 30182e6b..d3b270be 100644 --- a/.pyup.yml +++ b/.pyup.yml @@ -1,4 +1,4 @@ -# autogenerated pyup.io config file +# autogenerated pyup.io config file # see https://pyup.io/docs/configuration/ for all available options schedule: every month diff --git a/README.rst b/README.rst index c9e58f52..1367cf3c 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ Numcodecs ========= -Numcodecs is a Python package providing buffer compression and transformation +Numcodecs is a Python package providing buffer compression and transformation codecs for use in data storage and communication applications. .. image:: https://readthedocs.org/projects/numcodecs/badge/?version=latest diff --git a/adhoc/blosc_memleak_check.py b/adhoc/blosc_memleak_check.py index 3a875449..427c3e15 100644 --- a/adhoc/blosc_memleak_check.py +++ b/adhoc/blosc_memleak_check.py @@ -1,13 +1,13 @@ import sys -import numcodecs import numpy as np from numpy.testing import assert_array_equal +import numcodecs codec = numcodecs.Blosc() data = np.arange(int(sys.argv[1])) -for i in range(int(sys.argv[2])): +for _ in range(int(sys.argv[2])): enc = codec.encode(data) dec = codec.decode(enc) arr = np.frombuffer(dec, dtype=data.dtype) diff --git a/docs/conf.py b/docs/conf.py index 0cf73e55..800be7be 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,9 +13,10 @@ # serve to show the default. -import sys import os +import sys from unittest.mock import Mock as MagicMock + import numcodecs diff --git a/notebooks/benchmark_vlen.ipynb b/notebooks/benchmark_vlen.ipynb index 8878a2cf..c627cac9 100644 --- a/notebooks/benchmark_vlen.ipynb +++ b/notebooks/benchmark_vlen.ipynb @@ -25,6 +25,7 @@ ], "source": [ "import numpy as np\n", + "\n", "import numcodecs\n", "\n", "numcodecs.__version__" diff --git a/numcodecs/__init__.py b/numcodecs/__init__.py index 47c2c616..82836db0 100644 --- a/numcodecs/__init__.py +++ b/numcodecs/__init__.py @@ -1,4 +1,4 @@ -# flake8: noqa +# ruff: noqa: E402,F401 """Numcodecs is a Python package providing buffer compression and transformation codecs for use in data storage and communication applications. These include: @@ -17,14 +17,12 @@ """ -import multiprocessing import atexit +import multiprocessing from contextlib import suppress - -from numcodecs.version import version as __version__ from numcodecs.registry import get_codec, register_codec - +from numcodecs.version import version as __version__ from numcodecs.zlib import Zlib register_codec(Zlib) @@ -130,7 +128,7 @@ with suppress(ImportError): from numcodecs import vlen - from numcodecs.vlen import VLenUTF8, VLenBytes, VLenArray + from numcodecs.vlen import VLenArray, VLenBytes, VLenUTF8 register_codec(VLenUTF8) register_codec(VLenBytes) diff --git a/numcodecs/astype.py b/numcodecs/astype.py index e1e95adf..b5c5abc9 100644 --- a/numcodecs/astype.py +++ b/numcodecs/astype.py @@ -1,7 +1,7 @@ import numpy as np from .abc import Codec -from .compat import ndarray_copy, ensure_ndarray +from .compat import ensure_ndarray, ndarray_copy class AsType(Codec): diff --git a/numcodecs/bitround.py b/numcodecs/bitround.py index 767e5e43..29f46bf8 100644 --- a/numcodecs/bitround.py +++ b/numcodecs/bitround.py @@ -1,6 +1,5 @@ import numpy as np - from .abc import Codec from .compat import ensure_ndarray_like, ndarray_copy diff --git a/numcodecs/blosc.pyx b/numcodecs/blosc.pyx index 45e5ea10..c8322e4e 100644 --- a/numcodecs/blosc.pyx +++ b/numcodecs/blosc.pyx @@ -468,7 +468,7 @@ def decompress_partial(source, start, nitems, dest=None): raise RuntimeError('error during blosc partial decompression: %d', ret) return dest - + # set the value of this variable to True or False to override the # default adaptive behaviour diff --git a/numcodecs/bz2.py b/numcodecs/bz2.py index fd77d2c8..2b63b147 100644 --- a/numcodecs/bz2.py +++ b/numcodecs/bz2.py @@ -1,8 +1,7 @@ import bz2 as _bz2 - from numcodecs.abc import Codec -from numcodecs.compat import ndarray_copy, ensure_contiguous_ndarray +from numcodecs.compat import ensure_contiguous_ndarray, ndarray_copy class BZ2(Codec): diff --git a/numcodecs/categorize.py b/numcodecs/categorize.py index 74d35afa..787c17a5 100644 --- a/numcodecs/categorize.py +++ b/numcodecs/categorize.py @@ -1,9 +1,8 @@ -from .abc import Codec -from .compat import ensure_ndarray, ndarray_copy, ensure_text - - import numpy as np +from .abc import Codec +from .compat import ensure_ndarray, ensure_text, ndarray_copy + class Categorize(Codec): """Filter encoding categorical string data as integers. @@ -41,7 +40,7 @@ class Categorize(Codec): def __init__(self, labels, dtype, astype='u1'): self.dtype = np.dtype(dtype) if self.dtype.kind not in 'UO': - raise TypeError("only unicode ('U') and object ('O') dtypes are " "supported") + raise TypeError("only unicode ('U') and object ('O') dtypes are supported") self.labels = [ensure_text(label) for label in labels] self.astype = np.dtype(astype) if self.astype == np.dtype(object): diff --git a/numcodecs/checksum32.py b/numcodecs/checksum32.py index e4306d20..ab36dd93 100644 --- a/numcodecs/checksum32.py +++ b/numcodecs/checksum32.py @@ -1,9 +1,7 @@ +import struct import zlib - import numpy as np -import struct - from .abc import Codec from .compat import ensure_contiguous_ndarray, ndarray_copy diff --git a/numcodecs/compat.py b/numcodecs/compat.py index c5df5452..96522ce6 100644 --- a/numcodecs/compat.py +++ b/numcodecs/compat.py @@ -1,7 +1,7 @@ -# flake8: noqa -import functools -import codecs +# ruff: noqa: F401 import array +import codecs +import functools import numpy as np diff --git a/numcodecs/delta.py b/numcodecs/delta.py index 624a36df..9303015d 100644 --- a/numcodecs/delta.py +++ b/numcodecs/delta.py @@ -1,6 +1,5 @@ import numpy as np - from .abc import Codec from .compat import ensure_ndarray, ndarray_copy diff --git a/numcodecs/fixedscaleoffset.py b/numcodecs/fixedscaleoffset.py index 2ea871c5..b9f3393a 100644 --- a/numcodecs/fixedscaleoffset.py +++ b/numcodecs/fixedscaleoffset.py @@ -1,6 +1,5 @@ import numpy as np - from .abc import Codec from .compat import ensure_ndarray, ndarray_copy diff --git a/numcodecs/jenkins.pyx b/numcodecs/jenkins.pyx index 24392238..0efaf26c 100644 --- a/numcodecs/jenkins.pyx +++ b/numcodecs/jenkins.pyx @@ -168,7 +168,7 @@ cpdef uint32_t jenkins_lookup3(const uint8_t[::1] _data, uint32_t initval=0): if length == 12: c += (k[11]) << 24 length -= 1 - + if length == 11: c += (k[10]) << 16 length -= 1 @@ -231,7 +231,7 @@ cdef inline uint32_t _jenkins_lookup3_final(uint32_t a, uint32_t b, uint32_t c): the output delta to a Gray code (a^(a>>1)) so a string of 1's (as is commonly produced by subtraction) look like a single 1-bit difference. - * the base values were pseudorandom, all zero but one bit set, or + * the base values were pseudorandom, all zero but one bit set, or all zero plus a counter that starts at zero. These constants passed: @@ -279,7 +279,7 @@ cdef inline (uint32_t, uint32_t, uint32_t) _jenkins_lookup3_mix(uint32_t a, uint the output delta to a Gray code (a^(a>>1)) so a string of 1's (as is commonly produced by subtraction) look like a single 1-bit difference. - * the base values were pseudorandom, all zero but one bit set, or + * the base values were pseudorandom, all zero but one bit set, or all zero plus a counter that starts at zero. Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that @@ -289,7 +289,7 @@ cdef inline (uint32_t, uint32_t, uint32_t) _jenkins_lookup3_mix(uint32_t a, uint 14 9 3 7 17 3 Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing for "differ" defined as + with a one-bit base and a two-bit delta. I - used http://burtleburtle.net/bob/hash/avalanche.html to choose + used http://burtleburtle.net/bob/hash/avalanche.html to choose the operations, constants, and arrangements of the variables. This does not achieve avalanche. There are input bits of (a,b,c) diff --git a/numcodecs/json.py b/numcodecs/json.py index 7db107dd..ea3175d5 100644 --- a/numcodecs/json.py +++ b/numcodecs/json.py @@ -1,10 +1,8 @@ import json as _json import textwrap - import numpy as np - from .abc import Codec from .compat import ensure_text diff --git a/numcodecs/lzma.py b/numcodecs/lzma.py index 4966920b..592463b4 100644 --- a/numcodecs/lzma.py +++ b/numcodecs/lzma.py @@ -10,7 +10,7 @@ if _lzma: from .abc import Codec - from .compat import ndarray_copy, ensure_contiguous_ndarray + from .compat import ensure_contiguous_ndarray, ndarray_copy # noinspection PyShadowingBuiltins class LZMA(Codec): diff --git a/numcodecs/msgpacks.py b/numcodecs/msgpacks.py index e3dc7680..3f4ea40a 100644 --- a/numcodecs/msgpacks.py +++ b/numcodecs/msgpacks.py @@ -1,6 +1,5 @@ -import numpy as np import msgpack - +import numpy as np from .abc import Codec from .compat import ensure_contiguous_ndarray diff --git a/numcodecs/ndarray_like.py b/numcodecs/ndarray_like.py index 99416f8d..70035a5c 100644 --- a/numcodecs/ndarray_like.py +++ b/numcodecs/ndarray_like.py @@ -1,4 +1,4 @@ -from typing import Any, Optional, Protocol, runtime_checkable +from typing import Any, ClassVar, Optional, Protocol, runtime_checkable class _CachedProtocolMeta(Protocol.__class__): @@ -11,7 +11,7 @@ class _CachedProtocolMeta(Protocol.__class__): isinstance checks using the object's class as the cache key. """ - _instancecheck_cache: dict[tuple[type, type], bool] = {} + _instancecheck_cache: ClassVar[dict[tuple[type, type], bool]] = {} def __instancecheck__(self, instance): key = (self, instance.__class__) diff --git a/numcodecs/packbits.py b/numcodecs/packbits.py index 6ada4379..d22976ed 100644 --- a/numcodecs/packbits.py +++ b/numcodecs/packbits.py @@ -1,6 +1,5 @@ import numpy as np - from .abc import Codec from .compat import ensure_ndarray, ndarray_copy diff --git a/numcodecs/pcodec.py b/numcodecs/pcodec.py index b345bd2e..c01d41be 100644 --- a/numcodecs/pcodec.py +++ b/numcodecs/pcodec.py @@ -1,11 +1,11 @@ -from typing import Optional, Literal +from typing import Literal, Optional import numcodecs import numcodecs.abc from numcodecs.compat import ensure_contiguous_ndarray try: - from pcodec import standalone, ChunkConfig, PagingSpec, ModeSpec + from pcodec import ChunkConfig, ModeSpec, PagingSpec, standalone except ImportError: # pragma: no cover standalone = None diff --git a/numcodecs/quantize.py b/numcodecs/quantize.py index c9fe3bd9..3594209c 100644 --- a/numcodecs/quantize.py +++ b/numcodecs/quantize.py @@ -1,9 +1,7 @@ import math - import numpy as np - from .abc import Codec from .compat import ensure_ndarray, ndarray_copy @@ -65,12 +63,12 @@ def encode(self, buf): # apply scaling precision = 10.0**-self.digits - exp = math.log(precision, 10) + exp = math.log10(precision) if exp < 0: exp = int(math.floor(exp)) else: exp = int(math.ceil(exp)) - bits = math.ceil(math.log(10.0**-exp, 2)) + bits = math.ceil(math.log2(10.0**-exp)) scale = 2.0**bits enc = np.around(scale * arr) / scale diff --git a/numcodecs/registry.py b/numcodecs/registry.py index cb512548..befecf0a 100644 --- a/numcodecs/registry.py +++ b/numcodecs/registry.py @@ -1,8 +1,8 @@ """The registry module provides some simple convenience functions to enable applications to dynamically register and look-up codec classes.""" -from importlib.metadata import entry_points import logging +from importlib.metadata import entry_points logger = logging.getLogger("numcodecs") codec_registry = {} diff --git a/numcodecs/shuffle.py b/numcodecs/shuffle.py index cc243369..0e7031f5 100644 --- a/numcodecs/shuffle.py +++ b/numcodecs/shuffle.py @@ -1,7 +1,8 @@ import numpy as np -from .compat import ensure_contiguous_ndarray -from .abc import Codec + from ._shuffle import _doShuffle, _doUnshuffle +from .abc import Codec +from .compat import ensure_contiguous_ndarray class Shuffle(Codec): diff --git a/numcodecs/tests/common.py b/numcodecs/tests/common.py index 012b820c..2de81052 100644 --- a/numcodecs/tests/common.py +++ b/numcodecs/tests/common.py @@ -3,19 +3,15 @@ import os from glob import glob - import numpy as np -from numpy.testing import assert_array_almost_equal, assert_array_equal import pytest +from numpy.testing import assert_array_almost_equal, assert_array_equal - +# star import needed for repr tests so eval finds names +from numcodecs import * # noqa: F403 from numcodecs.compat import ensure_bytes, ensure_ndarray from numcodecs.registry import get_codec -# star import needed for repr tests so eval finds names -from numcodecs import * # noqa - - greetings = [ '¡Hola mundo!', 'Hej Världen!', @@ -200,7 +196,7 @@ def assert_array_items_equal(res, arr): # and values arr = arr.ravel().tolist() res = res.ravel().tolist() - for a, r in zip(arr, res): + for a, r in zip(arr, res, strict=True): if isinstance(a, np.ndarray): assert_array_equal(a, r) elif a != a: diff --git a/numcodecs/tests/test_astype.py b/numcodecs/tests/test_astype.py index b941e1dd..b4653f5b 100644 --- a/numcodecs/tests/test_astype.py +++ b/numcodecs/tests/test_astype.py @@ -1,16 +1,14 @@ import numpy as np from numpy.testing import assert_array_equal - from numcodecs.astype import AsType from numcodecs.tests.common import ( - check_encode_decode, + check_backwards_compatibility, check_config, + check_encode_decode, check_repr, - check_backwards_compatibility, ) - # mix of dtypes: integer, float # mix of shapes: 1D, 2D, 3D # mix of orders: C, F diff --git a/numcodecs/tests/test_base64.py b/numcodecs/tests/test_base64.py index 82172d97..03f2d491 100644 --- a/numcodecs/tests/test_base64.py +++ b/numcodecs/tests/test_base64.py @@ -1,20 +1,17 @@ import itertools - import numpy as np import pytest - from numcodecs.base64 import Base64 from numcodecs.tests.common import ( - check_encode_decode, - check_repr, check_backwards_compatibility, + check_encode_decode, check_err_decode_object_buffer, check_err_encode_object_buffer, + check_repr, ) - codecs = [ Base64(), ] diff --git a/numcodecs/tests/test_bitround.py b/numcodecs/tests/test_bitround.py index 05284bc5..31332ff9 100644 --- a/numcodecs/tests/test_bitround.py +++ b/numcodecs/tests/test_bitround.py @@ -1,5 +1,4 @@ import numpy as np - import pytest from numcodecs.bitround import BitRound, max_bits diff --git a/numcodecs/tests/test_blosc.py b/numcodecs/tests/test_blosc.py index 907b2307..d0a16272 100644 --- a/numcodecs/tests/test_blosc.py +++ b/numcodecs/tests/test_blosc.py @@ -1,11 +1,9 @@ from multiprocessing import Pool from multiprocessing.pool import ThreadPool - import numpy as np import pytest - try: from numcodecs import blosc from numcodecs.blosc import Blosc @@ -14,16 +12,15 @@ from numcodecs.tests.common import ( + check_backwards_compatibility, + check_config, check_encode_decode, check_encode_decode_partial, - check_config, - check_backwards_compatibility, check_err_decode_object_buffer, check_err_encode_object_buffer, check_max_buffer_size, ) - codecs = [ Blosc(shuffle=Blosc.SHUFFLE), Blosc(clevel=0, shuffle=Blosc.SHUFFLE), diff --git a/numcodecs/tests/test_bz2.py b/numcodecs/tests/test_bz2.py index fa2ca6c3..ce83f1e2 100644 --- a/numcodecs/tests/test_bz2.py +++ b/numcodecs/tests/test_bz2.py @@ -1,20 +1,17 @@ import itertools - import numpy as np - from numcodecs.bz2 import BZ2 from numcodecs.tests.common import ( - check_encode_decode, - check_config, - check_repr, check_backwards_compatibility, + check_config, + check_encode_decode, check_err_decode_object_buffer, check_err_encode_object_buffer, + check_repr, ) - codecs = [ BZ2(), BZ2(level=1), diff --git a/numcodecs/tests/test_categorize.py b/numcodecs/tests/test_categorize.py index 32c9992d..0ec115bb 100644 --- a/numcodecs/tests/test_categorize.py +++ b/numcodecs/tests/test_categorize.py @@ -1,17 +1,15 @@ import numpy as np -from numpy.testing import assert_array_equal import pytest - +from numpy.testing import assert_array_equal from numcodecs.categorize import Categorize from numcodecs.tests.common import ( - check_encode_decode, - check_config, check_backwards_compatibility, + check_config, + check_encode_decode, check_encode_decode_array, ) - labels = ['ƒöõ', 'ßàř', 'ßāẑ', 'ƪùüx'] arrays = [ np.random.choice(labels, size=1000), diff --git a/numcodecs/tests/test_checksum32.py b/numcodecs/tests/test_checksum32.py index 641b5ef3..048f727b 100644 --- a/numcodecs/tests/test_checksum32.py +++ b/numcodecs/tests/test_checksum32.py @@ -1,20 +1,17 @@ import itertools - import numpy as np import pytest - from numcodecs.checksum32 import CRC32, Adler32 from numcodecs.tests.common import ( - check_encode_decode, - check_config, - check_repr, check_backwards_compatibility, + check_config, + check_encode_decode, check_err_encode_object_buffer, + check_repr, ) - # mix of dtypes: integer, float, bool, string # mix of shapes: 1D, 2D, 3D # mix of orders: C, F diff --git a/numcodecs/tests/test_compat.py b/numcodecs/tests/test_compat.py index f54e19c7..64addf6a 100644 --- a/numcodecs/tests/test_compat.py +++ b/numcodecs/tests/test_compat.py @@ -1,12 +1,10 @@ import array import mmap - import numpy as np import pytest - -from numcodecs.compat import ensure_text, ensure_bytes, ensure_contiguous_ndarray +from numcodecs.compat import ensure_bytes, ensure_contiguous_ndarray, ensure_text def test_ensure_text(): diff --git a/numcodecs/tests/test_delta.py b/numcodecs/tests/test_delta.py index a1e915e0..fb5714bb 100644 --- a/numcodecs/tests/test_delta.py +++ b/numcodecs/tests/test_delta.py @@ -1,17 +1,15 @@ import numpy as np -from numpy.testing import assert_array_equal import pytest - +from numpy.testing import assert_array_equal from numcodecs.delta import Delta from numcodecs.tests.common import ( - check_encode_decode, + check_backwards_compatibility, check_config, + check_encode_decode, check_repr, - check_backwards_compatibility, ) - # mix of dtypes: integer, float # mix of shapes: 1D, 2D, 3D # mix of orders: C, F diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py index 2923ac22..4946c7ae 100644 --- a/numcodecs/tests/test_entrypoints.py +++ b/numcodecs/tests/test_entrypoints.py @@ -5,7 +5,6 @@ import numcodecs.registry - here = os.path.abspath(os.path.dirname(__file__)) diff --git a/numcodecs/tests/test_entrypoints_backport.py b/numcodecs/tests/test_entrypoints_backport.py index c3e9369a..21f245aa 100644 --- a/numcodecs/tests/test_entrypoints_backport.py +++ b/numcodecs/tests/test_entrypoints_backport.py @@ -1,14 +1,13 @@ +import importlib import os.path -import pkgutil import sys +from multiprocessing import Process import pytest -from multiprocessing import Process - import numcodecs.registry -if not pkgutil.find_loader("importlib_metadata"): # pragma: no cover +if not importlib.util.find_spec("importlib_metadata").loader: # pragma: no cover pytest.skip( "This test module requires importlib_metadata to be installed", allow_module_level=True, diff --git a/numcodecs/tests/test_fixedscaleoffset.py b/numcodecs/tests/test_fixedscaleoffset.py index 8f985c4a..daa64220 100644 --- a/numcodecs/tests/test_fixedscaleoffset.py +++ b/numcodecs/tests/test_fixedscaleoffset.py @@ -1,20 +1,17 @@ import itertools - import numpy as np -from numpy.testing import assert_array_equal import pytest - +from numpy.testing import assert_array_equal from numcodecs.fixedscaleoffset import FixedScaleOffset from numcodecs.tests.common import ( - check_encode_decode, + check_backwards_compatibility, check_config, + check_encode_decode, check_repr, - check_backwards_compatibility, ) - arrays = [ np.linspace(1000, 1001, 1000, dtype='= 2.0.0 detected. The zfpy library is incompatible with this version of NumPy. " "Please downgrade to NumPy < 2.0.0 or wait for an update from zfpy.", UserWarning, + stacklevel=2, ) else: with suppress(ImportError): import zfpy as _zfpy if _zfpy: - from .abc import Codec - from .compat import ndarray_copy, ensure_contiguous_ndarray, ensure_bytes import numpy as np + from .abc import Codec + from .compat import ensure_bytes, ensure_contiguous_ndarray, ndarray_copy + # noinspection PyShadowingBuiltins class ZFPY(Codec): """Codec providing compression using zfpy via the Python standard diff --git a/numcodecs/zlib.py b/numcodecs/zlib.py index b5e294f4..ca247af2 100644 --- a/numcodecs/zlib.py +++ b/numcodecs/zlib.py @@ -1,8 +1,7 @@ import zlib as _zlib - from .abc import Codec -from .compat import ndarray_copy, ensure_contiguous_ndarray +from .compat import ensure_contiguous_ndarray, ndarray_copy class Zlib(Codec): diff --git a/pyproject.toml b/pyproject.toml index 3fb3ad0d..b6955be8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ msgpack = [ ] zfpy = [ "zfpy>=1.0.0", - "numpy<2.0.0", + "numpy<2.0.0", ] pcodec = [ "pcodec>=0.2.0", @@ -98,8 +98,11 @@ exclude_lines = [ "pragma: ${PY_MAJOR_VERSION} no cover", ] +[tool.repo-review] +ignore = ["PY005", "PY007", "PP302", "PP308", "PP309", "GH103", "GH212", "PC111", "PC140", "PC160", "PC170", "PC180", "MY100", "RF103"] + [tool.pytest.ini_options] -addopts = "--cov=numcodecs --cov-report xml --doctest-modules --doctest-glob=*.pyx" +addopts = "-ra --strict-config --strict-markers --cov=numcodecs --cov-report xml --doctest-modules --doctest-glob=*.pyx" doctest_optionflags = [ "NORMALIZE_WHITESPACE", "ELLIPSIS", @@ -120,6 +123,8 @@ norecursedirs = [ "notebooks", "numcodecs.egg-info", ] +log_cli_level = "INFO" +xfail_strict = true [tool.cibuildwheel] environment = { DISABLE_NUMCODECS_AVX2=1 } [tool.cibuildwheel.macos] @@ -132,8 +137,8 @@ environment = { DISABLE_NUMCODECS_AVX2=1, DISABLE_NUMCODECS_SSE2=1 } line-length = 100 [tool.ruff.lint] -extend-select = [ "UP" ] -ignore = ["UP007"] +extend-select = [ "B", "I", "RUF", "UP" ] +ignore = [ "RUF001", "UP007" ] [tool.ruff.format] quote-style = "preserve" diff --git a/setup.py b/setup.py index 815224aa..464b6593 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,14 @@ import os import sys +from distutils import ccompiler +from distutils.command.clean import clean +from distutils.sysconfig import customize_compiler from glob import glob import cpuinfo from Cython.Distutils.build_ext import new_build_ext as build_ext from setuptools import Extension, setup from setuptools.errors import CCompilerError, ExecError, PlatformError -from distutils import ccompiler -from distutils.command.clean import clean -from distutils.sysconfig import customize_compiler # determine CPU support for SSE2 and AVX2 cpu_info = cpuinfo.get_cpu_info() @@ -333,14 +333,14 @@ def run(self): build_ext.run(self) except PlatformError as e: error(e) - raise BuildFailed() + raise BuildFailed() from e def build_extension(self, ext): try: build_ext.build_extension(self, ext) except ext_errors as e: error(e) - raise BuildFailed() + raise BuildFailed() from e class Sclean(clean):