Entrypoints
We use click as a tool to add new entry points and their CLI arguments. For this we have a main entry point from which all other entry points are started.
The main entry point is src/modalities/__main__.py:main()
.
We register other sub-entrypoints by using our main click.group
, called main
, as follows:
@main.command(name="my_new_entry_point")
See the following full example:
import click
import click_pathlib
@click.group()
def main() -> None:
pass
config_option = click.option(
"--config_file_path",
type=click_pathlib.Path(exists=False),
required=True,
help="Path to a file with the YAML config file.",
)
@main.command(name="do_stuff")
@config_option
@click.option(
"--my_cli_argument",
type=int,
required=True,
help="New integer argument",
)
def entry_point_do_stuff(config_file_path: Path, my_cli_argument: int):
print(f"Do stuff with {config_file_path} and {my_cli_argument}...)
...
if __name__ == "__main__":
main()
With
[project.scripts]
modalities = "modalities.__main__:main"
in our pyproject.toml
, we can start only main with modalities
(which does nothing), or a specific sub-entrypoint e.g. modalities do_stuff --config_file_path config_files/config.yaml --my_cli_argument 3537
.
Alternatively, directly use src/modalities/__main__.py do_stuff --config_file_path config_files/config.yaml --my_cli_argument 3537
.