Embedding IPython - Prompt reflecting nesting level, and banner printing filename and lineno
- Lenguaje dominante
- Python
- Estrellas
- 16.8k
- Forks
- 4.5k
- Merge medio
- 1 d 2 h
- PR fusionados (30 d)
- 6
Descripción
When embedding IPython, is it possible to modify the prompt to **display** the nesting level?
Also, how can I have my call to `ipshell()` automatically display the `filename` and `lineno` as soon as it starts (e.g. as part of the banner).
More specifically, I would like to be able execute the following code anytime I call `ipshell()`
``` python
frameinfo = getframeinfo(currentframe())
print "Stopped at:"
print frameinfo.filename, frameinfo.lineno
```
I currently have the following setup:
``` python
from IPython.config.loader import Config
try:
get_ipython
except NameError:
nested = 0
cfg = Config()
prompt_config = cfg.PromptManager
prompt_config.in_template = 'In <\\#>: '
prompt_config.in2_template = ' .\\D.: '
prompt_config.out_template = 'Out<\\#>: '
else:
# print("Running nested copies of IPython.")
print("The prompts for the nested IPythons have been modified")
print(" ")
cfg = Config()
nested = 1
# First import the embed function
from IPython.frontend.terminal.embed import InteractiveShellEmbed
# Now create the IPython shell instance. Put ipshell() anywhere in your code where you want it to open.
ipshell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg)
msg = '***Called from top level.\n \
Hit Ctrl-D to exit interpreter and continue program.\n \
Note that if you use %kill_embedded, you can fully deactivate\n \
This embedded instance so it will never turn on again';
```
With the above, I can then call `ipshell(msg)` whenever I want my code to open an IPython shell, but:
**How can I have the prompt reflect the nesting level and have the banner display `filename` and `lineno`?**
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.