Skip to content

Commit

Permalink
Switch to blosc2; add Python 3.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Apr 19, 2024
1 parent 74a79e7 commit 1ae39ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Physics",
]

Expand All @@ -51,7 +52,7 @@ all = [
"asyncpg",
"appdirs",
"awkward >=2.4.3",
"blosc",
"blosc2",
"cachetools",
"cachey",
"click !=8.1.0",
Expand Down Expand Up @@ -108,7 +109,7 @@ array = [
client = [
"appdirs",
"awkward >=2.4.3",
"blosc",
"blosc2",
"click !=8.1.0",
"dask[array]",
"dask[dataframe]",
Expand All @@ -132,7 +133,7 @@ client = [
# These are used by the client/server to more efficiently compress.
# They fall back to gzip (which is slower) if these are not installed.
compression = [
"blosc",
"blosc2",
"lz4",
"zstandard",
]
Expand Down Expand Up @@ -233,7 +234,7 @@ server = [
"asgi-correlation-id",
"asyncpg",
"awkward >=2.4.3",
"blosc",
"blosc2",
"cachetools",
"cachey",
"click !=8.1.0",
Expand Down
6 changes: 3 additions & 3 deletions tiled/client/decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ..utils import modules_available

if modules_available("blosc"):
if modules_available("blosc2"):

class BloscDecoder:
def __init__(self):
Expand All @@ -18,13 +18,13 @@ def decode(self, data: bytes) -> bytes:

def flush(self) -> bytes:
# Hide this here to defer the numpy import that it triggers.
import blosc
import blosc2

if len(self._data) == 1:
(data,) = self._data
else:
data = b"".join(self._data)
return blosc.decompress(data)
return blosc2.decompress(data)

SUPPORTED_DECODERS["blosc"] = BloscDecoder

Expand Down
14 changes: 4 additions & 10 deletions tiled/media_type_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,8 @@ def close(self):
]:
compression_registry.register(media_type, "lz4", LZ4Buffer)

if modules_available("blosc"):
import blosc

# The choice of settings here is cribbed from distributed.protocol.compression.
n = blosc.set_nthreads(2)
if hasattr("blosc", "releasegil"):
blosc.set_releasegil(True)
blosc_settings = {"cname": "lz4", "clevel": 5}
if modules_available("blosc2"):
import blosc2

class BloscBuffer:
"""
Expand All @@ -352,9 +346,9 @@ def write(self, b):
if hasattr(b, "itemsize"):
# This could be memoryview or numpy.ndarray, for example.
# Blosc uses item-aware shuffling for improved results.
compressed = blosc.compress(b, typesize=b.itemsize, **blosc_settings)
compressed = blosc2.compress(b, typesize=b.itemsize)
else:
compressed = blosc.compress(b, **blosc_settings)
compressed = blosc2.compress(b)
self._file.write(compressed)

def close(self):
Expand Down

0 comments on commit 1ae39ce

Please sign in to comment.