File tree Expand file tree Collapse file tree 4 files changed +58
-9
lines changed
package_with_entrypoint-0.1.dist-info Expand file tree Collapse file tree 4 files changed +58
-9
lines changed Original file line number Diff line number Diff line change 12
12
__lazy_load_codecs : Dict [str , EntryPoint ] = {}
13
13
14
14
15
- def _collect_entrypoints () -> None :
15
+ def _collect_entrypoints () -> Dict [ str , EntryPoint ] :
16
16
entry_points = get_entry_points ()
17
- if hasattr (entry_points , "select" ):
18
- # If entry_points() has a select method, use that. Python 3.10+
19
- for e in entry_points .select (group = "zarr.codecs" ):
20
- __lazy_load_codecs [e .name ] = e
21
- else :
22
- # Otherwise, fallback to using get
23
- for e in entry_points .get ("zarr.codecs" , []):
24
- __lazy_load_codecs [e .name ] = e
17
+ for e in entry_points .select (group = "zarr.codecs" ):
18
+ __lazy_load_codecs [e .name ] = e
19
+ return __lazy_load_codecs
25
20
26
21
27
22
def register_codec (key : str , codec_cls : Type [Codec ]) -> None :
Original file line number Diff line number Diff line change
1
+ [zarr.codecs]
2
+ test = package_with_entrypoint:TestCodec
Original file line number Diff line number Diff line change
1
+ from numpy import ndarray
2
+ from zarr .abc .codec import ArrayBytesCodec
3
+ from zarr .common import ArraySpec , BytesLike
4
+ from zarr .config import RuntimeConfiguration
5
+
6
+
7
+ class TestCodec (ArrayBytesCodec ):
8
+ is_fixed_size = True
9
+
10
+ async def encode (
11
+ self ,
12
+ chunk_array : ndarray ,
13
+ chunk_spec : ArraySpec ,
14
+ runtime_configuration : RuntimeConfiguration ,
15
+ ) -> BytesLike | None :
16
+ pass
17
+
18
+ async def decode (
19
+ self ,
20
+ chunk_bytes : BytesLike ,
21
+ chunk_spec : ArraySpec ,
22
+ runtime_configuration : RuntimeConfiguration ,
23
+ ) -> ndarray :
24
+ pass
25
+
26
+ def compute_encoded_size (self , input_byte_length : int , chunk_spec : ArraySpec ) -> int :
27
+ return input_byte_length
Original file line number Diff line number Diff line change
1
+ import os .path
2
+ import sys
3
+
4
+ import pytest
5
+
6
+ import zarr .codecs .registry
7
+
8
+
9
+ here = os .path .abspath (os .path .dirname (__file__ ))
10
+
11
+
12
+ @pytest .fixture ()
13
+ def set_path ():
14
+ sys .path .append (here )
15
+ zarr .codecs .registry ._collect_entrypoints ()
16
+ yield
17
+ sys .path .remove (here )
18
+ entry_points = zarr .codecs .registry ._collect_entrypoints ()
19
+ entry_points .pop ("test" )
20
+
21
+
22
+ @pytest .mark .usefixtures ("set_path" )
23
+ def test_entrypoint_codec ():
24
+ cls = zarr .codecs .registry .get_codec_class ("test" )
25
+ assert cls .__name__ == "TestCodec"
You can’t perform that action at this time.
0 commit comments