simplezarr 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simplezarr/__init__.py +6 -0
- simplezarr/_version.py +227 -0
- simplezarr/codecs.py +509 -0
- simplezarr/misc.py +4 -0
- simplezarr/nodes.py +466 -0
- simplezarr/stores.py +504 -0
- simplezarr/utils/__init__.py +0 -0
- simplezarr/utils/chunkpool.py +447 -0
- simplezarr/utils/multiscale.py +255 -0
- simplezarr/utils/units.py +44 -0
- simplezarr-0.0.1.dist-info/METADATA +95 -0
- simplezarr-0.0.1.dist-info/RECORD +14 -0
- simplezarr-0.0.1.dist-info/WHEEL +4 -0
- simplezarr-0.0.1.dist-info/licenses/LICENSE +21 -0
simplezarr/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# ruff: noqa: F401
|
|
2
|
+
|
|
3
|
+
from ._version import version_info, __version__
|
|
4
|
+
from .stores import BaseStore, ReadableStore, WritableStore, ListableStore
|
|
5
|
+
from .stores import MemoryStore, LocalStore, WrapperStore, SlowStore
|
|
6
|
+
from .nodes import open_zarr, ZarrNode, ZarrGroup, ZarrArray
|
simplezarr/_version.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"""
|
|
2
|
+
_version.py v1.6
|
|
3
|
+
|
|
4
|
+
Simple version string management, using a hard-coded version string
|
|
5
|
+
for simplicity and compatibility, while adding git info at runtime.
|
|
6
|
+
See https://github.com/pygfx/_version for more info.
|
|
7
|
+
This code is subject to The Unlicense (public domain).
|
|
8
|
+
|
|
9
|
+
Any updates to this file should be done in https://github.com/pygfx/_version
|
|
10
|
+
|
|
11
|
+
Usage in short:
|
|
12
|
+
|
|
13
|
+
* Add this file to the root of your library (next to the `__init__.py`).
|
|
14
|
+
* On a new release, you just update the __version__.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
# ruff: noqa: RUF100, S310, PLR2004, D212, D400, D415, S603, BLE001, COM812
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
import subprocess
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
# This is the base version number, to be bumped before each release.
|
|
24
|
+
# The build system detects this definition when building a distribution.
|
|
25
|
+
__version__ = "0.0.1"
|
|
26
|
+
|
|
27
|
+
# Set this to your library name
|
|
28
|
+
project_name = "simplezarr"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
logger = logging.getLogger(project_name)
|
|
32
|
+
|
|
33
|
+
# Get whether this is a repo. If so, repo_dir is the path, otherwise None.
|
|
34
|
+
# .git is a dir in a normal repo and a file when in a submodule.
|
|
35
|
+
repo_dir = Path(__file__).parents[1]
|
|
36
|
+
repo_dir = repo_dir if repo_dir.joinpath(".git").exists() else None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_version() -> str:
|
|
40
|
+
"""Get the version string."""
|
|
41
|
+
try:
|
|
42
|
+
if repo_dir:
|
|
43
|
+
release, post, tag, dirty = get_version_info_from_git()
|
|
44
|
+
result = get_extended_version(release, post, tag, dirty)
|
|
45
|
+
|
|
46
|
+
# Warn if release does not match base_version.
|
|
47
|
+
# Can happen between bumping and tagging. And also when merging a
|
|
48
|
+
# version bump into a working branch, because we use --first-parent.
|
|
49
|
+
if release and release != base_version:
|
|
50
|
+
release2, _post, _tag, _dirty = get_version_info_from_git(
|
|
51
|
+
first_parent=False
|
|
52
|
+
)
|
|
53
|
+
if release2 != base_version:
|
|
54
|
+
warning(
|
|
55
|
+
f"{project_name} version from git ({release})"
|
|
56
|
+
f" and __version__ ({base_version}) don't match."
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return result
|
|
60
|
+
|
|
61
|
+
except Exception as err:
|
|
62
|
+
# Failsafe.
|
|
63
|
+
warning(f"Error getting refined version: {err}")
|
|
64
|
+
|
|
65
|
+
return base_version
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get_extended_version(release: str, post: str, tag: str, dirty: str) -> str:
|
|
69
|
+
"""Get an extended version string with information from git."""
|
|
70
|
+
# Start version string (__version__ string is leading).
|
|
71
|
+
version = base_version
|
|
72
|
+
labels = []
|
|
73
|
+
|
|
74
|
+
if release and release != base_version:
|
|
75
|
+
pre_label = "from_tag_" + release.replace(".", "_")
|
|
76
|
+
labels = [pre_label, f"post{post}", tag, dirty]
|
|
77
|
+
elif post and post != "0":
|
|
78
|
+
version += f".post{post}"
|
|
79
|
+
labels = [tag, dirty]
|
|
80
|
+
elif dirty:
|
|
81
|
+
labels = [tag, dirty]
|
|
82
|
+
else:
|
|
83
|
+
# If not post and not dirty, show 'clean' version without git tag.
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
# Compose final version (remove empty labels, e.g. when not dirty).
|
|
87
|
+
# Everything after the '+' is not sortable (does not get in version_info).
|
|
88
|
+
label_str = ".".join(label for label in labels if label)
|
|
89
|
+
if label_str:
|
|
90
|
+
version += "+" + label_str
|
|
91
|
+
return version
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def get_version_info_from_git(
|
|
95
|
+
*, first_parent: bool = True
|
|
96
|
+
) -> tuple[str, str, str, str]:
|
|
97
|
+
"""
|
|
98
|
+
Get (release, post, tag, dirty) from Git.
|
|
99
|
+
|
|
100
|
+
With `release` the version number from the latest tag, `post` the
|
|
101
|
+
number of commits since that tag, `tag` the git hash, and `dirty` a string
|
|
102
|
+
that is either empty or says 'dirty'.
|
|
103
|
+
"""
|
|
104
|
+
# Call out to Git.
|
|
105
|
+
command = ["git", "describe", "--long", "--always", "--tags", "--dirty"]
|
|
106
|
+
if first_parent:
|
|
107
|
+
command.append("--first-parent")
|
|
108
|
+
try:
|
|
109
|
+
p = subprocess.run(command, check=False, cwd=repo_dir, capture_output=True)
|
|
110
|
+
except Exception as e:
|
|
111
|
+
warning(f"Could not get {project_name} version: {e}")
|
|
112
|
+
p = None
|
|
113
|
+
|
|
114
|
+
# Parse the result into parts.
|
|
115
|
+
if p is None:
|
|
116
|
+
parts = ("", "", "unknown")
|
|
117
|
+
else:
|
|
118
|
+
output = p.stdout.decode(errors="ignore")
|
|
119
|
+
if p.returncode:
|
|
120
|
+
stderr = p.stderr.decode(errors="ignore")
|
|
121
|
+
warning(
|
|
122
|
+
f"Could not get {project_name} version.\n\nstdout: "
|
|
123
|
+
+ output
|
|
124
|
+
+ "\n\nstderr: "
|
|
125
|
+
+ stderr
|
|
126
|
+
)
|
|
127
|
+
parts = ("", "", "unknown")
|
|
128
|
+
else:
|
|
129
|
+
parts = output.strip().lstrip("v").split("-")
|
|
130
|
+
if len(parts) <= 2:
|
|
131
|
+
# No tags (and thus no post). Only git hash and maybe 'dirty'.
|
|
132
|
+
parts = ("", "", *parts)
|
|
133
|
+
|
|
134
|
+
# Return unpacked parts.
|
|
135
|
+
release = parts[0]
|
|
136
|
+
post = parts[1]
|
|
137
|
+
tag = parts[2]
|
|
138
|
+
dirty = "dirty" if len(parts) > 3 else ""
|
|
139
|
+
return release, post, tag, dirty
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def version_to_tuple(v: str) -> tuple:
|
|
143
|
+
parts = []
|
|
144
|
+
for part in v.split("+", maxsplit=1)[0].split("."):
|
|
145
|
+
if not part:
|
|
146
|
+
pass
|
|
147
|
+
elif part.startswith("post"):
|
|
148
|
+
try:
|
|
149
|
+
parts.extend(["post", int(part[4:])])
|
|
150
|
+
except ValueError:
|
|
151
|
+
parts.append(part)
|
|
152
|
+
else:
|
|
153
|
+
try:
|
|
154
|
+
parts.append(int(part))
|
|
155
|
+
except ValueError:
|
|
156
|
+
parts.append(part)
|
|
157
|
+
return tuple(parts)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def warning(m: str) -> None:
|
|
161
|
+
logger.warning(m)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# Apply the versioning.
|
|
165
|
+
base_version = __version__
|
|
166
|
+
__version__ = get_version()
|
|
167
|
+
version_info = version_to_tuple(__version__)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
# The CLI part.
|
|
171
|
+
|
|
172
|
+
CLI_USAGE = """
|
|
173
|
+
_version.py
|
|
174
|
+
|
|
175
|
+
help - Show this message.
|
|
176
|
+
version - Show the current version.
|
|
177
|
+
bump VERSION - Bump the __version__ to the given VERSION.
|
|
178
|
+
update - Self-update the _version.py module by downloading the
|
|
179
|
+
reference code and replacing version number and project name.
|
|
180
|
+
""".lstrip()
|
|
181
|
+
|
|
182
|
+
if __name__ == "__main__":
|
|
183
|
+
import sys
|
|
184
|
+
import urllib.request
|
|
185
|
+
|
|
186
|
+
def prnt(m: str) -> None:
|
|
187
|
+
sys.stdout.write(m + "\n")
|
|
188
|
+
sys.stdout.flush()
|
|
189
|
+
|
|
190
|
+
_, *args = sys.argv
|
|
191
|
+
this_file = Path(__file__)
|
|
192
|
+
|
|
193
|
+
if not args or args[0] == "version":
|
|
194
|
+
prnt(f"{project_name} v{__version__}")
|
|
195
|
+
|
|
196
|
+
elif args[0] == "bump":
|
|
197
|
+
if len(args) != 2:
|
|
198
|
+
sys.exit("Expected a version number to bump to.")
|
|
199
|
+
new_version = args[1].lstrip("v") # allow '1.2.3' and 'v1.2.3'
|
|
200
|
+
if new_version.count(".") != 2:
|
|
201
|
+
sys.exit("Expected two dots in new version string.")
|
|
202
|
+
if not all(s.isnumeric() for s in new_version.split(".")):
|
|
203
|
+
sys.exit("Expected only numbers in new version string.")
|
|
204
|
+
with this_file.open("rb") as f:
|
|
205
|
+
text = ref_text = f.read().decode()
|
|
206
|
+
text = text.replace(base_version, new_version, 1)
|
|
207
|
+
with this_file.open("wb") as f:
|
|
208
|
+
f.write(text.encode())
|
|
209
|
+
prnt(f"Bumped version from '{base_version}' to '{new_version}'.")
|
|
210
|
+
|
|
211
|
+
elif args[0] == "update":
|
|
212
|
+
u = "https://raw.githubusercontent.com/pygfx/_version/main/_version.py"
|
|
213
|
+
with urllib.request.urlopen(u) as f:
|
|
214
|
+
text = ref_text = f.read().decode()
|
|
215
|
+
text = text.replace("0.0.0", base_version, 1)
|
|
216
|
+
text = text.replace("PROJECT_NAME", project_name, 1)
|
|
217
|
+
with this_file.open("wb") as f:
|
|
218
|
+
f.write(text.encode())
|
|
219
|
+
prnt("Updated to the latest _version.py.")
|
|
220
|
+
|
|
221
|
+
elif args[0].lstrip("-") in ["h", "help"]:
|
|
222
|
+
prnt(CLI_USAGE)
|
|
223
|
+
|
|
224
|
+
else:
|
|
225
|
+
prnt(f"Unknown command for _version.py: {args[0]!r}")
|
|
226
|
+
prnt("Use ``python _version.py help`` to see a list of options.")
|
|
227
|
+
sys.exit(1)
|