Skip to content

hpcman

find_submodules()

Find submodules that contain an app.py file.

The app.py file contains the CLI entry for each submodule using typer. In the hpcman.app.py, each submodule app.py will be imported and the CLI entry for each submodule will be added to the app.py file.

Returns:

Name Type Description
submods List[str]

A list of submodules that contain an app.py file.

Source code in hpcman/__init__.py
def find_submodules() -> List[str]:
    """Find submodules that contain an app.py file.

    The app.py file contains the CLI entry for each submodule using typer. In the hpcman.app.py, each submodule app.py
    will be imported and the CLI entry for each submodule will be added to the app.py file.

    Returns:
        submods: A list of submodules that contain an app.py file.
    """
    submods = []
    for submod in iter_modules([Path(__file__).parent.as_posix()]):
        if submod.ispkg:
            imp: Optional[ModuleSpec] = importlib.util.find_spec(f"{__package__}.{submod.name}.app")
            if imp:
                submods.append(imp.name.split(".")[1])
    return submods

get_version()

Gets version string of hpcman using importlib. Falls back to extracting from the pyproject.toml file.

In python versions before 3.8, importlib_metadata.version is used. In python versions 3.8 and above, importlib.metadata.version is used.

The version string is extracted from the pyproject.toml file if the version is not otherwise found. This may happen in development environments.

Returns:

Name Type Description
__version__ str

Version string of hpcman.

Source code in hpcman/__init__.py
def get_version() -> str:
    """Gets version string of hpcman using importlib. Falls back to extracting from the pyproject.toml file.

    In python versions before 3.8, importlib_metadata.version is used. In python versions 3.8 and above,
    importlib.metadata.version is used.

    The version string is extracted from the pyproject.toml file if the version is not otherwise found. This may happen
    in development environments.

    Returns:
        __version__: Version string of hpcman.
    """
    if sys.version_info[0:2] == (3, 7):
        import importlib_metadata as metadata
    elif sys.version_info >= (3, 8, 0):
        import importlib.metadata as metadata

    try:
        __version__: str = str(metadata.version(__package__))
    except metadata.PackageNotFoundError:
        import toml

        pyproject = Path(Path(__package__).absolute().parent, "pyproject.toml")
        if pyproject.exists():
            __version__ = toml.load(pyproject.as_posix())["tool"]["poetry"]["version"]
        else:
            __version__ = "unknown"
    return __version__