Skip to content

Commit

Permalink
Deprecate blosc helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Dec 3, 2024
1 parent d8a0a55 commit e1179a3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 71 deletions.
6 changes: 0 additions & 6 deletions docs/compression/blosc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ Blosc
Helper functions
----------------

.. autofunction:: init
.. autofunction:: destroy
.. autofunction:: compname_to_compcode
.. autofunction:: list_compressors
.. autofunction:: get_nthreads
.. autofunction:: set_nthreads
.. autofunction:: cbuffer_sizes
.. autofunction:: cbuffer_complib
.. autofunction:: cbuffer_metainfo
.. autofunction:: compress
.. autofunction:: decompress
.. autofunction:: decompress_partial
26 changes: 19 additions & 7 deletions numcodecs/blosc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import threading
import multiprocessing
import os
from deprecated import deprecated


from cpython.buffer cimport PyBUF_ANY_CONTIGUOUS, PyBUF_WRITEABLE
Expand Down Expand Up @@ -95,24 +96,31 @@ def get_mutex():
_importer_pid = os.getpid()


def init():
def _init():
"""Initialize the Blosc library environment."""
blosc_init()

init = deprecated(_init)

def destroy():

def _destroy():
"""Destroy the Blosc library environment."""
blosc_destroy()


def compname_to_compcode(cname):
destroy = deprecated(_destroy)


def _compname_to_compcode(cname):
"""Return the compressor code associated with the compressor name. If the compressor
name is not recognized, or there is not support for it in this build, -1 is returned
instead."""
if isinstance(cname, str):
cname = cname.encode('ascii')
return blosc_compname_to_compcode(cname)

compname_to_compcode = deprecated(_compname_to_compcode)


def list_compressors():
"""Get a list of compressors supported in the current build."""
Expand All @@ -133,7 +141,7 @@ def set_nthreads(int nthreads):
return blosc_set_nthreads(nthreads)


def cbuffer_sizes(source):
def _cbuffer_sizes(source):
"""Return information about a compressed buffer, namely the number of uncompressed
bytes (`nbytes`) and compressed (`cbytes`). It also returns the `blocksize` (which
is used internally for doing the compression by blocks).
Expand All @@ -160,6 +168,7 @@ def cbuffer_sizes(source):

return nbytes, cbytes, blocksize

cbuffer_sizes = deprecated(_cbuffer_sizes)

def cbuffer_complib(source):
"""Return the name of the compression library used to compress `source`."""
Expand All @@ -180,7 +189,7 @@ def cbuffer_complib(source):
return complib


def cbuffer_metainfo(source):
def _cbuffer_metainfo(source):
"""Return some meta-information about the compressed buffer in `source`, including
the typesize, whether the shuffle or bit-shuffle filters were used, and the
whether the buffer was memcpyed.
Expand Down Expand Up @@ -217,11 +226,13 @@ def cbuffer_metainfo(source):

return typesize, shuffle, memcpyed

cbuffer_metainfo = deprecated(_cbuffer_metainfo)

def err_bad_cname(cname):
def _err_bad_cname(cname):
raise ValueError('bad compressor or compressor not supported: %r; expected one of '
'%s' % (cname, list_compressors()))

err_bad_cname = deprecated(_err_bad_cname)

def compress(source, char* cname, int clevel, int shuffle=SHUFFLE,
int blocksize=AUTOBLOCKS):
Expand Down Expand Up @@ -405,7 +416,7 @@ def decompress(source, dest=None):
return dest


