anemoi-utils 0.2.0__py3-none-any.whl → 0.2.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.
Potentially problematic release.
This version of anemoi-utils might be problematic. Click here for more details.
- anemoi/utils/__main__.py +6 -1
- anemoi/utils/_version.py +2 -2
- anemoi/utils/cli.py +126 -0
- {anemoi_utils-0.2.0.dist-info → anemoi_utils-0.2.1.dist-info}/METADATA +1 -1
- {anemoi_utils-0.2.0.dist-info → anemoi_utils-0.2.1.dist-info}/RECORD +9 -8
- {anemoi_utils-0.2.0.dist-info → anemoi_utils-0.2.1.dist-info}/LICENSE +0 -0
- {anemoi_utils-0.2.0.dist-info → anemoi_utils-0.2.1.dist-info}/WHEEL +0 -0
- {anemoi_utils-0.2.0.dist-info → anemoi_utils-0.2.1.dist-info}/entry_points.txt +0 -0
- {anemoi_utils-0.2.0.dist-info → anemoi_utils-0.2.1.dist-info}/top_level.txt +0 -0
anemoi/utils/__main__.py
CHANGED
|
@@ -20,7 +20,7 @@ from .commands import COMMANDS
|
|
|
20
20
|
LOG = logging.getLogger(__name__)
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def
|
|
23
|
+
def create_parser():
|
|
24
24
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
25
25
|
|
|
26
26
|
parser.add_argument(
|
|
@@ -41,6 +41,11 @@ def main():
|
|
|
41
41
|
command_parser = subparsers.add_parser(name, help=command.__doc__)
|
|
42
42
|
command.add_arguments(command_parser)
|
|
43
43
|
|
|
44
|
+
return parser
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main():
|
|
48
|
+
parser = create_parser()
|
|
44
49
|
args = parser.parse_args()
|
|
45
50
|
|
|
46
51
|
if args.version:
|
anemoi/utils/_version.py
CHANGED
anemoi/utils/cli.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# (C) Copyright 2024 European Centre for Medium-Range Weather Forecasts.
|
|
2
|
+
# This software is licensed under the terms of the Apache Licence Version 2.0
|
|
3
|
+
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
|
4
|
+
# In applying this licence, ECMWF does not waive the privileges and immunities
|
|
5
|
+
# granted to it by virtue of its status as an intergovernmental organisation
|
|
6
|
+
# nor does it submit to any jurisdiction.
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import importlib
|
|
10
|
+
import logging
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
import traceback
|
|
14
|
+
|
|
15
|
+
LOG = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Command:
|
|
19
|
+
def run(self, args):
|
|
20
|
+
raise NotImplementedError(f"Command not implemented: {args.command}")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def make_parser(description, commands):
|
|
24
|
+
parser = argparse.ArgumentParser(
|
|
25
|
+
description=description,
|
|
26
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"--version",
|
|
31
|
+
"-V",
|
|
32
|
+
action="store_true",
|
|
33
|
+
help="show the version and exit",
|
|
34
|
+
)
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"--debug",
|
|
37
|
+
"-d",
|
|
38
|
+
action="store_true",
|
|
39
|
+
help="Debug mode",
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
subparsers = parser.add_subparsers(help="commands:", dest="command")
|
|
43
|
+
for name, command in commands.items():
|
|
44
|
+
command_parser = subparsers.add_parser(name, help=command.__doc__)
|
|
45
|
+
command.add_arguments(command_parser)
|
|
46
|
+
|
|
47
|
+
return parser
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Failed(Command):
|
|
51
|
+
def __init__(self, name, error):
|
|
52
|
+
self.name = name
|
|
53
|
+
self.error = error
|
|
54
|
+
|
|
55
|
+
def add_arguments(self, command_parser):
|
|
56
|
+
command_parser.add_argument("x", nargs=argparse.REMAINDER)
|
|
57
|
+
|
|
58
|
+
def run(self, args):
|
|
59
|
+
print(f"Command '{self.name}' not available: {self.error}")
|
|
60
|
+
sys.exit(1)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def register_commands(here, package, select, fail=None):
|
|
64
|
+
result = {}
|
|
65
|
+
not_available = {}
|
|
66
|
+
|
|
67
|
+
for p in os.listdir(here):
|
|
68
|
+
full = os.path.join(here, p)
|
|
69
|
+
if p.startswith("_"):
|
|
70
|
+
continue
|
|
71
|
+
if not (p.endswith(".py") or (os.path.isdir(full) and os.path.exists(os.path.join(full, "__init__.py")))):
|
|
72
|
+
continue
|
|
73
|
+
|
|
74
|
+
name, _ = os.path.splitext(p)
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
imported = importlib.import_module(
|
|
78
|
+
f".{name}",
|
|
79
|
+
package=package,
|
|
80
|
+
)
|
|
81
|
+
except ImportError as e:
|
|
82
|
+
not_available[name] = e
|
|
83
|
+
continue
|
|
84
|
+
|
|
85
|
+
obj = select(imported)
|
|
86
|
+
if obj is not None:
|
|
87
|
+
result[name] = obj
|
|
88
|
+
|
|
89
|
+
for name, e in not_available.items():
|
|
90
|
+
if fail is None:
|
|
91
|
+
pass
|
|
92
|
+
if callable(fail):
|
|
93
|
+
result[name] = fail(name, e)
|
|
94
|
+
|
|
95
|
+
return result
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def cli_main(version, description, commands):
|
|
99
|
+
parser = make_parser(description, commands)
|
|
100
|
+
args = parser.parse_args()
|
|
101
|
+
|
|
102
|
+
if args.version:
|
|
103
|
+
print(version)
|
|
104
|
+
return
|
|
105
|
+
|
|
106
|
+
if args.command is None:
|
|
107
|
+
parser.print_help()
|
|
108
|
+
return
|
|
109
|
+
|
|
110
|
+
cmd = commands[args.command]
|
|
111
|
+
|
|
112
|
+
logging.basicConfig(
|
|
113
|
+
format="%(asctime)s %(levelname)s %(message)s",
|
|
114
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
115
|
+
level=logging.DEBUG if args.debug else logging.INFO,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
try:
|
|
119
|
+
cmd.run(args)
|
|
120
|
+
except ValueError as e:
|
|
121
|
+
traceback.print_exc()
|
|
122
|
+
LOG.error("\n💣 %s", str(e).lstrip())
|
|
123
|
+
LOG.error("💣 Exiting")
|
|
124
|
+
sys.exit(1)
|
|
125
|
+
|
|
126
|
+
sys.exit(0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: anemoi-utils
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: A package to hold various functions to support training of ML models on ECMWF data.
|
|
5
5
|
Author-email: "European Centre for Medium-Range Weather Forecasts (ECMWF)" <software.support@ecmwf.int>
|
|
6
6
|
License: Apache License
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
anemoi/utils/__init__.py,sha256=zZZpbKIoGWwdCOuo6YSruLR7C0GzvzI1Wzhyqaa0K7M,456
|
|
2
|
-
anemoi/utils/__main__.py,sha256=
|
|
3
|
-
anemoi/utils/_version.py,sha256=
|
|
2
|
+
anemoi/utils/__main__.py,sha256=1JH882AKwooNwvyNoNzQMNaqVdE1RsPlmoUNV-1M550,1868
|
|
3
|
+
anemoi/utils/_version.py,sha256=MxUhzLJIZQfEpDTTcKSxciTGrMLd5v2VmMlHa2HGeo0,411
|
|
4
4
|
anemoi/utils/caching.py,sha256=HrC9aFHlcCTaM2Z5u0ivGIXz7eFu35UQQhUuwwuG2pk,1743
|
|
5
5
|
anemoi/utils/checkpoints.py,sha256=1_3mg4B-ykTVfIvIUEv7IxGyREx_ZcilVbB3U-V6O6I,5165
|
|
6
|
+
anemoi/utils/cli.py,sha256=39THXs5SVtJ3L4ugemgbRIlK4ivEGraSsu5ns9KUn68,3271
|
|
6
7
|
anemoi/utils/config.py,sha256=XEesqODvkuE3ZA7dnEnZ-ooBRtU6ecPmkfP65FtialA,2147
|
|
7
8
|
anemoi/utils/dates.py,sha256=Ot9OTY1uFvHxW1EU4DPv3oUqmzvkXTwKuwhlfVlY788,8426
|
|
8
9
|
anemoi/utils/grib.py,sha256=gVfo4KYQv31iRyoqRDwk5tiqZDUgOIvhag_kO0qjYD0,3067
|
|
@@ -14,9 +15,9 @@ anemoi/utils/commands/__init__.py,sha256=Pc5bhVgW92ox1lMR5WUOLuhiY2HT6PsadSHclyw
|
|
|
14
15
|
anemoi/utils/commands/checkpoint.py,sha256=SEnAizU3WklqMXUjmIh4eNrgBVwmheKG9gEBS90zwYU,1741
|
|
15
16
|
anemoi/utils/mars/__init__.py,sha256=RAeY8gJ7ZvsPlcIvrQ4fy9xVHs3SphTAPw_XJDtNIKo,1750
|
|
16
17
|
anemoi/utils/mars/mars.yaml,sha256=R0dujp75lLA4wCWhPeOQnzJ45WZAYLT8gpx509cBFlc,66
|
|
17
|
-
anemoi_utils-0.2.
|
|
18
|
-
anemoi_utils-0.2.
|
|
19
|
-
anemoi_utils-0.2.
|
|
20
|
-
anemoi_utils-0.2.
|
|
21
|
-
anemoi_utils-0.2.
|
|
22
|
-
anemoi_utils-0.2.
|
|
18
|
+
anemoi_utils-0.2.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
19
|
+
anemoi_utils-0.2.1.dist-info/METADATA,sha256=paJt_2GuGwfGVTD8pj2vmPjHyDtUtbejpzKHShtwq3A,15174
|
|
20
|
+
anemoi_utils-0.2.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
21
|
+
anemoi_utils-0.2.1.dist-info/entry_points.txt,sha256=LENOkn88xzFQo-V59AKoA_F_cfYQTJYtrNTtf37YgHY,60
|
|
22
|
+
anemoi_utils-0.2.1.dist-info/top_level.txt,sha256=DYn8VPs-fNwr7fNH9XIBqeXIwiYYd2E2k5-dUFFqUz0,7
|
|
23
|
+
anemoi_utils-0.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|