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


Python Config.get方法代码示例

本文整理汇总了Python中traitlets.config.Config.get方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get方法的具体用法?Python Config.get怎么用?Python Config.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在traitlets.config.Config的用法示例。


在下文中一共展示了Config.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_install

# 需要导入模块: from traitlets.config import Config [as 别名]
# 或者: from traitlets.config.Config import get [as 别名]
    def check_install(self, argv=None, dirs=None):
        """Check files were installed in the correct place."""
        if argv is None:
            argv = []
        if dirs is None:
            dirs = {
                'conf': jupyter_core.paths.jupyter_config_dir(),
                'data': jupyter_core.paths.jupyter_data_dir(),
            }
        conf_dir = dirs['conf']

        # do install
        main_app(argv=['enable'] + argv)

        # list everything that got installed
        installed_files = []
        for root, subdirs, files in os.walk(dirs['conf']):
            installed_files.extend([os.path.join(root, f) for f in files])
        nt.assert_true(
            installed_files,
            'Install should create files in {}'.format(dirs['conf']))

        # a bit of a hack to allow initializing a new app instance
        for klass in app_classes:
            reset_app_class(klass)

        # do uninstall
        main_app(argv=['disable'] + argv)
        # check the config directory
        conf_installed = [
            path for path in installed_files
            if path.startswith(conf_dir) and os.path.exists(path)]
        for path in conf_installed:
            with open(path, 'r') as f:
                conf = Config(json.load(f))
            nbapp = conf.get('NotebookApp', {})
            nt.assert_not_in(
                'jupyter_nbextensions_configurator',
                nbapp.get('server_extensions', []),
                'Uninstall should empty'
                'server_extensions list'.format(path))
            nbservext = nbapp.get('nbserver_extensions', {})
            nt.assert_false(
                {k: v for k, v in nbservext.items() if v},
                'Uninstall should disable all '
                'nbserver_extensions in file {}'.format(path))
            confstrip = {}
            confstrip.update(conf)
            confstrip.pop('NotebookApp', None)
            confstrip.pop('version', None)
            nt.assert_false(confstrip, 'Uninstall should leave config empty.')

        reset_app_class(DisableJupyterNbextensionsConfiguratorApp)
开发者ID:gitter-badger,项目名称:jupyter_nbextensions_configurator-1,代码行数:55,代码来源:test_application.py

示例2: _uninstall_pre_config

# 需要导入模块: from traitlets.config import Config [as 别名]
# 或者: from traitlets.config.Config import get [as 别名]
def _uninstall_pre_config(logger=None):
    """Undo config settings inserted by an old (pre-themysto) installation."""
    # for application json config files
    cm = BaseJSONConfigManager(config_dir=jupyter_config_dir())

    # -------------------------------------------------------------------------
    # notebook json config
    config_basename = 'jupyter_notebook_config'
    config = Config(cm.get(config_basename))
    config_path = cm.file_name(config_basename)
    if config and logger:
        logger.info('- Removing old config values from {}'.format(config_path))
    to_remove = ['nbextensions']
    # remove from notebook >= 4.2 key nbserver_extensions
    section = config.get('NotebookApp', Config())
    server_extensions = section.get('nbserver_extensions', {})
    for se in to_remove:
        server_extensions.pop(se, None)
    if len(server_extensions) == 0:
        section.pop('nbserver_extensions', None)
    # and notebook < 4.2 key server_extensions
    _update_config_list(
        config, 'NotebookApp.server_extensions', to_remove, False)
    _update_config_list(config, 'NotebookApp.extra_template_paths', [
        os.path.join(jupyter_data_dir(), 'templates'),
    ], False)
    _set_managed_config(cm, config_basename, config, logger)

    # -------------------------------------------------------------------------
    # nbconvert json config
    config_basename = 'jupyter_nbconvert_config'
    config = Config(cm.get(config_basename))
    if config and logger:
        logger.info('- Removing old config values from {}'.format(config_path))
    _update_config_list(config, 'Exporter.template_path', [
        '.', os.path.join(jupyter_data_dir(), 'templates'),
    ], False)
    _update_config_list(config, 'Exporter.preprocessors', [
        'pre_codefolding.CodeFoldingPreprocessor',
        'pre_pymarkdown.PyMarkdownPreprocessor',
    ], False)
    section = config.get('NbConvertApp', {})
    if (section.get('postprocessor_class') ==
            'post_embedhtml.EmbedPostProcessor'):
        section.pop('postprocessor_class', None)
    if len(section) == 0:
        config.pop('NbConvertApp', None)
    _set_managed_config(cm, config_basename, config, logger)

    # -------------------------------------------------------------------------
    # Remove old config lines from .py configuration files
    for config_basename in ('jupyter_notebook_config.py',
                            'jupyter_nbconvert_config.py'):
        py_config_path = os.path.join(jupyter_config_dir(), config_basename)
        if not os.path.isfile(py_config_path):
            continue
        if logger:
            logger.info(
                '--  Removing now-empty config file {}'.format(py_config_path))
        with io.open(py_config_path, 'r') as f:
            lines = f.readlines()
        marker = '#--- nbextensions configuration ---'
        marker_inds = [ii for ii, l in enumerate(lines) if l.find(marker) >= 0]
        if len(marker_inds) >= 2:
            lines = lines[0:marker_inds[0]] + lines[marker_inds[1] + 1:]
            if [l for l in lines if l.strip]:
                with io.open(py_config_path, 'w') as f:
                    f.writelines(lines)
            else:
                if logger:
                    logger.info(
                        'Removing now-empty config file {}'.format(
                            py_config_path))
                try:
                    os.remove(py_config_path)
                except OSError as ex:
                    if ex.errno != errno.ENOENT:
                        raise
开发者ID:flying-sheep,项目名称:jupyter_contrib_nbextensions,代码行数:80,代码来源:migrate.py


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