ipython / ipython/ipython

Embedding IPython - Prompt reflecting nesting level, and banner printing filename and lineno

Ouverte
#3,095 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
needs-info
Langage dominant
Python
Étoiles
16.8k
Forks
4.5k
Merge moyen
1 j 2 h
PR mergées (30 j)
6

Description

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`?**

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.