Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from spyder.utils.programs import is_module_installed
else:
# We add "spyder" to sys.path for external interpreters,
# so this works!
# See create_kernel_spec of plugins/ipythonconsole
from config.main import CONF
from utils.programs import is_module_installed
# ---- IPython config ----
try:
profile_path = osp.join(get_ipython_dir(), 'profile_default')
cfg = load_pyconfig_files(['ipython_config.py',
'ipython_kernel_config.py'],
profile_path)
except:
cfg = Config()
# ---- Spyder config ----
spy_cfg = Config()
# Until we implement Issue 1052
spy_cfg.InteractiveShell.xmode = 'Plain'
# Run lines of code at startup
run_lines_o = CONF.get('ipython_console', 'startup/run_lines')
if run_lines_o:
spy_cfg.IPKernelApp.exec_lines = [x.strip() for x in run_lines_o.split(',')]
else:
spy_cfg.IPKernelApp.exec_lines = []
# Clean terminal arguments input
clear_argv = "import sys;sys.argv = [''];del sys"
def _ensure_subconfig(self):
"""ensure that sub-dicts that should be Config objects are
casts dicts that are under section keys to Config objects,
which is necessary for constructing Config objects from dict literals.
"""
for key in self:
obj = self[key]
if _is_section_key(key) \
and isinstance(obj, dict) \
and not isinstance(obj, Config):
setattr(self, key, Config(obj))
# banner directly, so we write it to stdout before starting the IPython app
io.stdout.write(self.banner)
# Pass exec_lines in order to start autoreload
if self.ipy_autoreload:
if not isinstance(self.ipy_autoreload, bool):
mode = self.ipy_autoreload
else:
mode = 2
logger.debug(f"Initializing IPython autoreload in mode {mode}")
exec_lines = [
"import konch as __konch",
f"__konch.IPythonShell.init_autoreload({mode})",
]
else:
exec_lines = []
ipy_config = IPyConfig()
if self.ipy_colors:
ipy_config.TerminalInteractiveShell.colors = self.ipy_colors
if self.ipy_highlighting_style:
ipy_config.TerminalInteractiveShell.highlighting_style = (
self.ipy_highlighting_style
)
configure_ipython_prompt(ipy_config, prompt=self.prompt, output=self.output)
# Use start_ipython rather than embed so that IPython is loaded in the "normal"
# way. See https://github.com/django/django/pull/512
start_ipython(
display_banner=False,
user_ns=self.context,
config=ipy_config,
extensions=self.ipy_extensions or [],
exec_lines=exec_lines,
argv=[],
import yt.mods
import yt
import IPython
local_ns = yt.mods.__dict__.copy()
local_ns['ds'] = args.ds
local_ns['pf'] = args.ds
local_ns['yt'] = yt
try:
from traitlets.config.loader import Config
except ImportError:
from IPython.config.loader import Config
import sys
cfg = Config()
# prepend sys.path with current working directory
sys.path.insert(0,'')
IPython.embed(config=cfg,user_ns=local_ns)
def launch_scheduler(in_addr, out_addr, mon_addr, not_addr, reg_addr, config=None,
logname='root', log_url=None, loglevel=logging.DEBUG,
identity=b'task', in_thread=False):
ZMQStream = zmqstream.ZMQStream
if config:
# unwrap dict back into Config
config = Config(config)
if in_thread:
# use instance() to get the same Context/Loop as our parent
ctx = zmq.Context.instance()
loop = ioloop.IOLoop.current()
else:
# in a process, don't use instance()
# for safety with multiprocessing
ctx = zmq.Context()
loop = ioloop.IOLoop()
ins = ZMQStream(ctx.socket(zmq.ROUTER),loop)
util.set_hwm(ins, 0)
ins.setsockopt(zmq.IDENTITY, identity + b'_in')
ins.bind(in_addr)
outs = ZMQStream(ctx.socket(zmq.ROUTER),loop)
}, "Show the application's configuration (json format)"),
}
# subcommands for launching other applications
# if this is not empty, this will be a parent Application
# this must be a dict of two-tuples,
# the first element being the application class/import string
# and the second being the help string for the subcommand
subcommands = Dict()
# parse_command_line will initialize a subapp, if requested
subapp = Instance('traitlets.config.application.Application', allow_none=True)
# extra command-line arguments that don't set config values
extra_args = List(Unicode())
cli_config = Instance(Config, (), {},
help="""The subset of our configuration that came from the command-line
We re-load this configuration after loading config files,
to ensure that it maintains highest priority.
"""
)
_loaded_config_files = List()
show_config = Bool(
help="Instead of starting the Application, dump configuration to stdout"
).tag(config=True)
show_config_json = Bool(
help="Instead of starting the Application, dump configuration to stdout (as JSON)"
).tag(config=True)
"""extract my config from a global Config object
will construct a Config object of only the config values that apply to me
based on my mro(), as well as those of my parent(s) if they exist.
If I am Bar and my parent is Foo, and their parent is Tim,
this will return merge following config sections, in this order::
[Bar, Foo.Bar, Tim.Foo.Bar]
With the last item being the highest priority.
"""
cfgs = [cfg]
if self.parent:
cfgs.append(self.parent._find_my_config(cfg))
my_config = Config()
for c in cfgs:
for sname in self.section_names():
# Don't do a blind getattr as that would cause the config to
# dynamically create the section with name Class.__name__.
if c._has_section(sname):
my_config.merge(c[sname])
return my_config
def embed_ipython():
warnings.filterwarnings("ignore", category=UserWarning)
c = Config()
if ipython_version[0] >= 5 :
from IPython.terminal.prompts import ClassicPrompts
c.TerminalInteractiveShell.prompts_class = ClassicPrompts
else:
c.PromptManager.in_template = '>>> '
c.PromptManager.in2_template = '... '
c.PromptManager.out_template = ''
c.InteractiveShell.banner1 = "\nhiss - python{0}.{1}\n".format(*sys.version_info[0:2])
c.PrefilterManager.multi_line_specials = True
c.InteractiveShell.autoindent = True
c.InteractiveShell.colors = 'linux'
c.InteractiveShell.confirm_exit = False
embed(config=c)
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)