Belle II Software
development
interactive.py
1
#!/usr/bin/env python3
2
3
10
11
"""
12
interactive
13
-----------
14
15
Defines a function embed() that can be used to drop into an interactive python
16
shell from within a steering file or python module. If available, IPython will
17
be used. Use Ctrl+D to exit the shell.
18
19
>>> import interactive
20
>>> interactive.embed()
21
In [1]:
22
23
See framework/examples/interactive_python.py for an example.
24
"""
25
26
from
traitlets.config.loader
import
Config
27
from
IPython.terminal.prompts
import
Prompts, Token
28
from
IPython
import
embed
# noqa
29
30
31
class
Basf2IPythonPrompt
(Prompts):
32
"""Provide slightly customized prompts when running basf2 interactively"""
33
34
def
in_prompt_tokens
(self, cli=None):
35
"""Input prompt"""
36
return
[(Token.Prompt,
"basf2 in ["
),
37
(Token.PromptNum, str(self.shell.execution_count)),
38
(Token.Prompt,
']: '
)]
39
40
def
out_prompt_tokens
(self):
41
"""Output prompt"""
42
return
[(Token.OutPrompt,
"basf2 out["
),
43
(Token.OutPromptNum, str(self.shell.execution_count)),
44
(Token.OutPrompt,
']: '
)]
45
46
47
def
basf2_shell_config():
48
"""Return a config object customizing the shell prompt for basf2"""
49
c = Config()
50
c.TerminalInteractiveShell.prompts_class = Basf2IPythonPrompt
51
return
c
52
53
54
if
__name__ ==
'__main__'
:
55
from
basf2
import
basf2label
56
from
basf2
import
*
# noqa
57
embed(config=basf2_shell_config(), header=f
"Welcome to {basf2label}"
)
interactive.Basf2IPythonPrompt
Definition
interactive.py:31
interactive.Basf2IPythonPrompt.in_prompt_tokens
in_prompt_tokens(self, cli=None)
Definition
interactive.py:34
interactive.Basf2IPythonPrompt.out_prompt_tokens
out_prompt_tokens(self)
Definition
interactive.py:40
framework
scripts
interactive.py
Generated on Mon Sep 1 2025 02:51:53 for Belle II Software by
1.13.2