anemoi-utils 0.4.24__tar.gz → 0.4.25__tar.gz

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.

Files changed (102) hide show
  1. anemoi_utils-0.4.25/.release-please-manifest.json +3 -0
  2. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/CHANGELOG.md +8 -0
  3. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/PKG-INFO +3 -1
  4. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/pyproject.toml +2 -0
  5. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/_version.py +2 -2
  6. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/cli.py +14 -4
  7. anemoi_utils-0.4.25/src/anemoi/utils/commands/transfer.py +74 -0
  8. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/grids.py +27 -0
  9. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/remote/__init__.py +8 -3
  10. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/remote/s3.py +1 -1
  11. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/testing.py +101 -0
  12. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi_utils.egg-info/PKG-INFO +3 -1
  13. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi_utils.egg-info/SOURCES.txt +1 -1
  14. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi_utils.egg-info/requires.txt +2 -0
  15. anemoi_utils-0.4.24/.release-please-manifest.json +0 -3
  16. anemoi_utils-0.4.24/tests/test_grids.py +0 -29
  17. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.gitattributes +0 -0
  18. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/CODEOWNERS +0 -0
  19. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/ci-hpc-config.yml +0 -0
  20. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/dependabot.yml +0 -0
  21. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/labeler.yml +0 -0
  22. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/pull_request_template.md +0 -0
  23. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/downstream-ci-hpc.yml +0 -0
  24. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/pr-conventional-commit.yml +0 -0
  25. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/pr-label-conventional-commits.yml +0 -0
  26. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/pr-label-file-based.yml +0 -0
  27. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/pr-label-public.yml +0 -0
  28. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/python-publish.yml +0 -0
  29. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/python-pull-request.yml +0 -0
  30. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/readthedocs-pr-update.yml +0 -0
  31. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.github/workflows/release-please.yml +0 -0
  32. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.gitignore +0 -0
  33. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.pre-commit-config.yaml +0 -0
  34. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.readthedocs.yaml +0 -0
  35. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/.release-please-config.json +0 -0
  36. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/CONTRIBUTORS.md +0 -0
  37. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/LICENSE +0 -0
  38. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/README.md +0 -0
  39. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/Makefile +0 -0
  40. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/_static/logo.png +0 -0
  41. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/_static/style.css +0 -0
  42. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/_templates/.gitkeep +0 -0
  43. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/_templates/apidoc/package.rst.jinja +0 -0
  44. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/conf.py +0 -0
  45. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/index.rst +0 -0
  46. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/installing.rst +0 -0
  47. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/checkpoints.rst +0 -0
  48. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/config.rst +0 -0
  49. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/dates.rst +0 -0
  50. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/grib.rst +0 -0
  51. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/humanize.rst +0 -0
  52. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/provenance.rst +0 -0
  53. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/s3.rst +0 -0
  54. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/testing.rst +0 -0
  55. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/modules/text.rst +0 -0
  56. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/docs/scripts/api_build.sh +0 -0
  57. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/setup.cfg +0 -0
  58. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/__init__.py +0 -0
  59. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/__main__.py +0 -0
  60. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/caching.py +0 -0
  61. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/checkpoints.py +0 -0
  62. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/commands/__init__.py +0 -0
  63. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/commands/config.py +0 -0
  64. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/commands/requests.py +0 -0
  65. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/compatibility.py +0 -0
  66. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/config.py +0 -0
  67. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/dates.py +0 -0
  68. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/devtools.py +0 -0
  69. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/grib.py +0 -0
  70. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/hindcasts.py +0 -0
  71. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/humanize.py +0 -0
  72. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/logs.py +0 -0
  73. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/mars/__init__.py +0 -0
  74. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/mars/mars.yaml +0 -0
  75. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/mars/requests.py +0 -0
  76. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/provenance.py +0 -0
  77. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/registry.py +0 -0
  78. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/remote/ssh.py +0 -0
  79. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/rules.py +0 -0
  80. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/s3.py +0 -0
  81. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/sanitise.py +0 -0
  82. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/sanitize.py +0 -0
  83. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/schemas/__init__.py +0 -0
  84. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/schemas/errors.py +0 -0
  85. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/text.py +0 -0
  86. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi/utils/timer.py +0 -0
  87. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi_utils.egg-info/dependency_links.txt +0 -0
  88. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi_utils.egg-info/entry_points.txt +0 -0
  89. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/src/anemoi_utils.egg-info/top_level.txt +0 -0
  90. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test-transfer-data/directory/b/c/x +0 -0
  91. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test-transfer-data/directory/b/y +0 -0
  92. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test-transfer-data/directory/exotic filename ;^/"'[=.,#]()/303/252/303/274/303/247/303/262/342/234/205.txt" +0 -0
  93. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test-transfer-data/directory/z +0 -0
  94. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test-transfer-data/file +0 -0
  95. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test_caching.py +0 -0
  96. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test_compatibility.py +0 -0
  97. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test_dates.py +0 -0
  98. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test_frequency.py +0 -0
  99. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test_provenance.py +0 -0
  100. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test_remote.py +0 -0
  101. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test_sanetise.py +0 -0
  102. {anemoi_utils-0.4.24 → anemoi_utils-0.4.25}/tests/test_utils.py +0 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.4.25"
