Plugins
Entry Points
gallia uses the entry_points mechanism for registering plugins.
These entry points are known by gallia:
gallia_commandsList of subclasses of
gallia.command.AsyncScriptadd new a command to the CLI.gallia_cli_initList of callables which get called during the initialization phase of the
ArgumentParser; can be used to add new groups to the CLI.gallia_transportsList of subclasses of
gallia.transports.BaseTransportadd a new URI scheme for the--targetflag.gallia_uds_ecusList of subclasses of
gallia.services.uds.ECUwhich add new choices for the--oemflag.
Example
Below is an example that adds a new command to the CLI (using gallia.command.Script).
Let’s assume the following code snippet lives in the python module hello.py within the hello_gallia package.
from argparse import Namespace
from gallia.command import Script
class HelloWorld(Script):
"""A hello world script showing gallia's plugin API."""
COMMAND = "hello"
SHORT_HELP = "say hello to the world"
def main(self, args: Namespace) -> None:
print("Hello World")
commands = [HelloWorld]
In pyproject.toml using poetry the following entry_point needs to be specified:
[tool.poetry.plugins."gallia_commands"]
"hello_world_commands" = "hello_gallia.hello:commands"
After issueing poetry install, the script can be called with gallia script hello.
If a standalone script is desired, the HelloWorld class can be called like this:
parser = argparse.ArgumentParser()
sys.exit(HelloWorld(parser).entry_point(parser.parse_args()))