本文整理汇总了Python中IPython.start_ipython方法的典型用法代码示例。如果您正苦于以下问题:Python IPython.start_ipython方法的具体用法?Python IPython.start_ipython怎么用?Python IPython.start_ipython使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython
的用法示例。
在下文中一共展示了IPython.start_ipython方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _start_repl
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def _start_repl(api: Iota) -> None:
"""
Starts the REPL.
"""
banner = (
'IOTA API client for {uri} ({devnet}) '
'initialized as variable `api`.\n'
'Type `help(api)` for list of API commands.'.format(
devnet='devnet' if api.devnet else 'mainnet',
uri=api.adapter.get_uri(),
)
)
scope_vars = {'api': api}
try:
import IPython
except ImportError:
# IPython not available; use regular Python REPL.
from code import InteractiveConsole
InteractiveConsole(locals=scope_vars).interact(banner, '')
else:
print(banner)
IPython.start_ipython(argv=[], user_ns=scope_vars)
示例2: main
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def main():
args = parse_args()
archives = args.archives
if args.debug:
logging.basicConfig(level=logging.DEBUG)
excludes = parse_exclude(args.exclude) if args.exclude else ["*.log"]
conf = analyze(archives, excludes) # noqa F841 / unused var
# import all the built-in predicates
from insights.parsr.query import (lt, le, eq, gt, ge, isin, contains, # noqa: F403
startswith, endswith, ieq, icontains, istartswith, iendswith, # noqa: F403
matches, make_child_query) # noqa: F403
q = make_child_query # noqa: F405
import IPython
from traitlets.config.loader import Config
IPython.core.completer.Completer.use_jedi = False
c = Config()
c.TerminalInteractiveShell.banner1 = banner
IPython.start_ipython([], user_ns=locals(), config=c)
示例3: shell
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def shell():
import IPython
from zeus.app import app
from zeus.config import db
ctx = app.make_shell_context()
ctx["app"].test_request_context().push()
ctx["db"] = db
# Import all models into the shell context
ctx.update(db.Model._decl_class_registry)
startup = os.environ.get("PYTHONSTARTUP")
if startup and os.path.isfile(startup):
with open(startup, "rb") as f:
eval(compile(f.read(), startup, "exec"), ctx)
IPython.start_ipython(user_ns=ctx, argv=[])
示例4: client
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def client(**kwargs):
"""Start a REPL shell, with an already configured Clearly Client `clearlycli`.
\b
HOST: The host where Clearly Server is running, default localhost
PORT: The port where Clearly Server is running, default 12223
"""
from clearly.client import ClearlyClient, ModeTask, ModeWorker
share = dict(
clearlycli=ClearlyClient(**{k: v for k, v in kwargs.items() if v}),
ModeTask=ModeTask, ModeWorker=ModeWorker,
)
# the first option was bpython, but unfortunately it is broken...
# https://github.com/bpython/bpython/issues/758
# from bpython import embed
# embed(dict(clearlycli=clearlycli))
import IPython
from traitlets.config.loader import Config
c = Config()
c.TerminalInteractiveShell.banner1 = logo.render('client') + '\n'
c.TerminalInteractiveShell.banner2 = 'Clearly client is ready to use: clearlycli'
IPython.start_ipython(argv=[], user_ns=share, config=c)
示例5: connect
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def connect(args):
if len(args.argv) == 1:
connect_file = args.argv[0]
else:
files = glob("ipython-kernel-*.json")
files = [(os.path.getmtime(i), i) for i in files]
files.sort()
if len(files) > 0:
connect_file = files[-1][1]
else:
connect_file = None
assert connect_file and os.path.isfile(connect_file), "No connection file found"
argv = []
argv.append("console")
argv.append("--existing=%s" % os.path.abspath(connect_file))
logging.info("Connect to %s" % connect_file)
import IPython
IPython.start_ipython(argv=argv)
示例6: _run_interactive
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def _run_interactive(namespace, descriptions):
# We at a fully interactive terminal — i.e. stdin AND stdout are
# connected to the TTY — so display some introductory text...
banner = ["{automagenta}Welcome to the MAAS shell.{/automagenta}"]
if len(descriptions) > 0:
banner += ["", "Predefined objects:", ""]
wrap = textwrap.TextWrapper(60, " ", " ").wrap
sortkey = lambda name: (name.casefold(), name)
for name in sorted(descriptions, key=sortkey):
banner.append(" {autoyellow}%s{/autoyellow}:" % name)
banner.extend(wrap(descriptions[name]))
banner.append("")
for line in banner:
print(colorized(line))
# ... then start IPython, or the plain familiar Python REPL if
# IPython is not installed.
try:
import IPython
except ImportError:
code.InteractiveConsole(namespace).interact(" ")
else:
IPython.start_ipython(argv=[], display_banner=False, user_ns=namespace)
示例7: _start_shell
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def _start_shell(local_ns=None):
# An interactive shell is useful for debugging/development.
import IPython
user_ns = {}
if local_ns:
user_ns.update(local_ns)
user_ns.update(globals())
IPython.start_ipython(argv=[], user_ns=user_ns)
示例8: open_interpreter
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def open_interpreter(model, message=None, variables=None, funcs=None):
""" Opens an (I)Python interpreter
Args:
model (YATSM model): Pass YATSM model to work with
message (str, optional): Additional message to pass to user in banner
variables (dict of objects, optional): Variables available in (I)Python
session
funcs (dict of callable, optional): Functions available in (I)Python
session
"""
local = dict(_funcs, model=model, np=np, plt=plt)
if variables:
local.update(variables)
if funcs:
local.update(funcs)
banner = """\
YATSM {yver} Interactive Interpreter (Python {pver})
Type "help(model)" for info on YATSM model methods.
NumPy and matplotlib.pyplot are already imported as "np" and "plt".
""".format(
yver=__version__,
pver='.'.join(map(str, sys.version_info[:3])),
funcs='\n\t'.join([k for k in local])
)
banner = textwrap.dedent(banner)
if isinstance(message, str):
banner += '\n' + message
try:
import IPython
IPython.InteractiveShell.banner1 = banner
IPython.start_ipython(argv=[], user_ns=local)
except:
code.interact(banner, local=local)
示例9: do
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def do(interactive: bool, query: str, paths: List[str]) -> None:
"""Execute a query or enter interactive mode."""
if not query or query == "-":
namespace = {"Query": Query, "START": START, "SYMBOL": SYMBOL, "TOKEN": TOKEN}
try:
import IPython
IPython.start_ipython(argv=[], user_ns=namespace)
except ImportError:
import code as _code
_code.interact(local=namespace)
finally:
return
code = compile(query, "<console>", "eval")
result = eval(code) # noqa eval() - developer tool, hopefully they're not dumb
if isinstance(result, Query):
if result.retcode:
exc = click.ClickException("query failed")
exc.exit_code = result.retcode
raise exc
result.diff(interactive=interactive)
elif result:
click.echo(repr(result))
示例10: _run
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def _run(self):
# looping did not work
self.interrupt.wait()
print '\n' * 3
print "Entering Console, stopping services"
for s in self.app.services.values():
if s != self:
s.stop()
IPython.start_ipython(argv=['--gui', 'gevent'], user_ns=self.console_locals)
self.interrupt.clear()
sys.exit(0)
示例11: start_session
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def start_session(paths, change_directory=False, __coverage=None):
__cwd = os.path.abspath(os.curdir)
def callback(brokers):
models = Holder()
for i, (path, broker) in enumerate(brokers):
avail = _get_available_models(broker)
if paths:
if len(paths) > 1:
models[paths[i]] = Models(broker, avail, __cwd, path, __coverage)
else:
models = Models(broker, avail, __cwd, path, __coverage)
else:
models = Models(broker, avail, __cwd, path, __coverage)
if change_directory and len(brokers) == 1:
__working_path, _ = brokers[0]
os.chdir(__working_path)
# disable jedi since it won't autocomplete for objects with__getattr__
# defined.
IPython.core.completer.Completer.use_jedi = False
__cfg = Config()
__cfg.TerminalInteractiveShell.banner1 = Models.__doc__
__ns = {}
__ns.update(globals())
__ns.update({"models": models})
IPython.start_ipython([], user_ns=__ns, config=__cfg)
with_brokers(paths, callback)
if change_directory:
os.chdir(__cwd)
示例12: open_console
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def open_console(self, w, given_commands=None):
""" Start an interactive ipython console """
import sisyphus
user_ns = {'tk': sisyphus.toolkit,
'config_files': self.args.config_files,
}
# TODO Update welcome message
welcome_msg = """
Info: IPCompleter.greedy = True is set to True.
This allows to auto complete lists and dictionaries entries, but may evaluates functions on tab.
Enter tk? for help"""
run_commands = []
if given_commands:
for c in given_commands:
run_commands.append('print("Run command:", %s)' % repr(c))
run_commands.append(c)
import IPython
from traitlets.config.loader import Config
c = Config()
c.InteractiveShellApp.exec_lines = ['%rehashx'] + run_commands
c.InteractiveShell.confirm_exit = False
c.IPCompleter.greedy = True
c.InteractiveShell.banner2 = welcome_msg
with self.pause():
IPython.start_ipython(config=c, argv=[], user_ns=user_ns)
示例13: console
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import start_ipython [as 别名]
def console(args):
""" Start an interactive ipython console """
user_ns = {'tk': sisyphus.toolkit,
'config_files': args.config_files,
}
if args.load:
jobs = [sisyphus.toolkit.load_job(i) for i in args.load]
user_ns['jobs'] = jobs
for i, job in enumerate(jobs):
print("jobs[%i]: %s" % (i, job))
elif not args.not_load_config:
load_configs(args.config_files)
# TODO Update welcome message
welcome_msg = """
Info: IPCompleter.greedy = True is set to True.
This allows to auto complete lists and dictionaries entries, but may evaluates functions on tab.
Enter tk? for help"""
import IPython
from traitlets.config.loader import Config
c = Config()
c.InteractiveShell.banner2 = welcome_msg
c.IPCompleter.greedy = True
c.InteractiveShellApp.exec_lines = ['%rehashx'] + args.commands
IPython.start_ipython(config=c, argv=[], user_ns=user_ns)
# ### Notebook stuff, needs more testing
# TODO currently not working