本文整理汇总了Python中IPython.terminal.embed.InteractiveShellEmbed类的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShellEmbed类的具体用法?Python InteractiveShellEmbed怎么用?Python InteractiveShellEmbed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InteractiveShellEmbed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_shell
def make_shell(banner=u'IPython', **namespace):
cfg = Config()
prompt_config = cfg.PromptManager
prompt_config.in_template = r'{color.LightGreen}\[email protected]\h{color.LightBlue}[{color.LightCyan}\Y1{color.LightBlue}]{color.Green}|\#> '
prompt_config.out_template = r'<\#> '
sh = InteractiveShellEmbed(config=cfg, banner1=banner)
return sh.mainloop(local_ns=namespace)
示例2: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument('cmd', nargs='*',
help='run this command and exit')
args = parser.parse_args()
c = Config()
c.InteractiveShell.confirm_exit = False
if args.cmd:
c.PromptManager.out_template = ''
c.HistoryAccessor.enabled = False
ipshell = InteractiveShellEmbed(config=c, banner1='')
ipshell.extension_manager.load_extension('xalc')
if args.cmd:
ipshell.run_cell(' '.join(args.cmd), store_history=False)
sys.exit()
print('xalc examples/tests:')
for inp, out in tests:
print(' {:10s} => {:10s}'.format(inp, out))
ipshell()
示例3: test_ipython
def test_ipython(tmp_path):
os.chdir(str(tmp_path))
dotenv_file = tmp_path / '.env'
dotenv_file.write_text("MYNEWVALUE=q1w2e3\n")
ipshell = InteractiveShellEmbed()
ipshell.magic("load_ext dotenv")
ipshell.magic("dotenv")
assert os.environ["MYNEWVALUE"] == 'q1w2e3'
示例4: main
def main(args):
red = RedFlyingBaron.from_paths(args, verbose=True)
shell = InteractiveShellEmbed(banner1="", banner2="")
shell.push(["red", "RedFlyingBaron"])
print "\nRedFlyingBaron instance is available under the name 'red':"
print red
shell.set_next_input("red")
shell()
示例5: wrapper
def wrapper(namespace=namespace, banner=''):
config = load_default_config()
# Always use .instace() to ensure _instance propagation to all parents
# this is needed for <TAB> completion works well for new imports
# and clear the instance to always have the fresh env
# on repeated breaks like with inspect_response()
InteractiveShellEmbed.clear_instance()
shell = InteractiveShellEmbed.instance(
banner1=banner, user_ns=namespace, config=config)
shell()
示例6: _ipython
def _ipython(local, banner):
from IPython.terminal.embed import InteractiveShellEmbed
from IPython.terminal.ipapp import load_default_config
InteractiveShellEmbed.clear_instance()
shell = InteractiveShellEmbed.instance(
banner1=banner,
user_ns=local,
config=load_default_config()
)
shell()
示例7: ipython
def ipython(message=None, frame=None):
"""Launch into customized IPython with greedy autocompletion and no prompt to exit.
If stdin is not tty, just issue warning message."""
import sys
if os.isatty(sys.stdin.fileno()):
config = Config({
'InteractiveShell': {'confirm_exit': False, },
'IPCompleter': {'greedy': True, }
})
InteractiveShellEmbed.instance(config=config)(message, local_ns=frame.f_locals, global_ns=frame.f_globals)
else:
warn("==========> IPython cannot be launched if stdin is not a tty.\n\n")
示例8: ipython_console
def ipython_console():
"""
Run ipython console
"""
from traitlets.config import Config
from IPython.terminal.embed import InteractiveShellEmbed
config = Config()
# basic configuration
config.TerminalInteractiveShell.confirm_exit = False
#
embed = InteractiveShellEmbed(config=config, banner1='')
embed.mainloop()
示例9: console
def console():
"""Starts an interactive IPython console"""
import sys
import builtins
from IPython.terminal.embed import (load_default_config,
InteractiveShell, InteractiveShellEmbed)
header = 'Django debug console'
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
# save ps1/ps2 if defined
ps1 = None
ps2 = None
try:
ps1 = sys.ps1
ps2 = sys.ps2
except AttributeError:
pass
# save previous instance
saved_shell_instance = InteractiveShell._instance
if saved_shell_instance is not None:
cls = type(saved_shell_instance)
cls.clear_instance()
# Starts shell
retvalue = None
def exit(value=None):
nonlocal retvalue
retvalue = value
try:
builtins.exit = exit
shell = InteractiveShellEmbed.instance(config=config)
shell(header=header, stack_depth=2, compile_flags=None)
InteractiveShellEmbed.clear_instance()
finally:
pass
# restore previous instance
if saved_shell_instance is not None:
cls = type(saved_shell_instance)
cls.clear_instance()
for subclass in cls._walk_mro():
subclass._instance = saved_shell_instance
if ps1 is not None:
sys.ps1 = ps1
sys.ps2 = ps2
return retvalue
示例10: _interact
def _interact(ns):
shell = InteractiveShellEmbed(user_ns=ns)
def _handle_exception(shell, exc_type, exc_value, exc_tb, tb_offset):
exc_info = (exc_type, exc_value, exc_tb)
shell.showtraceback(exc_info, tb_offset)
if not _is_exception_in_ipython_eval(exc_tb):
handle_exception(exc_info)
if isinstance(exc_value, TerminatedException):
context.result.add_error('Terminated')
shell.exit_now = True
shell.set_custom_exc((Exception, TerminatedException), _handle_exception)
shell()
示例11: start_shell
def start_shell(controller=None):
"""Load Kytos interactive shell."""
kytos_ascii = r"""
_ _
| | | |
| | ___ _| |_ ___ ___
| |/ / | | | __/ _ \/ __|
| <| |_| | || (_) \__ \
|_|\_\__, |\__\___/|___/
__/ |
|___/
"""
banner1 = f"""\033[95m{kytos_ascii}\033[0m
Welcome to Kytos SDN Platform!
We are making a huge effort to make sure that this console will work fine
but for now it's still experimental.
Kytos website.: https://kytos.io/
Documentation.: https://docs.kytos.io/
OF Address....:"""
exit_msg = "Stopping Kytos daemon... Bye, see you!"
if controller:
address = controller.server.server_address[0]
port = controller.server.server_address[1]
banner1 += f" tcp://{address}:{port}\n"
api_port = controller.api_server.port
banner1 += f" WEB UI........: http://{address}:{api_port}/\n"
banner1 += f" Kytos Version.: {__version__}"
banner1 += "\n"
cfg = Config()
cfg.TerminalInteractiveShell.autocall = 2
cfg.TerminalInteractiveShell.show_rewritten_input = False
cfg.TerminalInteractiveShell.confirm_exit = False
# Avoiding sqlite3.ProgrammingError when trying to save command history
# on Kytos shutdown
cfg.HistoryAccessor.enabled = False
ipshell = InteractiveShellEmbed(config=cfg,
banner1=banner1,
exit_msg=exit_msg)
ipshell.prompts = KytosPrompt(ipshell)
ipshell()
示例12: interact_ipython
def interact_ipython(header='', *args, **kwargs):
global interact_ipython_
def pre_prompt_hook(_):
R.gInterpreter.EndOfLineAction()
# Interact is a callable which starts an ipython shell
if not interact_ipython_:
interact_ipython_ = InteractiveShellEmbed(banner1=UP_LINE)
# needed for graphics to work correctly
interact_ipython_.set_hook('pre_prompt_hook', pre_prompt_hook)
stack_depth = kwargs.pop("stack_depth", 0) + 2
kwargs["stack_depth"] = stack_depth
interact_ipython_(header, *args, **kwargs)
示例13: debughook
def debughook(type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(type, value, tb)
else:
# we are NOT in interactive mode, print the exception...
#traceback.print_exception(type, value, tb)
colorhook(type, value, tb)
frame = tb.tb_next.tb_frame
sh = InteractiveShellEmbed(
banner1=termcolor.colored(
"Custom Debug IPython Shell:\n", 'red'))
sh.confirm_exit = False
sh.mainloop(local_ns=frame.f_locals, global_ns=frame.f_globals)
示例14: wrapper
def wrapper(namespace=namespace, banner=''):
config = load_default_config()
# Always use .instace() to ensure _instance propagation to all parents
# this is needed for <TAB> completion works well for new imports
shell = InteractiveShellEmbed.instance(
banner1=banner, user_ns=namespace, config=config)
shell()
示例15: interact
def interact(self, **kwargs):
from IPython.terminal.embed import InteractiveShellEmbed, load_default_config
import sys
config = kwargs.get('config')
header = kwargs.pop('header', u'')
compile_flags = kwargs.pop('compile_flags', None)
if config is None:
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
kwargs['config'] = config
frame = sys._getframe(1)
shell = InteractiveShellEmbed.instance(
_init_location_id='%s:%s' % (
frame.f_code.co_filename, frame.f_lineno), **kwargs)
shell(header=header, stack_depth=2, compile_flags=compile_flags,
_call_location_id='%s:%s' % (frame.f_code.co_filename, frame.f_lineno))
InteractiveShellEmbed.clear_instance()