The py-capellambse REPL

A simple Python REPL with a Capella model.

You can use this script to quickly launch an interactive Python interpreter and load a model.

If the readline module is available, the interpreter spawned from this script uses a separate readline history. It is located in $XDG_STATE_HOME/capellambse on proper operating systems and in the capellambse cache directory on others.

Normally this script is run with something like:

python -Xdev -m capellambse.repl test-5.0

However, as that can become quite unwieldy, it is also possible to run it directly from the source tree with:

./capellambse/repl.py test-5.0

On Unix-like operating systems, this will automatically enable -Xdev on the Python interpreter.

In order to add custom models for the –model argument, add a JSON file to your user known_models directory. This file defines the instantiation parameters for the capellambse.model.MelodyModel:

1{
2  "path": "tests/data/Library Project/Library Project.aird",
3  "resources": {
4    "Library Test": "tests/data/Library Test"
5  }
6}

Use the following command to view the path of your known_models directory, and to see which models are currently available:

python -m capellambse.cli_helpers

In addition to the standard Python builtins, he environment in the REPL also provides the following convenience imports:

  • The Python packages capellambse, inspect, logging, os, pathlib

  • importlib as im, with its submodules importlib.metadata as imm and importlib.resources as imr

  • The etree module from lxml

  • The pprint function from the pprint module

A few helpful functions specific to working interactively with models are also available. Use the help builtin inside the REPL to get more information and usage examples.

  • fzf: Wrapper around the fzf binary (must be in the PATH) which makes it easy to select a model element interactively from a list

  • logtee: Context manager that redirects log messages to a file

  • showxml: Print the XML representation of a model object

  • suppress: Context manager that suppresses exceptions of given type

Capellambse Repl

capellambse/repl.py [-h] [--disable-diagram-cache] [--dump] [-V] [--hold | --wipe] [model]

positional arguments

  • model - A model name from known_models, an AIRD file, or the path to (or contents of) a JSON file describing the model. The following models are known: docs, croud-surveillance-demo, level-crossing-demo, test-lib, test-6.0, test-5.2, ife-demo, coffee-machine, test-5.0 (default: None)

options

  • -h, --help - show this help message and exit

  • --disable-diagram-cache - Disable the diagram cache, if one was defined for the model

  • --dump - Dump model info as JSON to stdout and exit

  • -V, --version - show program’s version number and exit

  • --hold - Inhibit automatic model updates (update_cache=False)

  • --wipe - Wipe the cache (disable_cache=True)