Skip to content

app

Main typer app.py file for hpcman

Imports all submodules. App is actually started in the __main__.py file. We turn off auto-completion because it clutters the help message. We add a -h option for help messages as well, as the underlying click command does not support it. rich_markup_mode="rich" allows us to use rich markup in the help messages (i.e. colors, emojis, etc.).

app is generated from a function so type hinting works properly.

Attributes:

Name Type Description
app typer.Typer

The main app object.

generate_app()

Generate the main app object.

Returns:

Name Type Description
app typer.Typer

Main app object with generalized settings.

Source code in hpcman/app.py
def generate_app() -> typer.Typer:
    """Generate the main app object.

    Returns:
        app: Main app object with generalized settings.
    """
    app = typer.Typer(
        context_settings=dict(help_option_names=["-h", "--help"]),
        add_completion=False,
        rich_markup_mode="rich",
        no_args_is_help=True,
    )

    return app

import_submodules(app)

Imports submodules using importlib.

Uses the find_submodules() function specified in the __init__.py file.

Returns:

Name Type Description
app typer.Typer

Main app object with imported submodules.

Source code in hpcman/app.py
def import_submodules(app: typer.Typer) -> typer.Typer:
    """Imports submodules using importlib.

    Uses the `find_submodules()` function specified in the `__init__.py` file.

    Returns:
        app: Main app object with imported submodules.
    """
    for submod in find_submodules():
        imported = import_module(f"hpcman.{submod}.app")
        app.add_typer(imported.app, name=submod)

    return app

version()

Print version number and exit.

Uses the get_version() function specified in the __init__.py file.

Instead of using a --version flag, this command will print the version.

Returns:

Type Description
None

None

Source code in hpcman/app.py
@app.command()
def version() -> None:
    """Print version number and exit.

    Uses the `get_version()` function specified in the `__init__.py` file.

    Instead of using a `--version` flag, this command will print the version.

    Returns:
        None
    """
    print(get_version())