本文整理汇总了Python中traitlets.config.loader.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: default
def default(self):
"""
Return a new default configuration object
EXAMPLES::
sage: from sage.repl.configuration import sage_ipython_config
sage: sage_ipython_config.default()
{'InteractiveShell': {'colors': ...
"""
from sage.repl.interpreter import SageTerminalInteractiveShell
cfg = Config(
TerminalIPythonApp=Config(
display_banner=False,
verbose_crash=True,
test_shell=False,
shell_class=SageTerminalInteractiveShell,
),
InteractiveShell=Config(
prompts_class=SagePrompts,
ast_node_interactivity='all',
colors=self.colors(),
simple_prompt=self.simple_prompt(),
term_title=self.term_title(),
confirm_exit=False,
separate_in=''
),
InteractiveShellApp=Config(extensions=[SAGE_EXTENSION]),
)
if self._doctest_mode():
# Using the file-backed history causes problems in parallel tests
cfg.HistoryManager = Config(hist_file=':memory:')
return cfg
开发者ID:robertwb,项目名称:sage,代码行数:33,代码来源:configuration.py
示例2: test_fromdictmerge2
def test_fromdictmerge2(self):
c1 = Config({'Foo' : {'baz' : 2}})
c2 = Config({'Foo' : {'bar' : 1}})
c1.merge(c2)
self.assertEqual(c1.Foo.__class__, Config)
self.assertEqual(c1.Foo.bar, 1)
self.assertEqual(c1.Foo.baz, 2)
self.assertNotIn('baz', c2.Foo)
开发者ID:Carreau,项目名称:traitlets,代码行数:8,代码来源:test_loader.py
示例3: test_fromdictmerge2
def test_fromdictmerge2(self):
c1 = Config({"Foo": {"baz": 2}})
c2 = Config({"Foo": {"bar": 1}})
c1.merge(c2)
self.assertEqual(c1.Foo.__class__, Config)
self.assertEqual(c1.Foo.bar, 1)
self.assertEqual(c1.Foo.baz, 2)
self.assertNotIn("baz", c2.Foo)
开发者ID:willingc,项目名称:traitlets,代码行数:8,代码来源:test_loader.py
示例4: shellwidget_config
def shellwidget_config(self):
"""
Generate a Config instance for shell widgets using our config
system
This lets us create each widget with its own config (as opposed to
IPythonQtConsoleApp, where all widgets have the same config)
"""
# ---- IPython config ----
try:
profile_path = osp.join(get_ipython_dir(), 'profile_default')
full_ip_cfg = load_pyconfig_files(['ipython_qtconsole_config.py'],
profile_path)
# From the full config we only select the IPythonWidget section
# because the others have no effect here.
ip_cfg = Config({'IPythonWidget': full_ip_cfg.IPythonWidget})
except:
ip_cfg = Config()
# ---- Spyder config ----
spy_cfg = Config()
# Make the pager widget a rich one (i.e a QTextEdit)
spy_cfg.IPythonWidget.kind = 'rich'
# Gui completion widget
completion_type_o = CONF.get('ipython_console', 'completion_type')
completions = {0: "droplist", 1: "ncurses", 2: "plain"}
spy_cfg.IPythonWidget.gui_completion = completions[completion_type_o]
# Pager
pager_o = self.get_option('use_pager')
if pager_o:
spy_cfg.IPythonWidget.paging = 'inside'
else:
spy_cfg.IPythonWidget.paging = 'none'
# Calltips
calltips_o = self.get_option('show_calltips')
spy_cfg.IPythonWidget.enable_calltips = calltips_o
# Buffer size
buffer_size_o = self.get_option('buffer_size')
spy_cfg.IPythonWidget.buffer_size = buffer_size_o
# Prompts
in_prompt_o = self.get_option('in_prompt')
out_prompt_o = self.get_option('out_prompt')
if in_prompt_o:
spy_cfg.IPythonWidget.in_prompt = in_prompt_o
if out_prompt_o:
spy_cfg.IPythonWidget.out_prompt = out_prompt_o
# Merge IPython and Spyder configs. Spyder prefs will have prevalence
# over IPython ones
ip_cfg._merge(spy_cfg)
return ip_cfg
开发者ID:G-VAR,项目名称:spyder,代码行数:58,代码来源:ipython.py
示例5: test_merge_no_copies
def test_merge_no_copies(self):
c = Config()
c2 = Config()
c2.Foo.trait = []
c.merge(c2)
c2.Foo.trait.append(1)
self.assertIs(c.Foo, c2.Foo)
self.assertEqual(c.Foo.trait, [1])
self.assertEqual(c2.Foo.trait, [1])
开发者ID:Carreau,项目名称:traitlets,代码行数:9,代码来源:test_loader.py
示例6: test_auto_section
def test_auto_section(self):
c = Config()
self.assertNotIn('A', c)
assert not c._has_section('A')
A = c.A
A.foo = 'hi there'
self.assertIn('A', c)
assert c._has_section('A')
self.assertEqual(c.A.foo, 'hi there')
del c.A
self.assertEqual(c.A, Config())
开发者ID:Carreau,项目名称:traitlets,代码行数:11,代码来源:test_loader.py
示例7: load_config_file
def load_config_file(self, filename, path=None):
"""Load config files by filename and path."""
filename, ext = os.path.splitext(filename)
new_config = Config()
for config in self._load_config_files(filename, path=path, log=self.log,
raise_config_file_errors=self.raise_config_file_errors,
):
new_config.merge(config)
# add self.cli_config to preserve CLI config priority
new_config.merge(self.cli_config)
self.update_config(new_config)
开发者ID:SylvainCorlay,项目名称:traitlets,代码行数:11,代码来源:application.py
示例8: test_collision
def test_collision(self):
a = Config()
b = Config()
self.assertEqual(a.collisions(b), {})
a.A.trait1 = 1
b.A.trait2 = 2
self.assertEqual(a.collisions(b), {})
b.A.trait1 = 1
self.assertEqual(a.collisions(b), {})
b.A.trait1 = 0
self.assertEqual(a.collisions(b), {
'A': {
'trait1': "1 ignored, using 0",
}
})
self.assertEqual(b.collisions(a), {
'A': {
'trait1': "0 ignored, using 1",
}
})
a.A.trait2 = 3
self.assertEqual(b.collisions(a), {
'A': {
'trait1': "0 ignored, using 1",
'trait2': "2 ignored, using 3",
}
})
开发者ID:Carreau,项目名称:traitlets,代码行数:27,代码来源:test_loader.py
示例9: test_merge_exists
def test_merge_exists(self):
c1 = Config()
c2 = Config()
c1.Foo.bar = 10
c1.Foo.bam = 30
c2.Foo.bar = 20
c2.Foo.wow = 40
c1.merge(c2)
self.assertEqual(c1.Foo.bam, 30)
self.assertEqual(c1.Foo.bar, 20)
self.assertEqual(c1.Foo.wow, 40)
c2.Foo.Bam.bam = 10
c1.merge(c2)
self.assertEqual(c1.Foo.Bam.bam, 10)
开发者ID:Carreau,项目名称:traitlets,代码行数:14,代码来源:test_loader.py
示例10: test_deepcopy
def test_deepcopy(self):
c1 = Config()
c1.Foo.bar = 10
c1.Foo.bam = 30
c1.a = 'asdf'
c1.b = range(10)
c1.Test.logger = logging.Logger('test')
c1.Test.get_logger = logging.getLogger('test')
c2 = copy.deepcopy(c1)
self.assertEqual(c1, c2)
self.assertTrue(c1 is not c2)
self.assertTrue(c1.Foo is not c2.Foo)
self.assertTrue(c1.Test is not c2.Test)
self.assertTrue(c1.Test.logger is c2.Test.logger)
self.assertTrue(c1.Test.get_logger is c2.Test.get_logger)
开发者ID:Carreau,项目名称:traitlets,代码行数:15,代码来源:test_loader.py
示例11: load_default_config
def load_default_config(ipython_dir=None):
"""Load the default config file from the default ipython_dir.
This is useful for embedded shells.
"""
if ipython_dir is None:
ipython_dir = get_ipython_dir()
profile_dir = os.path.join(ipython_dir, 'profile_default')
config = Config()
for cf in Application._load_config_files("ipython_config", path=profile_dir):
config.update(cf)
return config
开发者ID:SylvainCorlay,项目名称:ipython,代码行数:15,代码来源:ipapp.py
示例12: test_custom
def test_custom(self):
config = Config()
config.foo = 'foo'
config.bar = 'bar'
c1 = Configurable(config=config)
c2 = Configurable(config=c1.config)
c3 = Configurable(config=c2.config)
self.assertEqual(c1.config, config)
self.assertEqual(c2.config, config)
self.assertEqual(c3.config, config)
# Test that copies are not made
self.assertTrue(c1.config is config)
self.assertTrue(c2.config is config)
self.assertTrue(c3.config is config)
self.assertTrue(c1.config is c2.config)
self.assertTrue(c2.config is c3.config)
开发者ID:marcosptf,项目名称:fedora,代码行数:16,代码来源:test_configurable.py
示例13: test_collision
def test_collision(self):
a = Config()
b = Config()
self.assertEqual(a.collisions(b), {})
a.A.trait1 = 1
b.A.trait2 = 2
self.assertEqual(a.collisions(b), {})
b.A.trait1 = 1
self.assertEqual(a.collisions(b), {})
b.A.trait1 = 0
self.assertEqual(a.collisions(b), {"A": {"trait1": "1 ignored, using 0"}})
self.assertEqual(b.collisions(a), {"A": {"trait1": "0 ignored, using 1"}})
a.A.trait2 = 3
self.assertEqual(b.collisions(a), {"A": {"trait1": "0 ignored, using 1", "trait2": "2 ignored, using 3"}})
开发者ID:willingc,项目名称:traitlets,代码行数:14,代码来源:test_loader.py
示例14: test_merge_doesnt_exist
def test_merge_doesnt_exist(self):
c1 = Config()
c2 = Config()
c2.bar = 10
c2.Foo.bar = 10
c1.merge(c2)
self.assertEqual(c1.Foo.bar, 10)
self.assertEqual(c1.bar, 10)
c2.Bar.bar = 10
c1.merge(c2)
self.assertEqual(c1.Bar.bar, 10)
开发者ID:Carreau,项目名称:traitlets,代码行数:11,代码来源:test_loader.py
示例15: kernel_config
def kernel_config():
"""Create a config object with IPython kernel options"""
import os
from IPython.core.application import get_ipython_dir
from spyderlib.config.main import CONF
from spyderlib.utils.programs import is_module_installed
from traitlets.config.loader import Config, load_pyconfig_files
# ---- IPython config ----
try:
profile_path = osp.join(get_ipython_dir(), 'profile_default')
ip_cfg = load_pyconfig_files(['ipython_config.py',
'ipython_qtconsole_config.py'],
profile_path)
except:
ip_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 = []
# Pylab configuration
mpl_backend = None
mpl_installed = is_module_installed('matplotlib')
pylab_o = CONF.get('ipython_console', 'pylab')
external_interpreter = \
os.environ.get('EXTERNAL_INTERPRETER', '').lower() == "true"
if mpl_installed and pylab_o:
# Get matplotlib backend
if not external_interpreter:
if os.environ["QT_API"] == 'pyqt5':
qt_backend = 'qt5'
else:
qt_backend = 'qt'
backend_o = CONF.get('ipython_console', 'pylab/backend', 0)
backends = {0: 'inline', 1: qt_backend, 2: qt_backend, 3: 'osx',
4: 'gtk', 5: 'wx', 6: 'tk'}
mpl_backend = backends[backend_o]
else:
mpl_backend = 'inline'
# Automatically load Pylab and Numpy, or only set Matplotlib
# backend
autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload')
if autoload_pylab_o:
spy_cfg.IPKernelApp.exec_lines.append(
"%pylab {0}".format(mpl_backend))
else:
spy_cfg.IPKernelApp.exec_lines.append(
"%matplotlib {0}".format(mpl_backend))
# Inline backend configuration
if backends[backend_o] == 'inline':
# Figure format
format_o = CONF.get('ipython_console',
'pylab/inline/figure_format', 0)
formats = {0: 'png', 1: 'svg'}
spy_cfg.InlineBackend.figure_format = formats[format_o]
# Resolution
spy_cfg.InlineBackend.rc = {'figure.figsize': (6.0, 4.0),
'savefig.dpi': 72,
'font.size': 10,
'figure.subplot.bottom': .125,
'figure.facecolor': 'white',
'figure.edgecolor': 'white'
}
resolution_o = CONF.get('ipython_console',
'pylab/inline/resolution')
spy_cfg.InlineBackend.rc['savefig.dpi'] = resolution_o
# Figure size
width_o = float(CONF.get('ipython_console', 'pylab/inline/width'))
height_o = float(CONF.get('ipython_console', 'pylab/inline/height'))
spy_cfg.InlineBackend.rc['figure.figsize'] = (width_o, height_o)
# Run a file at startup
use_file_o = CONF.get('ipython_console', 'startup/use_run_file')
run_file_o = CONF.get('ipython_console', 'startup/run_file')
if use_file_o and run_file_o:
spy_cfg.IPKernelApp.file_to_run = run_file_o
# Autocall
autocall_o = CONF.get('ipython_console', 'autocall')
spy_cfg.ZMQInteractiveShell.autocall = autocall_o
# To handle the banner by ourselves in IPython 3+
spy_cfg.ZMQInteractiveShell.banner1 = ''
#.........这里部分代码省略.........
开发者ID:AminJamalzadeh,项目名称:spyder,代码行数:101,代码来源:start_ipython_kernel.py
示例16: kernel_config
def kernel_config():
"""Create a config object with IPython kernel options."""
from IPython.core.application import get_ipython_dir
from traitlets.config.loader import Config, load_pyconfig_files
if not IS_EXT_INTERPRETER:
from spyder.config.main import CONF
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'
spy_cfg.IPCompleter.use_jedi = False
# 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"
spy_cfg.IPKernelApp.exec_lines.append(clear_argv)
# Pylab configuration
mpl_backend = None
mpl_installed = is_module_installed('matplotlib')
pylab_o = CONF.get('ipython_console', 'pylab')
if mpl_installed and pylab_o:
# Get matplotlib backend
backend_o = CONF.get('ipython_console', 'pylab/backend')
if backend_o == 1:
if is_module_installed('PyQt5'):
auto_backend = 'qt5'
elif is_module_installed('PyQt4'):
auto_backend = 'qt4'
elif is_module_installed('_tkinter'):
auto_backend = 'tk'
else:
auto_backend = 'inline'
else:
auto_backend = ''
backends = {0: 'inline', 1: auto_backend, 2: 'qt5', 3: 'qt4',
4: 'osx', 5: 'gtk3', 6: 'gtk', 7: 'wx', 8: 'tk'}
mpl_backend = backends[backend_o]
# Automatically load Pylab and Numpy, or only set Matplotlib
# backend
autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload')
if autoload_pylab_o:
spy_cfg.IPKernelApp.exec_lines.append(
"%pylab {0}".format(mpl_backend))
else:
spy_cfg.IPKernelApp.exec_lines.append(
"%matplotlib {0}".format(mpl_backend))
# Inline backend configuration
if mpl_backend == 'inline':
# Figure format
format_o = CONF.get('ipython_console',
'pylab/inline/figure_format', 0)
formats = {0: 'png', 1: 'svg'}
spy_cfg.InlineBackend.figure_format = formats[format_o]
# Resolution
if is_module_installed('ipykernel', '<4.5'):
dpi_option = 'savefig.dpi'
else:
dpi_option = 'figure.dpi'
spy_cfg.InlineBackend.rc = {'figure.figsize': (6.0, 4.0),
dpi_option: 72,
'font.size': 10,
'figure.subplot.bottom': .125,
'figure.facecolor': 'white',
'figure.edgecolor': 'white'}
resolution_o = CONF.get('ipython_console',
'pylab/inline/resolution')
spy_cfg.InlineBackend.rc[dpi_option] = resolution_o
# Figure size
#.........这里部分代码省略.........
开发者ID:rlaverde,项目名称:spyder,代码行数:101,代码来源:start_kernel.py
示例17: IPython
The code in this file is deliberately extra-verbose, meant for learning."""
from __future__ import print_function
# The basics to get you going:
# IPython injects get_ipython into builtins, so you can know if you have nested
# copies running.
# Try running this code both at the command line and from inside IPython (with
# %run example-embed.py)
from traitlets.config.loader import Config
try:
get_ipython
except NameError:
nested = 0
cfg = Config()
prompt_config = cfg.PromptManager
prompt_config.in_template = 'In <\\#>: '
prompt_config.in2_template = ' .\\D.: '
prompt_config.out_template = 'Out<\\#>: '
else:
print("Running nested copies of IPython.")
print("The prompts for the nested copy have been modified")
cfg = Config()
nested = 1
# First import the embeddable shell class
from IPython.terminal.embed import InteractiveShellEmbed
# Now create an instance of the embeddable shell. The first argument is a
# string with options exactly as you would type them if you were starting
开发者ID:daofeng2007,项目名称:ipython,代码行数:31,代码来源:embed_class_long.py
示例18: test_fromdictmerge
def test_fromdictmerge(self):
c1 = Config()
c2 = Config({"Foo": {"bar": 1}})
c1.merge(c2)
self.assertEqual(c1.Foo.__class__, Config)
self.assertEqual(c1.Foo.bar, 1)
开发者ID:willingc,项目名称:traitlets,代码行数:6,代码来源:test_loader.py
示例19: kernel_config
def kernel_config():
"""Create a config object with IPython kernel options."""
import ipykernel
from IPython.core.application import get_ipython_dir
from traitlets.config.loader import Config, load_pyconfig_files
# ---- 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'
# - Using Jedi slow completions a lot for objects with big repr's.
# - Jedi completions are not available in Python 2.
if not PY2:
spy_cfg.IPCompleter.use_jedi = False
# Run lines of code at startup
run_lines_o = os.environ.get('SPY_RUN_LINES_O')
if run_lines_o is not None:
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"
spy_cfg.IPKernelApp.exec_lines.append(clear_argv)
# Load %autoreload magic
spy_cfg.IPKernelApp.exec_lines.append(
"get_ipython().kernel._load_autoreload_magic()")
# Default inline backend configuration
# This is useful to have when people doesn't
# use our config system to configure the
# inline backend but want to use
# '%matplotlib inline' at runtime
if LooseVersion(ipykernel.__version__) < LooseVersion('4.5'):
dpi_option = 'savefig.dpi'
else:
dpi_option = 'figure.dpi'
spy_cfg.InlineBackend.rc = {'figure.figsize': (6.0, 4.0),
dpi_option: 72,
'font.size': 10,
'figure.subplot.bottom': .125,
'figure.facecolor': 'white',
'figure.edgecolor': 'white'}
# Pylab configuration
mpl_backend = None
pylab_o = os.environ.get('SPY_PYLAB_O')
if pylab_o == 'True' and is_module_installed('matplotlib'):
# Set Matplotlib backend
backend_o = os.environ.get('SPY_BACKEND_O')
if backend_o is not None:
if backend_o == '1':
if is_module_installed('PyQt5'):
auto_backend = 'qt5'
elif is_module_installed('PyQt4'):
auto_backend = 'qt4'
elif is_module_installed('_tkinter'):
auto_backend = 'tk'
else:
auto_backend = 'inline'
else:
auto_backend = ''
backends = {'0': 'inline',
'1': auto_backend,
'2': 'qt5',
'3': 'qt4',
'4': 'osx',
'5': 'gtk3',
'6': 'gtk',
'7': 'wx',
'8': 'tk'}
mpl_backend = backends[backend_o]
# Automatically load Pylab and Numpy, or only set Matplotlib
# backend
autoload_pylab_o = os.environ.get('SPY_AUTOLOAD_PYLAB_O') == 'True'
command = "get_ipython().kernel._set_mpl_backend('{0}', {1})"
spy_cfg.IPKernelApp.exec_lines.append(
command.format(mpl_backend, autoload_pylab_o))
# Inline backend configuration
if mpl_backend == 'inline':
# Figure format
format_o = os.environ.get('SPY_FORMAT_O')
formats = {'0': 'png',
#.........这里部分代码省略.........
开发者ID:0xBADCA7,项目名称:spyder,代码行数:101,代码来源:start_kernel.py
示例20: print
src = 'nbextensions'
destination = os.path.join(data_dir, 'nbextensions')
print("Install notebook extensions to %s" % destination)
recursive_overwrite(src, destination)
#
# 3. Update nbconvert configuration
#
json_config = os.path.join(jupyter_config_dir(), 'jupyter_nbconvert_config.json')
print("Configuring %s" % json_config)
if os.path.isfile(json_config) is True:
cl = JSONFileConfigLoader(json_config)
config = cl.load_config()
else:
config = Config()
newconfig = Config()
# Set template path, pre- and postprocessors of notebook extensions
newconfig.Exporter.template_path = [os.path.join(data_dir, 'templates')]
newconfig.Exporter.preprocessors = ["pre_codefolding.CodeFoldingPreprocessor", "pre_pymarkdown.PyMarkdownPreprocessor"]
newconfig.NbConvertApp.postprocessor_class = 'post_embedhtml.EmbedPostProcessor'
config.merge(newconfig)
config.version = 1
s=json.dumps(config, indent=2, separators=(',', ': '), sort_keys=True)
with open(json_config, 'w') as f:
f.write(s)
py_config = os.path.join(jupyter_config_dir(), 'jupyter_nbconvert_config.py')
print("Configuring %s" % py_config)
new_py_config = 'jupyter_nbconvert_config.py'
开发者ID:mangorilla,项目名称:IPython-notebook-extensions,代码行数:31,代码来源:setup.py
注:本文中的traitlets.config.loader.Config类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论