anemoi-utils 0.4.35__py3-none-any.whl → 0.4.37__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.
Potentially problematic release.
This version of anemoi-utils might be problematic. Click here for more details.
- anemoi/utils/_environment.py +3 -0
- anemoi/utils/_version.py +2 -2
- anemoi/utils/checkpoints.py +47 -32
- anemoi/utils/cli.py +38 -5
- anemoi/utils/commands/metadata.py +6 -4
- anemoi/utils/commands/transfer.py +6 -2
- anemoi/utils/config.py +0 -6
- anemoi/utils/logs.py +34 -6
- anemoi/utils/mlflow/auth.py +154 -18
- anemoi/utils/registry.py +55 -1
- anemoi/utils/remote/__init__.py +1 -3
- anemoi/utils/remote/s3.py +489 -543
- {anemoi_utils-0.4.35.dist-info → anemoi_utils-0.4.37.dist-info}/METADATA +3 -2
- {anemoi_utils-0.4.35.dist-info → anemoi_utils-0.4.37.dist-info}/RECORD +18 -18
- {anemoi_utils-0.4.35.dist-info → anemoi_utils-0.4.37.dist-info}/WHEEL +0 -0
- {anemoi_utils-0.4.35.dist-info → anemoi_utils-0.4.37.dist-info}/entry_points.txt +0 -0
- {anemoi_utils-0.4.35.dist-info → anemoi_utils-0.4.37.dist-info}/licenses/LICENSE +0 -0
- {anemoi_utils-0.4.35.dist-info → anemoi_utils-0.4.37.dist-info}/top_level.txt +0 -0
anemoi/utils/registry.py
CHANGED
|
@@ -97,6 +97,8 @@ class Registry(Generic[T]):
|
|
|
97
97
|
self.package = package
|
|
98
98
|
self.__registered = {}
|
|
99
99
|
self._sources = {}
|
|
100
|
+
self._aliases = {}
|
|
101
|
+
self._warnings = set()
|
|
100
102
|
self.kind = package.split(".")[-1]
|
|
101
103
|
self.key = key
|
|
102
104
|
self.api_version = api_version
|
|
@@ -118,7 +120,9 @@ class Registry(Generic[T]):
|
|
|
118
120
|
"""
|
|
119
121
|
return _BY_KIND.get(kind)
|
|
120
122
|
|
|
121
|
-
def register(
|
|
123
|
+
def register(
|
|
124
|
+
self, name: str, factory: Callable | None = None, source: Any | None = None, aliases: list[str] | None = None
|
|
125
|
+
) -> Wrapper | None:
|
|
122
126
|
"""Register a factory with the registry.
|
|
123
127
|
|
|
124
128
|
Parameters
|
|
@@ -129,6 +133,8 @@ class Registry(Generic[T]):
|
|
|
129
133
|
The factory to register, by default None.
|
|
130
134
|
source : Any, optional
|
|
131
135
|
The source of the factory, by default None.
|
|
136
|
+
aliases : list of str, optional
|
|
137
|
+
Aliases for the factory, by default None.
|
|
132
138
|
|
|
133
139
|
Returns
|
|
134
140
|
-------
|
|
@@ -136,7 +142,13 @@ class Registry(Generic[T]):
|
|
|
136
142
|
A wrapper if the factory is None, otherwise None.
|
|
137
143
|
"""
|
|
138
144
|
|
|
145
|
+
aliases = aliases or []
|
|
146
|
+
|
|
139
147
|
name = name.replace("_", "-")
|
|
148
|
+
assert (
|
|
149
|
+
name not in self._aliases
|
|
150
|
+
), f"'{name}' is already registered for '{self._aliases[name]}' in {self.package}"
|
|
151
|
+
assert name not in aliases, f"'{name}' cannot be an alias for itself in {self.package}"
|
|
140
152
|
|
|
141
153
|
if factory is None:
|
|
142
154
|
# This happens when the @register decorator is used
|
|
@@ -150,6 +162,15 @@ class Registry(Generic[T]):
|
|
|
150
162
|
warnings.warn(f"Existing: {self._sources[name]}")
|
|
151
163
|
warnings.warn(f"New: {source}")
|
|
152
164
|
|
|
165
|
+
for alias in aliases:
|
|
166
|
+
assert (
|
|
167
|
+
alias not in self.__registered
|
|
168
|
+
), f"Alias '{alias}' is already registered as a factory in {self.package}"
|
|
169
|
+
alias = alias.replace("_", "-")
|
|
170
|
+
if alias in self._aliases:
|
|
171
|
+
warnings.warn(f"Alias '{alias}' is already registered for '{self._aliases[alias]}' in {self.package}")
|
|
172
|
+
self._aliases[alias] = name
|
|
173
|
+
|
|
153
174
|
self.__registered[name] = factory
|
|
154
175
|
self._sources[name] = source
|
|
155
176
|
|
|
@@ -188,6 +209,7 @@ class Registry(Generic[T]):
|
|
|
188
209
|
"""
|
|
189
210
|
|
|
190
211
|
name = name.replace("_", "-")
|
|
212
|
+
name = self._unalias(name)
|
|
191
213
|
|
|
192
214
|
ok = name in self.factories
|
|
193
215
|
if not ok:
|
|
@@ -213,6 +235,7 @@ class Registry(Generic[T]):
|
|
|
213
235
|
"""
|
|
214
236
|
|
|
215
237
|
name = name.replace("_", "-")
|
|
238
|
+
name = self._unalias(name)
|
|
216
239
|
|
|
217
240
|
if return_none:
|
|
218
241
|
return self.factories.get(name)
|
|
@@ -305,6 +328,7 @@ class Registry(Generic[T]):
|
|
|
305
328
|
"""
|
|
306
329
|
|
|
307
330
|
name = name.replace("_", "-")
|
|
331
|
+
name = self._unalias(name)
|
|
308
332
|
|
|
309
333
|
factory = self.lookup(name)
|
|
310
334
|
return factory(*args, **kwargs)
|
|
@@ -352,3 +376,33 @@ class Registry(Generic[T]):
|
|
|
352
376
|
raise ValueError(
|
|
353
377
|
f"Entry '{config}' must either be a string, a dictionary with a single entry, or a dictionary with a '{self.key}' key"
|
|
354
378
|
)
|
|
379
|
+
|
|
380
|
+
def _unalias(self, name: str) -> str:
|
|
381
|
+
"""Resolve an alias to its canonical name.
|
|
382
|
+
|
|
383
|
+
Parameters
|
|
384
|
+
----------
|
|
385
|
+
name : str
|
|
386
|
+
The name to resolve.
|
|
387
|
+
|
|
388
|
+
Returns
|
|
389
|
+
-------
|
|
390
|
+
str
|
|
391
|
+
The canonical name.
|
|
392
|
+
"""
|
|
393
|
+
canonical = self._aliases.get(name, name)
|
|
394
|
+
if canonical != name:
|
|
395
|
+
warnings.warn(
|
|
396
|
+
f"Alias '{name}' for '{canonical}' in {self.package} is deprecated and will be removed in a future version.",
|
|
397
|
+
category=DeprecationWarning,
|
|
398
|
+
# stacklevel=2,
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
return canonical
|
|
402
|
+
|
|
403
|
+
def aliases(self):
|
|
404
|
+
"""Get the aliases."""
|
|
405
|
+
result = {}
|
|
406
|
+
for alias, name in self._aliases.items():
|
|
407
|
+
result.setdefault(name, []).append(alias)
|
|
408
|
+
return result
|
anemoi/utils/remote/__init__.py
CHANGED
|
@@ -77,13 +77,11 @@ class Loader:
|
|
|
77
77
|
progress : callable, optional
|
|
78
78
|
A callable for progress reporting, by default None.
|
|
79
79
|
"""
|
|
80
|
-
assert verbosity == 1, verbosity
|
|
80
|
+
# assert verbosity == 1, verbosity
|
|
81
81
|
|
|
82
82
|
if progress is None:
|
|
83
83
|
progress = _ignore
|
|
84
84
|
|
|
85
|
-
# from boto3.s3.transfer import TransferConfig
|
|
86
|
-
# config = TransferConfig(use_threads=False)
|
|
87
85
|
config = None
|
|
88
86
|
with concurrent.futures.ThreadPoolExecutor(max_workers=threads) as executor:
|
|
89
87
|
try:
|