Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add type hints and doctrings #45

Merged
merged 5 commits into from
Feb 26, 2025
Merged
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
15 changes: 13 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dynamic = [ "version" ]
dependencies = [
"anemoi-utils>=0.4.11",
"cfunits",
"earthkit-data>=0.12",
"earthkit-data>=0.12.4",
"earthkit-meteo>=0.3",
"earthkit-regrid>=0.4",
]
Expand All @@ -54,7 +54,7 @@ optional-dependencies.docs = [
"nbsphinx",
"pandoc",
"requests",
"sphinx",
"sphinx<8.2",
"sphinx-argparse<0.5",
"sphinx-rtd-theme",
"termcolor",
Expand All @@ -71,3 +71,14 @@ scripts.anemoi-transform = "anemoi.transform.__main__:main"

[tool.setuptools_scm]
version_file = "src/anemoi/transform/_version.py"

[tool.mypy]
strict = false
exclude = [
"docs/**",
]

[tool.pydocstringformatter]
write = true
exclude = "docs/**"
style = "numpydoc"
2 changes: 1 addition & 1 deletion src/anemoi/transform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
try:
# NOTE: the `_version.py` file must not be present in the git repository
# as it is generated by setuptools at install time
from ._version import __version__ # type: ignore
from ._version import __version__
except ImportError: # pragma: no cover
# Local copy or not installed with setuptools
__version__ = "999"
14 changes: 12 additions & 2 deletions src/anemoi/transform/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

from argparse import ArgumentParser

from anemoi.utils.cli import cli_main
from anemoi.utils.cli import make_parser

Expand All @@ -15,11 +17,19 @@


# For read-the-docs
def create_parser():
def create_parser() -> ArgumentParser:
"""Creates the argument parser for the CLI.

Returns
-------
ArgumentParser
The argument parser.
"""
return make_parser(__doc__, COMMANDS)


def main():
def main() -> None:
"""The main entry point for the CLI."""
cli_main(__version__, __doc__, COMMANDS)


Expand Down
12 changes: 12 additions & 0 deletions src/anemoi/transform/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

"""This module provides the command line interface for the Anemoi transform commands.

Commands
--------
Command : class
Base class for all commands.
Failed : class
Class representing a failed command.
register_commands : function
Function to register commands.
"""

import os

from anemoi.utils.cli import Command
Expand Down
20 changes: 18 additions & 2 deletions src/anemoi/transform/commands/get-grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@
# nor does it submit to any jurisdiction.


import argparse

from . import Command


class GetGrid(Command):
"""Extract the grid from a GRIB or NetCDF file and save it as a NPZ file."""

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

Parameters
----------
command_parser : argparse.ArgumentParser
The argument parser to add arguments to.
"""
command_parser.add_argument("--source", default="file", help="EKD Source type (default: file).")
command_parser.add_argument("input", help="Input file (GRIB or NetCDF).")
command_parser.add_argument("output", help="Output NPZ file.")

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

Parameters
----------
args : argparse.Namespace
The arguments to run the command with.
"""
import numpy as np
from earthkit.data import from_source

Expand Down
19 changes: 17 additions & 2 deletions src/anemoi/transform/commands/make-regrid-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# nor does it submit to any jurisdiction.


import argparse
import os

from . import Command
Expand All @@ -18,7 +19,14 @@ class MakeRegridMatrix(Command):
by earthkit-regrid.
"""

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

Parameters
----------
command_parser : argparse.ArgumentParser
The argument parser to add arguments to.
"""
command_parser.add_argument("--source1", default="file", help="EKD Source type (default: file).")
command_parser.add_argument("--source2", default="file", help="EKD Source type (default: file).")

Expand All @@ -31,7 +39,14 @@ def add_arguments(self, command_parser):

command_parser.add_argument("kwargs", nargs="*", help="MIR arguments.")

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

Parameters
----------
args : argparse.Namespace
The arguments to run the command with.
"""
import numpy as np
from earthkit.data import from_source
from earthkit.regrid.utils.mir import mir_make_matrix
Expand Down
Loading
Loading