source: trunk/bin/asap

Last change on this file was 3130, checked in by Malte Marquarding, 7 years ago

Make Ipython >= 5 compatible

File size: 1.9 KB
RevLine 
[2498]1#!/usr/bin/env python
2import os
3
[3130]4def _main500():
5    from IPython.terminal.prompts import Prompts, Token
6    from traitlets.config.loader import Config
[2621]7
[3130]8    class MyPrompt(Prompts):
9        def in_prompt_tokens(self, cli=None):
10            return [(Token.Prompt, 'ASAP> ')]
[2621]11
[3130]12        def out_prompt_tokens(self, cli=None):
13            return [(Token.OutPrompt, 'asap>: ')]
[2621]14
[3130]15    cfg = Config()
16    cfg.TerminalInteractiveShell.colors = "Linux"
17    cfg.TerminalInteractiveShell.prompts_class=MyPrompt
18    from IPython.terminal.embed import InteractiveShellEmbed
19    ipshell = InteractiveShellEmbed(config=cfg,
20                                    banner1 = welcome(),
21                                    exit_msg = '')
22    return ipshell
23   
[2929]24def _main011():
[2498]25    from IPython.config.loader import Config
26    cfg = Config()
27    prompt_config = cfg.PromptManager
28    prompt_config.in_template = 'ASAP> '
29    prompt_config.out_template = 'asap>: '
30    cfg.InteractiveShell.autoindent = True
31    cfg.InteractiveShell.autocall = 2
32    cfg.InteractiveShell.magic_pprint = True
33    cfg.InteractiveShell.use_readline=True
34    cfg.InteractiveShell.confirm_exit=False
35    cfg.InteractiveShell.xmode='Plain'
[2929]36    try:       
37        from IPython.terminal.embed import InteractiveShellEmbed
38    except ImportError:
39        from IPython.frontend.terminal.embed import InteractiveShellEmbed
[2498]40    ipshell = InteractiveShellEmbed(config=cfg,
41                                    banner1 = welcome(),
42                                    exit_msg = '')
[2621]43    return ipshell
[2498]44
45try:
46    os.system('clear')
47    import IPython
[2929]48    from asap import *   
49    vitems = IPython.__version__.split(".")
50    vmaj = int(vitems[0])
[3130]51    if vmaj >= 5:
52        ipshell = _main500()
[2621]53    else:
[2929]54        ipshell = _main011()
[2623]55    ipshell()
[3130]56   
[2498]57except ImportError:
[2621]58    banner =  "No ipython found. Running standard python"
59    import code
[2499]60    from asap import *
[2621]61    code.interact(banner, local=locals())
Note: See TracBrowser for help on using the repository browser.