当前位置: 首页>>代码示例>>Python>>正文


Python loader.Config类代码示例

本文整理汇总了Python中traitlets.config.loader.Config的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的traitlets.config.loader.Config类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。