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
asim
, with its submodulesimportlib.metadata
asimm
andimportlib.resources
asimr
The
etree
module fromlxml
The
pprint
function from thepprint
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 thefzf
binary (must be in the PATH) which makes it easy to select a model element interactively from a listlogtee
: Context manager that redirects log messages to a fileshowxml
: Print the XML representation of a model objectsuppress
: 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:test-5.0
,docs
,croud-surveillance-demo
,coffee-machine
,test-5.2
,test-6.0
,level-crossing-demo
,ife-demo
,test-lib
(default:None
)
options¶
--disable-diagram-cache
- Disable the diagram cache, if one was defined for the model--dump
- Dump model info as JSON to stdout and exit--hold
- Inhibit automatic model updates (update_cache=False)--wipe
- Wipe the cache (disable_cache=True)