Skip to content

Commit

Permalink
Work on cli
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed May 28, 2024
1 parent 5ac543b commit e3f7b19
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 89 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ repos:
hooks:
- id: sphinx-lint

- repo: https://github.com/LilSpazJoekp/docstrfmt
rev: v1.6.1
# For now, we use it. But it does not support a lot of sphinx features
- repo: https://github.com/dzhu/rstfmt
rev: v0.0.14
hooks:
- id: docstrfmt
language_version: python3
types_or: [rst] # Don't touch python docstrings.
- id: rstfmt
exclude: 'cli/.*' # Because we use argparse

- repo: https://github.com/b8raoult/pre-commit-docconvert
rev: "0.1.4"
Expand Down
15 changes: 7 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
import os
import sys

sys.path.insert(0, os.path.abspath(".."))


read_the_docs_build = os.environ.get("READTHEDOCS", None) == "True"

# top = os.path.realpath(os.path.dirname(os.path.dirname(__file__)))
# sys.path.insert(0, top)

sys.path.insert(0, os.path.join(os.path.abspath(".."), "src"))

source_suffix = ".rst"
master_doc = "index"
Expand All @@ -32,7 +27,7 @@

# -- Project information -----------------------------------------------------

project = "Anemoi"
project = "Anemoi Models"

author = "ECMWF"

Expand All @@ -44,8 +39,12 @@

copyright = "%s, ECMWF" % (years,)

try:
from anemoi.models._version import __version__

release = "0.1.0"
release = __version__
except ImportError:
release = "0.0.0"


# -- General configuration ---------------------------------------------------
Expand Down
55 changes: 30 additions & 25 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
.. _anemoi-utils:
.. _anemoi-models:

.. _index-page:

Welcome to Anemoi's documentation!
==================================
###########################################
Welcome to `anemoi-models` documentation!
###########################################

.. warning::

This documentation is work in progress.
This documentation is work in progress.

*Anemoi* is a framework for developing machine learning weather forecasting models. It
comprises of components or packages for preparing training datasets, conducting ML model
training and a registry for datasets and trained models. *Anemoi* provides tools for
operational inference, including interfacing to verification software. As a framework it
seeks to handle many of the complexities that meteorological organisations will share,
allowing them to easily train models from existing recipes but with their own data.
*Anemoi* is a framework for developing machine learning weather
forecasting models. It comprises of components or packages for preparing
training datasets, conducting ML model training and a registry for
datasets and trained models. *Anemoi* provides tools for operational
inference, including interfacing to verification software. As a
framework it seeks to handle many of the complexities that
meteorological organisations will share, allowing them to easily train
models from existing recipes but with their own data.

This package provides a series of utility functions for used by the rest of the *Anemoi*
packages.
This package provides a series of utility functions for used by the rest
of the *Anemoi* packages.

- :doc:`installing`
- :doc:`installing`

.. toctree::
:maxdepth: 1
:hidden:
:maxdepth: 1
:hidden:

installing
installing

Anemoi packages
---------------
*****************
Anemoi packages
*****************

- :ref:`anemoi-utils <anemoi-utils:index-page>`
- :ref:`anemoi-datasets <anemoi-datasets:index-page>`
- :ref:`anemoi-models <anemoi-models:index-page>`
- :ref:`anemoi-training <anemoi-training:index-page>`
- :ref:`anemoi-inference <anemoi-inference:index-page>`
- :ref:`anemoi-utils <anemoi-utils:index-page>`
- :ref:`anemoi-datasets <anemoi-datasets:index-page>`
- :ref:`anemoi-models <anemoi-models:index-page>`
- :ref:`anemoi-training <anemoi-training:index-page>`
- :ref:`anemoi-inference <anemoi-inference:index-page>`

License
-------
*********
License
*********

*Anemoi* is available under the open source `Apache License`__.

Expand Down
58 changes: 7 additions & 51 deletions src/anemoi/models/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,20 @@
# nor does it submit to any jurisdiction.
#


import argparse
import logging
import sys
import traceback
from anemoi.utils.cli import cli_main
from anemoi.utils.cli import make_parser

from . import __version__
from .commands import COMMANDS

LOG = logging.getLogger(__name__)


def main():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)

parser.add_argument(
"--version",
"-V",
action="store_true",
help="show the version and exit",
)
parser.add_argument(
"--debug",
"-d",
action="store_true",
help="Debug mode",
)

subparsers = parser.add_subparsers(help="commands:", dest="command")
for name, command in COMMANDS.items():
command_parser = subparsers.add_parser(name, help=command.__doc__)
command.add_arguments(command_parser)
# For read-the-docs
def create_parser():
return make_parser(__doc__, COMMANDS)

args = parser.parse_args()

if args.version:
print(__version__)
return

if args.command is None:
parser.print_help()
return

cmd = COMMANDS[args.command]

logging.basicConfig(
format="%(asctime)s %(levelname)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=logging.DEBUG if args.debug else logging.INFO,
)

try:
cmd.run(args)
except ValueError as e:
traceback.print_exc()
LOG.error("\n💣 %s", str(e).lstrip())
LOG.error("💣 Exiting")
sys.exit(1)
def main():
cli_main(__version__, __doc__, COMMANDS)


if __name__ == "__main__":
Expand Down

0 comments on commit e3f7b19

Please sign in to comment.