-
-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy path__init__.py
More file actions
187 lines (165 loc) · 4.33 KB
/
__init__.py
File metadata and controls
187 lines (165 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import functools
import logging
from typing import Literal
from zarr._version import version as __version__
from zarr.api.synchronous import (
array,
consolidate_metadata,
copy,
copy_all,
copy_store,
create,
create_array,
create_group,
create_hierarchy,
empty,
empty_like,
from_array,
full,
full_like,
group,
load,
ones,
ones_like,
open,
open_array,
open_consolidated,
open_group,
open_like,
save,
save_array,
save_group,
tree,
zeros,
zeros_like,
)
from zarr.core.array import Array, AsyncArray
from zarr.core.chunk_grids import ChunksType, RectilinearChunks, RegularChunks
from zarr.core.config import config
from zarr.core.group import AsyncGroup, Group
# in case setuptools scm screw up and find version to be 0.0.0
assert not __version__.startswith("0.0.0")
_logger = logging.getLogger(__name__)
def print_debug_info() -> None:
"""
Print version info for use in bug reports.
"""
import platform
from importlib.metadata import version
def print_packages(packages: list[str]) -> None:
not_installed = []
for package in packages:
try:
print(f"{package}: {version(package)}")
except ModuleNotFoundError:
not_installed.append(package)
if not_installed:
print("\n**Not Installed:**")
for package in not_installed:
print(package)
required = [
"packaging",
"numpy",
"numcodecs",
"typing_extensions",
"donfig",
]
optional = [
"botocore",
"cupy-cuda12x",
"fsspec",
"numcodecs",
"s3fs",
"gcsfs",
"universal-pathlib",
"rich",
"obstore",
]
print(f"platform: {platform.platform()}")
print(f"python: {platform.python_version()}")
print(f"zarr: {__version__}\n")
print("**Required dependencies:**")
print_packages(required)
print("\n**Optional dependencies:**")
print_packages(optional)
# The decorator ensures this always returns the same handler (and it is only
# attached once).
@functools.cache
def _ensure_handler() -> logging.Handler:
"""
The first time this function is called, attach a `StreamHandler` using the
same format as `logging.basicConfig` to the Zarr-Python root logger.
Return this handler every time this function is called.
"""
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
_logger.addHandler(handler)
return handler
def set_log_level(
level: Literal["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
) -> None:
"""Set the logging level for Zarr-Python.
Zarr-Python uses the standard library `logging` framework under the root
logger 'zarr'. This is a helper function to:
- set Zarr-Python's root logger level
- set the root logger handler's level, creating the handler
if it does not exist yet
Parameters
----------
level : str
The logging level to set.
"""
_logger.setLevel(level)
_ensure_handler().setLevel(level)
def set_format(log_format: str) -> None:
"""Set the format of logging messages from Zarr-Python.
Zarr-Python uses the standard library `logging` framework under the root
logger 'zarr'. This sets the format of log messages from the root logger's StreamHandler.
Parameters
----------
log_format : str
A string determining the log format (as defined in the standard library's `logging` module
for logging.Formatter)
"""
_ensure_handler().setFormatter(logging.Formatter(fmt=log_format))
__all__ = [
"Array",
"AsyncArray",
"AsyncGroup",
"ChunksType",
"Group",
"RectilinearChunks",
"RegularChunks",
"__version__",
"array",
"config",
"consolidate_metadata",
"copy",
"copy_all",
"copy_store",
"create",
"create_array",
"create_group",
"create_hierarchy",
"empty",
"empty_like",
"from_array",
"full",
"full_like",
"group",
"load",
"ones",
"ones_like",
"open",
"open_array",
"open_consolidated",
"open_group",
"open_like",
"print_debug_info",
"save",
"save_array",
"save_group",
"tree",
"zeros",
"zeros_like",
]