Plugins
Entry Points
gallia
uses the entry_points
mechanism for registering plugins.
These entry points are known by gallia
:
gallia_commands
List of subclasses of
gallia.command.BaseCommand
add new a command to the CLI.gallia_cli_init
List of callables which get called during the initialization phase of the
ArgumentParser
; can be used to add new groups to the CLI.gallia_transports
List of subclasses of
gallia.transports.BaseTransport
add a new URI scheme for the--target
flag.gallia_uds_ecus
List of subclasses of
gallia.services.uds.ECU
which add new choices for the--oem
flag.
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()))