def decompress_partial(source, start, nitems, dest=None):
def _decompress_partial(source, start, nitems, dest=None):
"""**Experimental**
Decompress data of only a part of a buffer.
Expand Down Expand Up @@ -478,6 +489,7 @@ def decompress_partial(source, start, nitems, dest=None):

return dest

decompress_partial = deprecated(_decompress_partial)

# set the value of this variable to True or False to override the
# default adaptive behaviour
Expand Down
98 changes: 40 additions & 58 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ name = "numcodecs"
description = """
A Python package providing buffer compression and transformation codecs \
for use in data storage and communication applications."""
readme = "README.rst"
dependencies = [
"numpy>=1.24",
]
readme = "README.rst"
dependencies = ["numpy>=1.24", "deprecated"]
requires-python = ">=3.11"
dynamic = [
"version",
]
dynamic = ["version"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand All @@ -33,9 +29,7 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
]
maintainers = [
{ name = "Alistair Miles", email = "[email protected]" },
]
maintainers = [{ name = "Alistair Miles", email = "[email protected]" }]
license = { text = "MIT" }

[project.urls]
Expand All @@ -45,33 +39,13 @@ Documentation = "https://numcodecs.readthedocs.io/"
Homepage = "https://github.com/zarr-developers/numcodecs"

[project.optional-dependencies]
docs = [
"sphinx",
"sphinx-issues",
"pydata-sphinx-theme",
"numpydoc",
]
test = [
"coverage",
"pytest",
"pytest-cov",
]
test_extras = [
"importlib_metadata",
]
msgpack = [
"msgpack",
]
zfpy = [
"zfpy>=1.0.0",
"numpy<2.0.0",
]
pcodec = [
"pcodec>=0.2,<0.3",
]
crc32c = [
"crc32c>=2.7",
]
docs = ["sphinx", "sphinx-issues", "pydata-sphinx-theme", "numpydoc"]
test = ["coverage", "pytest", "pytest-cov"]
test_extras = ["importlib_metadata"]
msgpack = ["msgpack"]
zfpy = ["zfpy>=1.0.0", "numpy<2.0.0"]
pcodec = ["pcodec>=0.2,<0.3"]
crc32c = ["crc32c>=2.7"]

[project.entry-points."zarr.codecs"]
"numcodecs.blosc" = "numcodecs.zarr3:Blosc"
Expand All @@ -98,14 +72,14 @@ crc32c = [

[tool.setuptools]
license-files = ["LICENSE.txt"]
package-dir = {"" = "."}
package-dir = { "" = "." }
packages = ["numcodecs", "numcodecs.tests"]
zip-safe = false

[tool.setuptools.package-data]
numcodecs = [
"tests/package_with_entrypoint/__init__.py",
"tests/package_with_entrypoint-0.1.dist-info/entry_points.txt"
"tests/package_with_entrypoint-0.1.dist-info/entry_points.txt",
]

[tool.setuptools_scm]
Expand All @@ -118,13 +92,25 @@ skip = "./.git,fixture"
ignore-words-list = "ba, compiletime, hist, nd, unparseable"

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"pragma: ${PY_MAJOR_VERSION} no cover",
]
exclude_lines = ["pragma: no cover", "pragma: ${PY_MAJOR_VERSION} no cover"]

[tool.repo-review]
ignore = ["PY005", "PY007", "PP302", "PP308", "PP309", "GH103", "GH212", "PC111", "PC140", "PC160", "PC170", "PC180", "MY100", "RF103"]
ignore = [
"PY005",
"PY007",
"PP302",
"PP308",
"PP309",
"GH103",
"GH212",
"PC111",
"PC140",
"PC160",
"PC170",
"PC180",
"MY100",
"RF103",
]

[tool.pytest.ini_options]
addopts = "-ra --strict-config --strict-markers --cov=numcodecs --cov-report xml --doctest-modules --doctest-glob=*.pyx"
Expand All @@ -133,9 +119,7 @@ doctest_optionflags = [
"ELLIPSIS",
"IGNORE_EXCEPTION_DETAIL",
]
testpaths = [
"numcodecs/tests",
]
testpaths = ["numcodecs/tests"]
norecursedirs = [
".git",
".github",
Expand All @@ -150,17 +134,15 @@ norecursedirs = [
]
log_cli_level = "INFO"
xfail_strict = true
filterwarnings = [
"error",
]
filterwarnings = ["error"]

[tool.cibuildwheel]
environment = { DISABLE_NUMCODECS_AVX2=1 }
environment = { DISABLE_NUMCODECS_AVX2 = 1 }
[tool.cibuildwheel.macos]
environment = { MACOSX_DEPLOYMENT_TARGET=10.9, DISABLE_NUMCODECS_AVX2=1, CFLAGS="$CFLAGS -Wno-implicit-function-declaration" }
environment = { MACOSX_DEPLOYMENT_TARGET = 10.9, DISABLE_NUMCODECS_AVX2 = 1, CFLAGS = "$CFLAGS -Wno-implicit-function-declaration" }
[[tool.cibuildwheel.overrides]]
select = "*-macosx_arm64"
environment = { DISABLE_NUMCODECS_AVX2=1, DISABLE_NUMCODECS_SSE2=1 }
environment = { DISABLE_NUMCODECS_AVX2 = 1, DISABLE_NUMCODECS_SSE2 = 1 }

[tool.ruff]
line-length = 100
Expand Down Expand Up @@ -189,13 +171,13 @@ ignore = [
"FURB101",
"FURB103",
"PT001",
"PT004", # deprecated
"PT005", # deprecated
"PT004", # deprecated
"PT005", # deprecated
"PT011",
"RUF001",
"RUF001",
"UP007",
"UP027", # deprecated
"UP038", # https://github.com/astral-sh/ruff/issues/7871
"UP027", # deprecated
"UP038", # https://github.com/astral-sh/ruff/issues/7871
]

[tool.ruff.format]
Expand Down

0 comments on commit e1179a3

Please sign in to comment.