Skip to content

Commit

Permalink
update registry
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Oct 31, 2024
1 parent 26c5ee8 commit bcc7cfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Keep it human-readable, your future self will thank you!

### Added
- Add supporting_arrays to checkpoints
- Add factories registry

## [0.4.1](https://github.com/ecmwf/anemoi-utils/compare/0.4.0...0.4.1) - 2024-10-23

Expand Down
10 changes: 9 additions & 1 deletion src/anemoi/utils/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def __init__(self, package):
self.registered = {}
self.kind = package.split(".")[-1]

def register(self, name: str, factory: callable):
def register(self, name: str, factory: callable = None):

# Decorator version
if factory is None:
return lambda f: self.register(name, f)

self.registered[name] = factory

def _load(self, file):
Expand Down Expand Up @@ -77,3 +82,6 @@ def lookup(self, name: str) -> callable:
def create(self, name: str, *args, **kwargs):
factory = self.lookup(name)
return factory(*args, **kwargs)

def __call__(self, name: str, *args, **kwargs):
return self.create(name, *args, **kwargs)

0 comments on commit bcc7cfa

Please sign in to comment.