3
+ }
@@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  Please add your functional changes to the appropriate section in the PR.
9
9
  Keep it human-readable, your future self will thank you!
10
10
 
11
+ ## [0.4.25](https://github.com/ecmwf/anemoi-utils/compare/0.4.24...0.4.25) (2025-06-24)
12
+
13
+
14
+ ### Features
15
+
16
+ * Add a CLI to transfer data ([#164](https://github.com/ecmwf/anemoi-utils/issues/164)) ([3a845ca](https://github.com/ecmwf/anemoi-utils/commit/3a845ca0c31d115e6b3d0496d862a3eaee5fb236))
17
+ * Add function to test cli ([#168](https://github.com/ecmwf/anemoi-utils/issues/168)) ([9ac9b06](https://github.com/ecmwf/anemoi-utils/commit/9ac9b06b8fd0a62cad33ea5de6a6b482f0a13656))
18
+
11
19
  ## [0.4.24](https://github.com/ecmwf/anemoi-utils/compare/0.4.23...0.4.24) (2025-06-06)
12
20
 
13
21
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anemoi-utils
3
- Version: 0.4.24
3
+ Version: 0.4.25
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
@@ -225,12 +225,14 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy
225
225
  Requires-Python: >=3.9
226
226
  License-File: LICENSE
227
227
  Requires-Dist: aniso8601
228
+ Requires-Dist: deprecation
228
229
  Requires-Dist: importlib-metadata; python_version < "3.10"
229
230
  Requires-Dist: multiurl
230
231
  Requires-Dist: numpy
231
232
  Requires-Dist: pydantic>=2.9
232
233
  Requires-Dist: python-dateutil
233
234
  Requires-Dist: pyyaml
235
+ Requires-Dist: rich
234
236
  Requires-Dist: tomli; python_version < "3.11"
235
237
  Requires-Dist: tqdm
236
238
  Provides-Extra: all
@@ -41,12 +41,14 @@ classifiers = [
41
41
  dynamic = [ "version" ]
42
42
  dependencies = [
43
43
  "aniso8601",
44
+ "deprecation",
44
45
  "importlib-metadata; python_version<'3.10'",
45
46
  "multiurl",
46
47
  "numpy",
47
48
  "pydantic>=2.9",
48
49
  "python-dateutil",
49
50
  "pyyaml",
51
+ "rich",
50
52
  "tomli; python_version<'3.11'",
51
53
  "tqdm",
52
54
  ]
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.4.24'
21
- __version_tuple__ = version_tuple = (0, 4, 24)
20
+ __version__ = version = '0.4.25'
21
+ __version_tuple__ = version_tuple = (0, 4, 25)
@@ -15,6 +15,7 @@ import os
15
15
  import sys
16
16
  import traceback
17
17
  from typing import Callable
18
+ from typing import Optional
18
19
 
19
20
  try:
20
21
  import argcomplete
@@ -185,7 +186,9 @@ def register_commands(here: str, package: str, select: Callable, fail: Callable
185
186
  return result
186
187
 
187
188
 
188
- def cli_main(version: str, description: str, commands: dict[str, Command]) -> None:
189
+ def cli_main(
190
+ version: str, description: str, commands: dict[str, Command], test_arguments: Optional[list[str]] = None
191
+ ) -> None:
189
192
  """Main entry point for the CLI.
190
193
 
191
194
  Parameters
@@ -196,9 +199,11 @@ def cli_main(version: str, description: str, commands: dict[str, Command]) -> No
196
199
  The description of the CLI
197
200
  commands : dict[str, Command]
198
201
  A dictionary of command names to Command instances
202
+ test_arguments : list[str], optional
203
+ The command line arguments to parse, used for testing purposes, by default None
199
204
  """
200
205
  parser = make_parser(description, commands)
201
- args, unknown = parser.parse_known_args()
206
+ args, unknown = parser.parse_known_args(test_arguments)
202
207
  if argcomplete:
203
208
  argcomplete.autocomplete(parser)
204
209
 
@@ -220,7 +225,7 @@ def cli_main(version: str, description: str, commands: dict[str, Command]) -> No
220
225
 
221
226
  if unknown and not cmd.accept_unknown_args:
222
227
  # This should trigger an error
223
- parser.parse_args()
228
+ parser.parse_args(test_arguments)
224
229
 
225
230
  try:
226
231
  if unknown:
@@ -228,9 +233,14 @@ def cli_main(version: str, description: str, commands: dict[str, Command]) -> No
228
233
  else:
229
234
  cmd.run(args)
230
235
  except ValueError as e:
236
+
237
+ if test_arguments:
238
+ raise
239
+
231
240
  traceback.print_exc()
232
241
  LOG.error("\n💣 %s", str(e).lstrip())
233
242
  LOG.error("💣 Exiting")
234
243
  sys.exit(1)
235
244
 
236
- sys.exit(0)
245
+ if not test_arguments:
246
+ sys.exit(0)
@@ -0,0 +1,74 @@
1
+ # (C) Copyright 2024 Anemoi contributors.
2
+ #
3
+ # This software is licensed under the terms of the Apache Licence Version 2.0
4
+ # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5
+ #
6
+ # In applying this licence, ECMWF does not waive the privileges and immunities
7
+ # granted to it by virtue of its status as an intergovernmental organisation
8
+ # nor does it submit to any jurisdiction.
9
+
10
+
11
+ from argparse import ArgumentParser
12
+ from argparse import Namespace
13
+
14
+ from anemoi.utils.remote import transfer
15
+
16
+ from . import Command
17
+
18
+
19
+ class Transfer(Command):
20
+ """Handle configuration related commands."""
21
+
22
+ def add_arguments(self, command_parser: ArgumentParser) -> None:
23
+ """Add arguments to the command parser.
24
+
25
+ Parameters
26
+ ----------
27
+ command_parser : ArgumentParser
28
+ The argument parser to which the arguments will be added.
29
+ """
30
+ command_parser.add_argument(
31
+ "--source", help="A path to a local file or folder or a URL to a file or a folder on S3."
32
+ )
33
+ command_parser.add_argument(
34
+ "--target", help="A path to a local file or folder or a URL to a file or a folder on S3 or a remote folder."
35
+ )
36
+ command_parser.add_argument(
37
+ "--overwrite",
38
+ action="store_true",
39
+ help="If the data is already on in the target location it will be overwritten..",
40
+ )
41
+ command_parser.add_argument(
42
+ "--resume",
43
+ action="store_true",
44
+ help="If the data is already on S3 it will not be uploaded, unless the remote file has a different size.",
45
+ )
46
+ command_parser.add_argument("--verbosity", default=1, help="The level of verbosity, by default 1.")
47
+ command_parser.add_argument(
48
+ "--progress", default=None, help="A callable that will be called with the number of files."
49
+ )
50
+ command_parser.add_argument(
51
+ "--threads", default=1, help="The number of threads to use when uploading a directory, by default 1."
52
+ )
53
+
54
+ def run(self, args: Namespace) -> None:
55
+ """Execute the command with the provided arguments.
56
+
57
+ Parameters
58
+ ----------
59
+ args : Namespace
60
+ The arguments passed to the command.
61
+ """
62
+ transfer(
63
+ source=args.source,
64
+ target=args.target,
65
+ overwrite=args.overwrite,
66
+ resume=args.resume,
67
+ verbosity=args.verbosity,
68
+ progress=args.progress,
69
+ threads=args.threads,
70
+ temporary_target=False,
71
+ )
72
+
73
+
74
+ command = Transfer
@@ -17,9 +17,12 @@ from typing import List
17
17
  from typing import Tuple
18
18
  from typing import Union
19
19
 
20
+ import deprecation
20
21
  import numpy as np
21
22
  import requests
22
23
 
24
+ from anemoi.utils._version import __version__
25
+
23
26
  from .caching import cached
24
27
 
25
28
  LOG = logging.getLogger(__name__)
@@ -28,6 +31,12 @@ LOG = logging.getLogger(__name__)
28
31
  GRIDS_URL_PATTERN = "https://get.ecmwf.int/repository/anemoi/grids/grid-{name}.npz"
29
32
 
30
33
 
34
+ @deprecation.deprecated(
35
+ deprecated_in="0.4.25",
36
+ removed_in="0.5.0",
37
+ current_version=__version__,
38
+ details="Use anemoi.transform.spatial.xyz_to_latlon instead.",
39
+ )
31
40
  def xyz_to_latlon(x: np.ndarray, y: np.ndarray, z: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
32
41
  """Convert Cartesian coordinates to latitude and longitude.
33
42
 
@@ -51,6 +60,12 @@ def xyz_to_latlon(x: np.ndarray, y: np.ndarray, z: np.ndarray) -> tuple[np.ndarr
51
60
  )
52
61
 
53
62
 
63
+ @deprecation.deprecated(
64
+ deprecated_in="0.4.25",
65
+ removed_in="0.5.0",
66
+ current_version=__version__,
67
+ details="Use anemoi.transform.spatial.xyz_to_latlon instead.",
68
+ )
54
69
  def latlon_to_xyz(lat: np.ndarray, lon: np.ndarray, radius: float = 1.0) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
55
70
  """Convert latitude and longitude to Cartesian coordinates.
56
71
 
@@ -87,6 +102,12 @@ def latlon_to_xyz(lat: np.ndarray, lon: np.ndarray, radius: float = 1.0) -> tupl
87
102
  return x, y, z
88
103
 
89
104
 
105
+ @deprecation.deprecated(
106
+ deprecated_in="0.4.25",
107
+ removed_in="0.5.0",
108
+ current_version=__version__,
109
+ details="Use anemoi.transform.spatial.nearest_grid_points instead.",
110
+ )
90
111
  def nearest_grid_points(
91
112
  source_latitudes: np.ndarray,
92
113
  source_longitudes: np.ndarray,
@@ -169,6 +190,12 @@ def _grids(name: Union[str, List[float], Tuple[float, ...]]) -> bytes:
169
190
  return response.content
170
191
 
171
192
 
193
+ @deprecation.deprecated(
194
+ deprecated_in="0.4.25",
195
+ removed_in="0.5.0",
196
+ current_version=__version__,
197
+ details="Use anemoi.transform.grids.named.lookup instead.",
198
+ )
172
199
  def grids(name: Union[str, List[float], Tuple[float, ...]]) -> dict:
173
200
  """Load grid data by name.
174
201
 
@@ -371,7 +371,12 @@ class BaseDownload(Loader):
371
371
  The target path.
372
372
  """
373
373
  if os.path.exists(target):
374
- shutil.rmtree(target)
374
+ if os.path.isfile(target):
375
+ LOGGER.info(f"Deleting file {target}")
376
+ os.remove(target)
377
+ else:
378
+ LOGGER.info(f"Deleting directory {target}")
379
+ shutil.rmtree(target)
375
380
 
376
381
 
377
382
  class BaseUpload(Loader):
@@ -642,10 +647,10 @@ def transfer(
642
647
  A path to a local file or folder or a URL to a file or a folder on S3 or a remote folder.
643
648
  The url should start with 's3://' or 'ssh://'.
644
649
  overwrite : bool, optional
645
- If the data is alreay on in the target location it will be overwritten.
650
+ If the data is already on in the target location it will be overwritten.
646
651
  By default False
647
652
  resume : bool, optional
648
- If the data is alreay on S3 it will not be uploaded, unless the remote file has a different size
653
+ If the data is already on S3 it will not be uploaded, unless the remote file has a different size
649
654
  Ignored if the target is an SSH remote folder (ssh://).
650
655
  By default False
651
656
  verbosity : int, optional
@@ -146,7 +146,7 @@ def s3_client(bucket: str, *, region: str = None, service: str = "s3") -> Any:
146
146
 
147
147
  return options
148
148
 
149
- LOG.info(f"Using S3 options: {_(options)}")
149
+ LOG.debug(f"Using S3 options: {_(options)}")
150
150
 
151
151
  thread_local.s3_clients[key] = boto3.client(service, **options)
152
152
 
@@ -299,3 +299,104 @@ def skip_missing_packages(*names: str) -> callable:
299
299
  return pytest.mark.skipif(True, reason=f"Package {missing[0]} is not installed")
300
300
 
301
301
  return pytest.mark.skipif(True, reason=f"Packages {list_to_human(missing)} are not installed")
302
+
303
+
304
+ def skip_if_missing_command(cmd: str) -> callable:
305
+ """Skip a test if the specified command is not available.
306
+
307
+ Parameters
308
+ ----------
309
+ cmd : str
310
+ The name of the command to check.
311
+
312
+ Returns
313
+ -------
314
+ Callable
315
+ A decorator that skips the test if the specified command is not available.
316
+ """
317
+
318
+ import shutil
319
+
320
+ if shutil.which(cmd):
321
+ return lambda f: f
322
+
323
+ return pytest.mark.skipif(True, reason=f"Command '{cmd}' is not available")
324
+
325
+
326
+ def cli_testing(package: str, cmd: str, *args: list[str]) -> None:
327
+ """Run a CLI command for testing purposes.
328
+
329
+ Parameters
330
+ ----------
331
+ package : str
332
+ The name of the package containing the CLI commands.
333
+ Can be 'anemoi-datasets' or 'anemoi.datasets'.
334
+ cmd : str
335
+ The command to run.
336
+ *args : list[str]
337
+ Additional arguments to pass to the command.
338
+ """
339
+
340
+ package = package.replace("-", ".")
341
+ COMMANDS = getattr(__import__(f"{package}.commands", fromlist=["COMMANDS"]), "COMMANDS")
342
+ version = getattr(__import__(f"{package}._version", fromlist=["__version__"]), "__version__", "0.1.0")
343
+
344
+ from anemoi.utils.cli import cli_main
345
+
346
+ cli_main(
347
+ version=version,
348
+ description=f"Testing the '{cmd}' CLI command from the '{package}' package.",
349
+ commands=COMMANDS,
350
+ test_arguments=(cmd,) + args,
351
+ )
352
+
353
+
354
+ def run_tests(globals: dict[str, callable]) -> None:
355
+ """Run all test functions that start with 'test_'.
356
+
357
+ Parameters
358
+ ----------
359
+ globals : dict[str, callable]
360
+ The global namespace containing the test functions.
361
+
362
+ Example
363
+ -------
364
+
365
+ Call from a test file to run all tests in that file:
366
+
367
+ ```python
368
+ if __name__ == "__main__":
369
+ from anemoi.utils.testing import run_tests
370
+ run_tests(globals())
371
+ ```
372
+
373
+ Useful for debugging or running tests in an interactive environment.
374
+
375
+ """
376
+ import logging
377
+
378
+ import rich
379
+
380
+ logging.basicConfig(level=logging.INFO)
381
+
382
+ for name, obj in list(globals.items()):
383
+ if name.startswith("test_") and callable(obj):
384
+
385
+ pytestmark = getattr(obj, "pytestmark", None)
386
+ if pytestmark is not None:
387
+ if not isinstance(pytestmark, list):
388
+ pytestmark = [pytestmark]
389
+
390
+ skip = False
391
+ for m in pytestmark:
392
+ if m.name == "skipif" and m.args == (True,):
393
+ skip = True
394
+ rich.print(
395
+ f"[red]Skipping [bold]{name}[/bold] due to skipif condition [bold]{m.kwargs['reason']}[/bold].[/red]"
396
+ )
397
+ break
398
+ if skip:
399
+ continue
400
+
401
+ rich.print(f"[green]Running [bold]{name}[/bold]...[/green]")
402
+ obj()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anemoi-utils
3
- Version: 0.4.24
3
+ Version: 0.4.25
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
@@ -225,12 +225,14 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy
225
225
  Requires-Python: >=3.9
226
226
  License-File: LICENSE
227
227
  Requires-Dist: aniso8601
228
+ Requires-Dist: deprecation
228
229
  Requires-Dist: importlib-metadata; python_version < "3.10"
229
230
  Requires-Dist: multiurl
230
231
  Requires-Dist: numpy
231
232
  Requires-Dist: pydantic>=2.9
232
233
  Requires-Dist: python-dateutil
233
234
  Requires-Dist: pyyaml
235
+ Requires-Dist: rich
234
236
  Requires-Dist: tomli; python_version < "3.11"
235
237
  Requires-Dist: tqdm
236
238
  Provides-Extra: all
@@ -68,6 +68,7 @@ src/anemoi/utils/timer.py
68
68
  src/anemoi/utils/commands/__init__.py
69
69
  src/anemoi/utils/commands/config.py
70
70
  src/anemoi/utils/commands/requests.py
71
+ src/anemoi/utils/commands/transfer.py
71
72
  src/anemoi/utils/mars/__init__.py
72
73
  src/anemoi/utils/mars/mars.yaml
73
74
  src/anemoi/utils/mars/requests.py
@@ -86,7 +87,6 @@ tests/test_caching.py
86
87
  tests/test_compatibility.py
87
88
  tests/test_dates.py
88
89
  tests/test_frequency.py
89
- tests/test_grids.py
90
90
  tests/test_provenance.py
91
91
  tests/test_remote.py
92
92
  tests/test_sanetise.py
@@ -1,9 +1,11 @@
1
1
  aniso8601
2
+ deprecation
2
3
  multiurl
3
4
  numpy
4
5
  pydantic>=2.9
5
6
  python-dateutil
6
7
  pyyaml
8
+ rich
7
9
  tqdm
8
10
 
9
11
  [:python_version < "3.10"]
@@ -1,3 +0,0 @@
1
- {
2
- ".": "0.4.24"
3
- }
@@ -1,29 +0,0 @@
1
- # (C) Copyright 2025 Anemoi contributors.
2
- #
3
- # This software is licensed under the terms of the Apache Licence Version 2.0
4
- # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5
- #
6
- # In applying this licence, ECMWF does not waive the privileges and immunities
7
- # granted to it by virtue of its status as an intergovernmental organisation
8
- # nor does it submit to any jurisdiction.
9
-
10
-
11
- from anemoi.utils.grids import grids
12
-
13
-
14
- def test_o96() -> None:
15
- """Test the grids function for the 'o96' grid."""
16
- x = grids("o96")
17
- assert x["latitudes"].mean() == 0.0
18
- assert x["longitudes"].mean() == 179.14285714285714
19
- assert x["latitudes"].shape == (40320,)
20
- assert x["longitudes"].shape == (40320,)
21
- assert x["latitudes"][31415] == -31.324557701757268
22
- assert x["longitudes"][31415] == 224.32835820895522
23
-
24
-
25
- if __name__ == "__main__":
26
- for name, obj in list(globals().items()):
27
- if name.startswith("test_") and callable(obj):
28
- print(f"Running {name}...")
29
- obj()
File without changes
File without changes
File without changes
File without changes