HPS Align

Main entrypoint when running this package

Call into this module and run the app constructed by typer:

python3 -m hps_align <args>

Besides running the app constructed by typer, we also make sure to inform ROOT that this is a batch script. This prevents ROOT from opening any GUI windows while constructing plots.

Sub-Modules

CLI Development

Module to hold CLI object

In hps_align, we use [typer] to generate our command line parser. This module is helpful because it parses the function signature of our functions in order to identify what the command line parameters should be. This allows us to forget about copying any new parameters to functions into an argparse definition since it will be handled by typer automatically.

One potentially issue with typer is that it requires its objects to be used as default values for function arguments. This is not an issue during normal operation; however, it prevents the function from being called like a normal function. This motivates a fix that can be included as another wrapper hps_align._cli.typer_unpacker defined below.

hps_align._cli.app

our typer app which must be informed of any command’s existence

Type:

typer.Typer

Examples

In order to register a function as a command with our CLI application:

@app.command()
def mycmd(...):
    # your code

In order to register a function and make it callable within other functions:

@app.comand()
@typer_unpacker
def mycmd(...):
    # your code

Using typer’s objects within your function arguments will help document the command options and define their types. Look at typer’s reference documentation in order to get the syntax for that.

hps_align._cli.typer_unpacker(f: Callable)

Decorator which accesses typer defaults and updates the kwargs so that the function can be used in typer CLI and normally

This was developed by GitHub user shaneatendpoint in response to question on GitHub. It will not be able to be included within typer unless Python’s typing system becomes more advanced.