diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e5d6f6e1..c928f082 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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" diff --git a/docs/conf.py b/docs/conf.py index 208e3d06..215c7d05 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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" @@ -32,7 +27,7 @@ # -- Project information ----------------------------------------------------- -project = "Anemoi" +project = "Anemoi Models" author = "ECMWF" @@ -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 --------------------------------------------------- diff --git a/docs/index.rst b/docs/index.rst index 20e70508..e7caaa5c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 ` -- :ref:`anemoi-datasets ` -- :ref:`anemoi-models ` -- :ref:`anemoi-training ` -- :ref:`anemoi-inference ` +- :ref:`anemoi-utils ` +- :ref:`anemoi-datasets ` +- :ref:`anemoi-models ` +- :ref:`anemoi-training ` +- :ref:`anemoi-inference ` -License -------- +********* + License +********* *Anemoi* is available under the open source `Apache License`__. diff --git a/src/anemoi/models/__main__.py b/src/anemoi/models/__main__.py index 2ac1a15d..be940c27 100644 --- a/src/anemoi/models/__main__.py +++ b/src/anemoi/models/__main__.py @@ -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__":