Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies = [
"importlib-metadata; python_version<'3.10'",
"multiurl",
"numpy",
"omegaconf",
"pydantic>=2.9",
"python-dateutil",
"pyyaml",
Expand Down
4 changes: 4 additions & 0 deletions src/anemoi/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import sys
import traceback
import warnings
from collections.abc import Callable

from anemoi.utils import ENV
Expand Down Expand Up @@ -225,6 +226,9 @@ def cli_main(
test_arguments : list[str], optional
The command line arguments to parse, used for testing purposes, by default None
"""

warnings.filterwarnings("default", category=DeprecationWarning)

parser = make_parser(description, commands)
args, unknown = parser.parse_known_args(test_arguments)
if argcomplete:
Expand Down
18 changes: 14 additions & 4 deletions src/anemoi/utils/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
from argparse import ArgumentParser
from argparse import Namespace

from ..config import config_path
from ..config import load_config
import deprecation

from anemoi.utils._version import __version__

from ..settings import load_settings
from ..settings import settings_path
from . import Command


Expand All @@ -30,6 +34,12 @@ def add_arguments(self, command_parser: ArgumentParser) -> None:
"""
command_parser.add_argument("--path", help="Print path to config file")

@deprecation.deprecated(
deprecated_in="0.1.0",
removed_in="0.2.0",
current_version=__version__,
details="Use `anemoi settings` instead.",
)
def run(self, args: Namespace) -> None:
"""Execute the command with the provided arguments.

Expand All @@ -39,9 +49,9 @@ def run(self, args: Namespace) -> None:
The arguments passed to the command.
"""
if args.path:
print(config_path())
print(settings_path())
else:
print(json.dumps(load_config(), indent=4))
print(json.dumps(load_settings(), indent=4))


command = Config
47 changes: 47 additions & 0 deletions src/anemoi/utils/commands/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# (C) Copyright 2024 Anemoi contributors.
#
# 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.


import json
from argparse import ArgumentParser
from argparse import Namespace

from ..settings import load_settings
from ..settings import settings_path
from . import Command


class Settings(Command):
"""Handle settings related commands."""

def add_arguments(self, command_parser: ArgumentParser) -> None:
"""Add arguments to the command parser.

Parameters
----------
command_parser : ArgumentParser
The argument parser to which the arguments will be added.
"""
command_parser.add_argument("--path", help="Print path to config file")

def run(self, args: Namespace) -> None:
"""Execute the command with the provided arguments.

Parameters
----------
args : Namespace
The arguments passed to the command.
"""
if args.path:
print(settings_path())
else:
print(json.dumps(load_settings(), indent=4))


command = Settings
Loading
Loading