-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor fix typo refactor wip update github action to trigger on pull requests refactor wip remove trace_info add recipy cleanup refactor refactor clean tasks raise when missing config added entry cli wip wip first / rename queues to tasks refactor wip wip secret config with no "." fix fix fix use tmp to download wip wip wip wip added heartbeat fix up up up
- Loading branch information
1 parent
722e152
commit e91f31d
Showing
22 changed files
with
1,399 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ name: Upload Python Package | |
on: | ||
|
||
push: {} | ||
|
||
pull_request: | ||
release: | ||
types: [created] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env python | ||
# (C) Copyright 2024 ECMWF. | ||
# | ||
# This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# In applying this licence, ECMWF does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an intergovernmental organisation | ||
# nor does it submit to any jurisdiction. | ||
# | ||
|
||
"""Command place holder. Delete when we have real commands. | ||
""" | ||
|
||
import logging | ||
import os | ||
|
||
from ..entry import CatalogueEntryNotFound | ||
from . import Command | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class BaseCommand(Command): | ||
internal = True | ||
timestamp = True | ||
|
||
def check_arguments(self, args): | ||
pass | ||
|
||
def is_path(self, name_or_path): | ||
return os.path.exists(name_or_path) | ||
|
||
def is_identifier(self, name_or_path): | ||
try: | ||
self.entry_class(key=name_or_path) | ||
return True | ||
except CatalogueEntryNotFound: | ||
return False | ||
|
||
def process_task(self, entry, args, k, func_name=None, /, **kwargs): | ||
""" | ||
Call the method `k` on the entry object. | ||
The args/kwargs given to the method are extracted from from the argument `k` in the `args` object. | ||
Additionally the argument `k` is casted to the correct type, | ||
depending on if this is a string, int, float, list or dict, or a boolean. | ||
The provided **kwargs are also passed to the method. | ||
The method name can be changed by providing the `func_name` argument. | ||
""" | ||
|
||
assert isinstance(k, str), k | ||
if func_name is None: | ||
func_name = k | ||
|
||
v = getattr(args, k) | ||
|
||
if v is None: | ||
return | ||
if v is True: | ||
LOG.debug(f"{entry.key} : Processing task {k}") | ||
return getattr(entry, func_name)(**kwargs) | ||
if v is False: | ||
return | ||
if isinstance(v, (str, int, float)): | ||
LOG.debug(f"{entry.key} : Processing task {k} with {v}") | ||
return getattr(entry, func_name)(v, **kwargs) | ||
if isinstance(v, list): | ||
v_str = ", ".join(str(x) for x in v) | ||
LOG.debug(f"{entry.key} : Processing task {k} with {v_str}") | ||
return getattr(entry, func_name)(*v, **kwargs) | ||
if isinstance(v, dict): | ||
v_str = ", ".join(f"{k_}={v_}" for k_, v_ in v.items()) | ||
LOG.debug(f"{entry.key} : Processing task {k} with {v_str}") | ||
return getattr(entry, func_name)(**v, **kwargs) | ||
raise ValueError(f"Invalid task {k}={v}. type(v)= {type(v)}") | ||
|
||
def run(self, args): | ||
LOG.debug(f"anemoi-registry args: {args}") | ||
name_or_path = args.NAME_OR_PATH | ||
entry = self.get_entry(name_or_path) | ||
self._run(entry, args) | ||
|
||
def get_entry(self, name_or_path): | ||
if self.is_path(name_or_path): | ||
LOG.info(f"Found local {self.kind} at {name_or_path}") | ||
return self.entry_class(path=name_or_path) | ||
|
||
if self.is_identifier(name_or_path): | ||
LOG.info(f"Processing {self.kind} with identifier '{name_or_path}'") | ||
return self.entry_class(key=name_or_path) | ||
|
||
def run_from_identifier(self, *args, **kwargs): | ||
raise NotImplementedError() | ||
|
||
def run_from_path(self, *args, **kwargs): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.