本文整理汇总了Python中IPython.frontend.terminal.embed.InteractiveShellEmbed类的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShellEmbed类的具体用法?Python InteractiveShellEmbed怎么用?Python InteractiveShellEmbed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InteractiveShellEmbed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invoke
def invoke(cls, ns, banner): # pragma: nocover
"""
:param ns: local namespace
:param banner: interactive shell startup banner
Embed an interactive ipython shell.
Try the InteractiveShellEmbed API first, fall back on
IPShellEmbed for older IPython versions.
"""
try:
from IPython.frontend.terminal.embed import (
InteractiveShellEmbed
)
# try and load their default profile
from IPython.frontend.terminal.ipapp import (
load_default_config
)
config = load_default_config()
shell = InteractiveShellEmbed(config=config, banner2=banner)
shell(local_ns=ns)
except ImportError:
# Support for the IPython <= 0.10 shell API
from IPython.Shell import IPShellEmbed
shell = IPShellEmbed(argv=[])
shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
shell(local_ns=ns, global_ns={})
示例2: run_ipython
def run_ipython():
import IPython
from IPython.frontend.terminal.embed import InteractiveShellEmbed
from django.conf import settings
try:
imported_objects = import_objects(options, self.style)
cfgfile = "%s/.config/ipython/profile_default/ipython_config.py" % os.environ['HOME']
cfg = IPython.config.loader.PyFileConfigLoader(cfgfile).load_config()
appname = "Welcome to the %s Shell.\n" % getattr(settings, "APPLICATION_NAME", "")
ipshell = InteractiveShellEmbed(config=cfg, banner1=appname, user_ns=imported_objects)
# An example how to define magics
# the function _toggle_logging has to be provided by the PYTHONSTARTUP script,
# see django_extensions/management/shells.py
try:
ipshell.define_magic('toggle_logging', imported_objects['_toggle_logging'])
except:
pass
ipshell()
except ImportError:
# IPython < 0.11
# Explicitly pass an empty list as arguments, because otherwise
# IPython would use sys.argv from this script.
# Notebook not supported for IPython < 0.11.
from IPython.Shell import IPShell
imported_objects = import_objects(options, self.style)
shell = IPShell(argv=[], user_ns=imported_objects)
shell.mainloop()
示例3: run
def run(self, options, args, arduino):
PromptManager.in_template = "PyArduino [\\#]> "
PromptManager.out_template = "PyArduino [\\#]: "
shell = InteractiveShellEmbed(banner2=banner)
shell.user_ns = {}
shell()
示例4: interface_shell_embed
def interface_shell_embed(interface):
"""
Returns an IPython shell which uses a Sage interface on the
backend to perform the evaluations. It uses
:class:`InterfaceShellTransformer` to transform the input into the
appropriate ``interface.eval(...)`` input.
EXAMPLES::
sage: from sage.misc.interpreter import interface_shell_embed
sage: shell = interface_shell_embed(gap)
sage: shell.run_cell('List( [1..10], IsPrime )')
[ false, true, true, false, true, false, true, false, false, false ]
"""
try:
cfg = Config(get_ipython().config)
except NameError:
cfg = Config(DEFAULT_SAGE_CONFIG)
cfg.PromptManager['in_template'] = interface.name() + ': '
ipshell = InteractiveShellEmbed(config=cfg,
banner1='\n --> Switching to %s <--\n\n'%interface,
exit_msg = '\n --> Exiting back to Sage <--\n')
ipshell.interface = interface
while ipshell.prefilter_manager.transformers:
ipshell.prefilter_manager.transformers.pop()
while ipshell.prefilter_manager.checkers:
ipshell.prefilter_manager.checkers.pop()
ipshell.ex('from sage.all import *')
InterfaceShellTransformer(shell=ipshell,
prefilter_manager=ipshell.prefilter_manager,
config=cfg)
return ipshell
示例5: main
def main():
# Load the UAVO xml files in the workspace
import taulabs
uavo_defs = taulabs.uavo_collection.UAVOCollection()
uavo_defs.from_uavo_xml_path('shared/uavobjectdefinition')
# Build a new module that will make up the global namespace for the
# interactive shell. This allows us to restrict what the ipython shell sees.
import imp
user_module = imp.new_module('taulabs_env')
user_module.__dict__.update({
'operator' : __import__('operator'),
})
# Extend the shell environment to include all of the uavo.UAVO_* classes that were
# auto-created when the uavo xml files were processed.
uavo_classes = [(t[0], t[1]) for t in taulabs.uavo.__dict__.iteritems() if 'UAVO_' in t[0]]
user_module.__dict__.update(uavo_classes)
# Build the "user" (ie. local) namespace that the interactive shell
# will see. These variables show up in the output of "%whos" in the shell.
user_ns = {
'uavo_defs' : uavo_defs,
}
import IPython
from IPython.frontend.terminal.embed import InteractiveShellEmbed
e = InteractiveShellEmbed(user_ns = user_ns, user_module = user_module)
e.enable_pylab(import_all = True)
e("Have a look around. Your UAVO definitions are in 'uavo_defs'.")
示例6: interact_ipython
def interact_ipython(header='', *args, **kwargs):
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
interact_ipython_(header, *args, **kwargs)
示例7: setupIpython
def setupIpython():
try:
import IPython
from IPython.config.loader import Config
from IPython.frontend.terminal.embed import InteractiveShellEmbed
cfg = Config()
cfg.PromptManager.in_template = "BinPy:\\#> "
cfg.PromptManager.out_template = "BinPy:\\#: "
bpyShell = InteractiveShellEmbed(config=cfg, banner1=banner,
exit_msg=exit_msg)
bpyShell.define_magic("clear", magic_clear)
except ImportError:
try:
from IPython.Shell import IPShellEmbed
argsv = ['-pi1', 'BinPY:\\#>', '-pi2', ' .\\D.:', '-po',
'BinPy:\\#>', '-nosep']
bpyShell = IPShellEmbed(argsv)
bpyShell.set_banner(banner)
bpyShell.set_exit_msg(exit_msg)
except ImportError:
raise
return bpyShell()
示例8: gambit_shell
def gambit_shell():
"""
Start an ipython session after initializing the environment
"""
import gambit
import gambit.nash
import gambit.qre
# Everything in this dictionary will be added to the top-level
# namespace in the shell.
ns = { 'gambit': gambit, 'nash': gambit.nash, 'qre': gambit.qre }
shell = InteractiveShellEmbed()
shell.user_ns = ns
shell()
示例9: run_shell
def run_shell(self, *args):
locs = dict(__name__="aptgregator-admin", wsgiapp=self.wsgiapp, app=self.app)
admin_boot = os.path.join(os.path.dirname(__file__), 'admin_boot.py')
execfile(admin_boot, {}, locs)
if self.options.script_file:
execfile(self.options.script_file, {}, locs)
return
try:
# try to use IPython if possible
if self.options.disable_ipython:
raise ImportError()
from IPython.frontend.terminal.embed import InteractiveShellEmbed
if self.options.verbose:
shell = InteractiveShellEmbed()
print ''
else:
shell = InteractiveShellEmbed(banner1='')
shell(local_ns=locs, global_ns={})
except ImportError:
import code
shell = code.InteractiveConsole(locals=locs)
if self.options.verbose:
banner = 'Python %s\n\n' % sys.version
else:
banner = ''
try:
import readline
except ImportError:
pass
print ''
shell.interact(banner)
示例10: main
def main():
uavo_list = telemetry.get_telemetry_by_args()
# retrieve the time from the first object.. also guarantees we can parse
base_time = next(iter(uavo_list)).time
# Build a new module that will make up the global namespace for the
# interactive shell. This allows us to restrict what the ipython shell sees.
import imp
user_module = imp.new_module('dronin_env')
user_module.__dict__.update({
'operator' : __import__('operator'),
'base_time' : base_time,
})
# Build the "user" (ie. local) namespace that the interactive shell
# will see. These variables show up in the output of "%whos" in the shell.
user_ns = {
'base_time' : base_time,
'log_file' : uavo_list.filename,
'githash' : uavo_list.githash,
'uavo_defs' : uavo_list.uavo_defs,
'uavo_list' : uavo_list,
}
# Extend the shell environment to include all of the uavo.UAVO_* classes that were
# auto-created when the uavo xml files were processed.
uavo_classes = [(t[0], t[1]) for t in uavo.__dict__.iteritems() if 'UAVO_' in t[0]]
user_module.__dict__.update(uavo_classes)
# Instantiate an ipython shell to interact with the log data.
import IPython
from IPython.frontend.terminal.embed import InteractiveShellEmbed
e = InteractiveShellEmbed(user_ns = user_ns, user_module = user_module)
e.enable_pylab(import_all = True)
e("Analyzing log file: %s" % uavo_list.filename)
示例11: setup_shell
def setup_shell():
banner = "+----------------------------------------------------------------------+\n"
banner += " PML Shell - built on IPython.\n"
banner += "+----------------------------------------------------------------------+\n"
banner += "Commands: \n"
banner += "\t'tutorial' will begin the interactive tutorial.\n"
banner += "\t'tutorial list' will display individual lessons in the tutorial.\n"
banner += "\t'docs' will open up the online documentation in a web browser.\n"
banner += "\t'exit', 'quit' or press 'CTRL + D' to exit the shell.\n"
exit_message = "\n* Exiting PML shell, good bye! *\n"
# XXX: this currently only supports IPython version 0.11 or higher!
config = Config()
config.PromptManager.in_template = "pml:\\#> "
config.PromptManager.out_template = "pml:\\#: "
pml_shell = InteractiveShellEmbed(config=config, banner1=banner,
exit_msg=exit_message)
pml_shell.define_magic("tutorial", magic_tutorial)
pml_shell.define_magic("docs", magic_docs)
return pml_shell
示例12: _12shell
def _12shell(vars, message, prompt, exit_msg):
#prompt_message = "Welcome! Useful: G is the graph, DB, C"
prompt_message = message
from IPython.frontend.terminal.embed import InteractiveShellEmbed
from IPython.config.loader import Config
cfg = Config()
# cfg.InteractiveShellEmbed.prompt_in1="pylans:ipy> "
cfg.PromptManager.in_template="myprompt:> "
# cfg.InteractiveShellEmbed.prompt_out="myprompt [\\#]: "
cfg.InteractiveShellEmbed.profile="pysh"
ipshell = InteractiveShellEmbed.instance(config=cfg, user_ns=vars,
banner2=message, exit_msg=exit_msg)
return ipshell
示例13: shell
def shell(no_ipython):
"""Start a new interactive python session."""
banner = 'Interactive Werkzeug Shell'
namespace = make_shell()
if not no_ipython:
try:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed.instance(banner1=banner)
except ImportError:
from IPython.Shell import IPShellEmbed
sh = IPShellEmbed(banner=banner)
except ImportError:
pass
else:
sh(local_ns=namespace)
return
from code import interact
interact(banner, local=namespace)
示例14: action
def action(ipython=use_ipython):
"""Start a new interactive python session."""
namespace = init_func()
if ipython:
try:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed.instance(banner1=banner)
except ImportError:
from IPython.Shell import IPShellEmbed
sh = IPShellEmbed(banner=banner)
except ImportError:
pass
else:
sh(local_ns=namespace)
return
from code import interact
interact(banner, local=namespace)
示例15: __init__
def __init__(self,argv=None,user_ns=None,user_global_ns=None,
cin=None, cout=None,cerr=None, input_func=None):
if argv is None:
argv=[]
# This is to get rid of the blockage that occurs during
# IPython.Shell.InteractiveShell.user_setup()
#IPython.iplib.raw_input = lambda x: None
# not used?
#self.term = IPython.genutils.IOTerm(cin=cin, cout=cout, cerr=cerr)
from IPython.config.loader import Config
cfg = Config()
cfg.InteractiveShell.colors = "Linux"
os.environ['TERM'] = 'dumb'
excepthook = sys.excepthook
self.IP = InteractiveShellEmbed(config=cfg, user_ns=user_ns, user_global_ns=user_global_ns)
self.IP.system = lambda cmd: self.shell(self.IP.var_expand(cmd),
header='IPython system call: ',
verbose=self.IP.rc.system_verbose)
if cin:
IPython.utils.io.stdin = IPython.utils.io.IOStream(cin)
if cout:
IPython.utils.io.stdout = IPython.utils.io.IOStream(cout)
if cerr:
IPython.utils.io.stderr = IPython.utils.io.IOStream(cerr)
if input_func:
IPython.frontend.terminal.interactiveshell.raw_input_original = input_func
sys.excepthook = excepthook
self.iter_more = False
self.history_level = 0
self.complete_sep = re.compile('[\s\{\}\[\]\(\)]')