本文整理汇总了Python中IPython.terminal.ipapp.load_default_config方法的典型用法代码示例。如果您正苦于以下问题:Python ipapp.load_default_config方法的具体用法?Python ipapp.load_default_config怎么用?Python ipapp.load_default_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.terminal.ipapp
的用法示例。
在下文中一共展示了ipapp.load_default_config方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _embed_ipython_shell
# 需要导入模块: from IPython.terminal import ipapp [as 别名]
# 或者: from IPython.terminal.ipapp import load_default_config [as 别名]
def _embed_ipython_shell(namespace={}, banner=''):
"""Start an IPython Shell"""
try:
from IPython.terminal.embed import InteractiveShellEmbed
from IPython.terminal.ipapp import load_default_config
except ImportError:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
from IPython.frontend.terminal.ipapp import load_default_config
@wraps(_embed_ipython_shell)
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()
return wrapper
示例2: embed
# 需要导入模块: from IPython.terminal import ipapp [as 别名]
# 或者: from IPython.terminal.ipapp import load_default_config [as 别名]
def embed(**kwargs):
"""Call this to embed IPython at the current point in your program.
The first invocation of this will create an :class:`InteractiveShellEmbed`
instance and then call it. Consecutive calls just call the already
created instance.
If you don't want the kernel to initialize the namespace
from the scope of the surrounding function,
and/or you want to load full IPython configuration,
you probably want `IPython.start_ipython()` instead.
Here is a simple example::
from IPython import embed
a = 10
b = 20
embed('First time')
c = 30
d = 40
embed
Full customization can be done by passing a :class:`Config` in as the
config argument.
"""
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
shell = InteractiveShellEmbed.instance(**kwargs)
shell(header=header, stack_depth=2, compile_flags=compile_flags)
示例3: embed
# 需要导入模块: from IPython.terminal import ipapp [as 别名]
# 或者: from IPython.terminal.ipapp import load_default_config [as 别名]
def embed(**kwargs):
"""
Copied from `IPython/terminal/embed.py`, but using our `InteractiveShellEmbed` instead.
"""
config = kwargs.get("config")
header = kwargs.pop("header", "")
compile_flags = kwargs.pop("compile_flags", None)
if config is None:
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
kwargs["config"] = config
shell = InteractiveShellEmbed.instance(**kwargs)
initialize_extensions(shell, config["InteractiveShellApp"]["extensions"])
shell(header=header, stack_depth=2, compile_flags=compile_flags)
示例4: shell
# 需要导入模块: from IPython.terminal import ipapp [as 别名]
# 或者: from IPython.terminal.ipapp import load_default_config [as 别名]
def shell(ipython_args):
"""Runs a shell in the app context.
Runs an interactive Python shell in the context of a given
Flask application. The application will populate the default
namespace of this shell according to it's configuration.
This is useful for executing small snippets of management code
without having to manually configuring the application.
"""
import IPython
from IPython.terminal.ipapp import load_default_config
from traitlets.config.loader import Config
from flask.globals import _app_ctx_stack
app = _app_ctx_stack.top.app
if 'IPYTHON_CONFIG' in app.config:
config = Config(app.config['IPYTHON_CONFIG'])
else:
config = load_default_config()
config.TerminalInteractiveShell.banner1 = '''Python %s on %s
IPython: %s
App: %s [%s]
Instance: %s''' % (sys.version,
sys.platform,
IPython.__version__,
app.import_name,
app.env,
app.instance_path)
IPython.start_ipython(
argv=ipython_args,
user_ns=app.make_shell_context(),
config=config,
)
示例5: shell
# 需要导入模块: from IPython.terminal import ipapp [as 别名]
# 或者: from IPython.terminal.ipapp import load_default_config [as 别名]
def shell(ipython_args):
"""Runs a shell in the app context.
Runs an interactive Python shell in the context of a given
Flask application. The application will populate the default
namespace of this shell according to it's configuration.
This is useful for executing small snippets of management code
without having to manually configuring the application.
"""
from sys import version, platform
from flask.globals import _app_ctx_stack
app = _app_ctx_stack.top.app
ctx = app.make_shell_context()
try:
from IPython import __version__ as ipython_version, start_ipython
from IPython.terminal.ipapp import load_default_config
from traitlets.config.loader import Config
if 'IPYTHON_CONFIG' in app.config:
config = Config(app.config['IPYTHON_CONFIG'])
else:
config = load_default_config()
config.TerminalInteractiveShell.banner1 = '''Python {} on {}
IPython: {}
App: {}{}
Instance: {}'''.format(version,
platform,
ipython_version,
app.import_name,
app.debug and ' [debug]' or '',
app.instance_path)
start_ipython(
argv=ipython_args,
user_ns=ctx,
config=config,
)
except ImportError:
# fallback to standard python interactive console
from code import interact
banner = '''Python {} on {}
App: {}{}
Instance: {}'''.format(version,
platform,
app.import_name,
app.debug and ' [debug]' or '',
app.instance_path)
interact(local=ctx, banner=banner)
示例6: start
# 需要导入模块: from IPython.terminal import ipapp [as 别名]
# 或者: from IPython.terminal.ipapp import load_default_config [as 别名]
def start(self) -> None:
try:
from ptpython.ipython import embed
from ptpython.repl import run_config
from IPython.terminal.ipapp import load_default_config
except ImportError:
raise ShellNotAvailableError("PtIPython shell not available.")
config_dir = Path("~/.ptpython/").expanduser()
# Apply config file
def configure(repl):
path = config_dir / "config.py"
if path.exists():
run_config(repl, str(path))
# Startup path
startup_paths = []
if "PYTHONSTARTUP" in os.environ:
startup_paths.append(os.environ["PYTHONSTARTUP"])
# exec scripts from startup paths
for path in startup_paths:
if Path(path).exists():
with Path(path).open("rb") as f:
code = compile(f.read(), path, "exec")
exec(code, self.context, self.context)
else:
print(f"File not found: {path}\n\n")
sys.exit(1)
ipy_config = load_default_config()
ipy_config.InteractiveShellEmbed = ipy_config.TerminalInteractiveShell
ipy_config["InteractiveShellApp"]["extensions"] = self.ipy_extensions
configure_ipython_prompt(ipy_config, prompt=self.prompt, output=self.output)
embed(
config=ipy_config,
configure=configure,
history_filename=config_dir / "history",
user_ns=self.context,
header=self.banner,
vi_mode=self.ptpy_vi_mode,
)
return None
示例7: interactive
# 需要导入模块: from IPython.terminal import ipapp [as 别名]
# 或者: from IPython.terminal.ipapp import load_default_config [as 别名]
def interactive(port=None, InterfaceClass=CanInterface, intro='', load_filename=None, can_baud=None):
global c
import atexit
c = InterfaceClass(port=port, load_filename=load_filename)
atexit.register(cleanupInteractiveAtExit)
if load_filename is None:
if can_baud != None:
c.setCanBaud(can_baud)
else:
c.setCanBaud(CAN_500KBPS)
gbls = globals()
lcls = locals()
try:
import IPython.Shell
ipsh = IPython.Shell.IPShell(argv=[''], user_ns=lcls, user_global_ns=gbls)
print intro
ipsh.mainloop(intro)
except ImportError, e:
try:
from IPython.terminal.interactiveshell import TerminalInteractiveShell
from IPython.terminal.ipapp import load_default_config
ipsh = TerminalInteractiveShell(config=load_default_config())
ipsh.user_global_ns.update(gbls)
ipsh.user_global_ns.update(lcls)
ipsh.autocall = 2 # don't require parenthesis around *everything*. be smart!
ipsh.mainloop(intro)
except ImportError, e:
try:
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
ipsh = TerminalInteractiveShell()
ipsh.user_global_ns.update(gbls)
ipsh.user_global_ns.update(lcls)
ipsh.autocall = 2 # don't require parenthesis around *everything*. be smart!
ipsh.mainloop(intro)
except ImportError, e:
print e
shell = code.InteractiveConsole(gbls)
shell.interact(intro)