Skip to content

CLI: knowledge-mapper run — start a Python-defined KnowledgeBase #10

@DaviddeBest-TNO

Description

@DaviddeBest-TNO

Goal

Add a knowledge-mapper run subcommand that starts a KnowledgeBase instance defined in a Python file, replacing the boilerplate if __name__ == "__main__" block that users currently need to write.

Motivation

Every Python-defined KB currently requires the same boilerplate:

if __name__ == "__main__":
    kb.register()
    kb.start_handling_loop()
    kb.unregister()

The CLI should handle this lifecycle automatically, including graceful shutdown.

Usage

knowledge-mapper run my_app.py:kb

Where my_app.py is the Python file and kb is the name of the KnowledgeBase variable.

Behaviour

  1. Load the specified Python module.
  2. Retrieve the named KnowledgeBase instance from the module.
  3. Call kb.register().
  4. Call kb.start_handling_loop() (blocking).
  5. On SIGINT/SIGTERM: call kb.unregister() and exit cleanly.

Implementation notes

  • Use typer as the CLI framework.
  • This is one subcommand of the knowledge-mapper entry point; knowledge-mapper sparql (separate issue) will be another.
  • Add knowledge-mapper to console_scripts in pyproject.toml.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions