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


Python BaseJSONConfigManager.get方法代码示例

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


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

示例1: _install_kernelspec_manager

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
def _install_kernelspec_manager(prefix, disable=False):
    CKSM = "beakerx.kernel_spec.BeakerXKernelSpec"
    KSMC = "kernel_spec_class"

    action_prefix = "Dis" if disable else "En"
    log.info("{}abling BeakerX server config...".format(action_prefix))
    path = os.path.join(prefix, "etc", "jupyter")
    if not os.path.exists(path):
        log.debug("Making directory {}...".format(path))
        os.makedirs(path)
    cm = BaseJSONConfigManager(config_dir=path)
    cfg = cm.get("jupyter_notebook_config")
    log.debug("Existing config in {}...\n{}".format(path, _pretty(cfg)))
    nb_app = cfg.setdefault("KernelSpecManager", {})
    if disable and nb_app.get(KSMC, None) == CKSM:
        nb_app.pop(KSMC)
    elif not disable:
        nb_app.update({KSMC: CKSM})

    log.debug("Writing config in {}...".format(path))
    cm.set("jupyter_notebook_config", cfg)
    cfg = cm.get("jupyter_notebook_config")

    log.debug("Verifying config in {}...\n{}".format(path, _pretty(cfg)))
    if disable:
        assert KSMC not in cfg["KernelSpecManager"]
    else:
        assert cfg["KernelSpecManager"][KSMC] == CKSM

    log.info("{}abled BeakerX server config".format(action_prefix))
开发者ID:twosigma,项目名称:beaker-notebook,代码行数:32,代码来源:install.py

示例2: install

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
def install(enable=False, disable=False, prefix=None, verbose=False):
    """Install the nb_conda_kernels config piece.

    Parameters
    ----------
    enable: bool
        Enable the BeakerX server config on every notebook launch
    disable: bool
        Disable BeakerX server config
    """
    if verbose:
        log.setLevel(logging.DEBUG)

    if enable == disable:
        log.error("Please provide (one of) --enable or --disable")
        raise ValueError(enable, disable)

    log.info("{}abling BeakerX server config...".format("En" if enable else "Dis"))

    path = jupyter_config_dir()

    if prefix is not None:
        path = join(prefix, "etc", "jupyter")
        if not exists(path):
            log.debug("Making directory {}...".format(path))
            os.makedirs(path)

    cm = BaseJSONConfigManager(config_dir=path)
    cfg = cm.get("jupyter_notebook_config")

    log.debug("Existing config in {}...\n{}".format(path, pretty(cfg)))

    nb_app = cfg.setdefault("KernelSpecManager", {})

    if enable:
        nb_app.update({KSMC: CKSM})
    elif disable and nb_app.get(KSMC, None) == CKSM:
        nb_app.pop(KSMC)

    log.debug("Writing config in {}...".format(path))

    cm.set("jupyter_notebook_config", cfg)

    cfg = cm.get("jupyter_notebook_config")

    log.debug("Verifying config in {}...\n{}".format(path, pretty(cfg)))

    if enable:
        assert cfg["KernelSpecManager"][KSMC] == CKSM
    else:
        assert KSMC not in cfg["KernelSpecManager"]

    log.info("{}abled BeakerX server config".format("En" if enable else "Dis"))
开发者ID:Jaykul,项目名称:beakerx,代码行数:55,代码来源:install.py

示例3: _install_extension_nb41

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
def _install_extension_nb41(enable=True):
    """deprecated, pre-4.2 implementation of installing notebook extension"""
    # server-side
    server = BaseJSONConfigManager(config_dir=jupyter_config_dir())
    server_cfg = server.get('jupyter_notebook_config')
    app_cfg = server_cfg.get('NotebookApp', {})
    server_extensions = app_cfg.get('server_extensions', [])
    server_ext = 'ipyparallel.nbextension'
    server_changed = False
    if enable and server_ext not in server_extensions:
        server_extensions.append(server_ext)
        server_changed = True
    elif (not enable) and server_ext in server_extensions:
        server_extensions.remove(server_ext)
        server_changed = True
    if server_changed:
        server.update('jupyter_notebook_config', {
            'NotebookApp': {
                'server_extensions': server_extensions,
            }
        })
    
    # frontend config (*way* easier because it's a dict)
    frontend = FrontendConfigManager()
    frontend.update('tree', {
        'load_extensions': {
            'ipyparallel/main': enable or None,
        }
    })
开发者ID:Ruk0610,项目名称:ipyparallel,代码行数:31,代码来源:install.py

示例4: install_server_extension

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
def install_server_extension(enable=True):
    """Register ipyparallel clusters tab as a notebook server extension
    
    Toggle with enable=True/False.
    """
    # server-side
    server = BaseJSONConfigManager(config_dir=jupyter_config_dir())
    server_cfg = server.get('jupyter_notebook_config')
    app_cfg = server_cfg.get('NotebookApp', {})
    server_extensions = app_cfg.get('server_extensions', [])
    server_ext = 'ipyparallel.nbextension'
    server_changed = False
    if enable and server_ext not in server_extensions:
        server_extensions.append(server_ext)
        server_changed = True
    elif (not enable) and server_ext in server_extensions:
        server_extensions.remove(server_ext)
        server_changed = True
    if server_changed:
        server.update('jupyter_notebook_config', {
            'NotebookApp': {
                'server_extensions': server_extensions,
            }
        })
    
    # frontend config (*way* easier because it's a dict)
    frontend = FrontendConfigManager()
    frontend.update('tree', {
        'load_extensions': {
            'ipyparallel/main': enable or None,
        }
    })
开发者ID:AminJamalzadeh,项目名称:ipyparallel,代码行数:34,代码来源:install.py

示例5: list_labextensions

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
    def list_labextensions(self):
        """List all the labextensions"""
        print("Known labextensions:")

        for config_dir in jupyter_config_path():
            cm = BaseJSONConfigManager(parent=self, config_dir=config_dir)
            data = cm.get(CONFIG_NAME)
            labextensions = (
                data.setdefault("LabApp", {})
                .setdefault("labextensions", {})
            )
            if labextensions:
                print(u'config dir: {}'.format(config_dir))
            for name, config in sorted(labextensions.items()):
                if isinstance(config, bool):
                    config = dict(enabled=config)
                enabled = config['enabled']
                full_dest = find_labextension(name)
                print(u'    {} {}: {}'.format(
                              name,
                              GREEN_ENABLED if enabled else RED_DISABLED,
                              full_dest if not None else RED_X+" Files not found"
                              ))
                if full_dest is not None:
                    validate_labextension_folder(name, full_dest, self.log)
开发者ID:Carreau,项目名称:jupyterlab,代码行数:27,代码来源:labextensions.py

示例6: get

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
 def get(self, section_name):
     """Get the config from all config sections."""
     config = {}
     for p in self.read_config_path:
         cm = BaseJSONConfigManager(config_dir=p)
         recursive_update(config, cm.get(section_name))
     return config
开发者ID:AnddyWang,项目名称:notebook,代码行数:9,代码来源:manager.py

示例7: list_nbextensions

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
    def list_nbextensions(self):
        """List all the nbextensions"""
        config_dirs = [os.path.join(p, 'nbconfig') for p in jupyter_config_path()]
        
        print("Known nbextensions:")
        
        for config_dir in config_dirs:
            head = u'  config dir: {}'.format(config_dir)
            head_shown = False

            cm = BaseJSONConfigManager(parent=self, config_dir=config_dir)
            for section in NBCONFIG_SECTIONS:
                data = cm.get(section)
                if 'load_extensions' in data:
                    if not head_shown:
                        # only show heading if there is an nbextension here
                        print(head)
                        head_shown = True
                    print(u'    {} section'.format(section))
                    
                    for require, enabled in data['load_extensions'].items():
                        print(u'      {} {}'.format(
                            require,
                            GREEN_ENABLED if enabled else RED_DISABLED))
                        if enabled:
                            validate_nbextension(require, logger=self.log)
开发者ID:ChunHungLiu,项目名称:notebook,代码行数:28,代码来源:nbextensions.py

示例8: list_nbextensions

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
    def list_nbextensions(self):
        """List all the nbextensions"""
        config_dirs = [os.path.join(p, 'nbconfig') for p in jupyter_config_path()]
        
        print("Known bundlerextensions:")
        
        for config_dir in config_dirs:
            head = u'  config dir: {}'.format(config_dir)
            head_shown = False

            cm = BaseJSONConfigManager(parent=self, config_dir=config_dir)
            data = cm.get('notebook')
            if 'bundlerextensions' in data:
                if not head_shown:
                    # only show heading if there is an nbextension here
                    print(head)
                    head_shown = True
                
                for bundler_id, info in data['bundlerextensions'].items():
                    label = info.get('label')
                    module = info.get('module_name')
                    if label is None or module is None:
                        msg = u'    {} {}'.format(bundler_id, RED_DISABLED)
                    else:
                        msg = u'    "{}" from {} {}'.format(
                            label, module, GREEN_ENABLED
                        )
                    print(msg)
开发者ID:Zsailer,项目名称:notebook,代码行数:30,代码来源:bundlerextensions.py

示例9: list_labextensions

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
 def list_labextensions(self):
     """List all the labextensions"""
     print("Known labextensions:")
     seen = False
     for config_dir in jupyter_config_path():
         config_dir = os.path.join(config_dir, CONFIG_DIR)
         cm = BaseJSONConfigManager(parent=self, config_dir=config_dir)
         labextensions = cm.get('labextensions')
         if labextensions:
             print(u'config dir: {}'.format(config_dir))
             seen = True
         for name, config in sorted(labextensions.items()):
             if isinstance(config, bool):
                 config = dict(enabled=config)
             enabled = config['enabled']
             full_dest = find_labextension(name)
             print(u'    {} {}: {}'.format(
                           name,
                           GREEN_ENABLED if enabled else RED_DISABLED,
                           full_dest if not None else RED_X+" Files not found"
                           ))
             if full_dest is not None:
                 validate_labextension_folder(name, full_dest, self.log)
     if not seen:
         print('....None found!')
开发者ID:rlugojr,项目名称:jupyterlab,代码行数:27,代码来源:labextensions.py

示例10: _set_nbextension_state

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
def _set_nbextension_state(section, require, state, user=True, sys_prefix=False, logger=None):
    """Set whether the section's frontend should require the named nbextension

    Returns True if the final state is the one requested.

    Parameters
    ----------
    section : string
        The section of the server to change, one of NBCONFIG_SECTIONS
    require : string
        An importable AMD module inside the nbextensions static path
    state : bool
        The state in which to leave the extension
    user : bool [default: True]
        Whether to update the user's .jupyter/nbextensions directory
    sys_prefix : bool [default: False]
        Whether to update the sys.prefix, i.e. environment. Will override
        `user`.
    logger : Jupyter logger [optional]
        Logger instance to use
    """
    user = False if sys_prefix else user
    config_dir = os.path.join(_get_config_dir(user=user, sys_prefix=sys_prefix), "nbconfig")
    cm = BaseJSONConfigManager(config_dir=config_dir)
    if logger:
        logger.info("{} {} extension {}...".format("Enabling" if state else "Disabling", section, require))
    cm.update(section, {"load_extensions": {require: state}})

    validate_nbextension(require, logger=logger)

    return cm.get(section).get(require) == state
开发者ID:jhamrick,项目名称:notebook,代码行数:33,代码来源:nbextensions.py

示例11: test_nbextension_disable

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
 def test_nbextension_disable(self):
     self.test_nbextension_enable()
     disable_nbextension(section='notebook', require=u'ƒ')
     
     config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
     cm = BaseJSONConfigManager(config_dir=config_dir)
     enabled = cm.get('notebook').get('load_extensions', {}).get(u'ƒ', False)
     assert not enabled
开发者ID:StantonYTWang,项目名称:notebook,代码行数:10,代码来源:test_nbextensions.py

示例12: test_labextension_disable

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
 def test_labextension_disable(self):
     self.test_labextension_enable()
     disable_labextension(self.name)
     
     config_dir = os.path.join(_get_config_dir(user=True), 'labconfig')
     cm = BaseJSONConfigManager(config_dir=config_dir)
     enabled = cm.get('jupyterlab_config').get('LabApp', {}).get('labextensions', {}).get(self.name, False)
     assert not enabled
开发者ID:aggFTW,项目名称:jupyterlab,代码行数:10,代码来源:test_labextensions.py

示例13: get

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
 def get(self, section_name):
     """Get the config from all config sections."""
     config = {}
     # step through back to front, to ensure front of the list is top priority
     for p in self.read_config_path[::-1]:
         cm = BaseJSONConfigManager(config_dir=p)
         recursive_update(config, cm.get(section_name))
     return config
开发者ID:dougc333,项目名称:TestCode,代码行数:10,代码来源:manager.py

示例14: _set_bundler_state

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
def _set_bundler_state(name, label, module_name, group, state,
                       user=True, sys_prefix=False, logger=None):
    """Set whether a bundler is enabled or disabled.
    
    Returns True if the final state is the one requested.
    
    Parameters
    ----------
    name : string
        Unique name of the bundler
    label : string
        Human-readable label for the bundler menu item in the notebook UI
    module_name : string
        Dotted module/package name containing the bundler
    group : string
        'download' or 'deploy' indicating the parent menu containing the label
    state : bool
        The state in which to leave the extension
    user : bool [default: True]
        Whether to update the user's .jupyter/nbconfig directory
    sys_prefix : bool [default: False]
        Whether to update the sys.prefix, i.e. environment. Will override
        `user`.
    logger : Jupyter logger [optional]
        Logger instance to use
    """
    user = False if sys_prefix else user
    config_dir = os.path.join(
        _get_config_dir(user=user, sys_prefix=sys_prefix), 'nbconfig')
    cm = BaseJSONConfigManager(config_dir=config_dir)
    
    if logger:
        logger.info("{} {} bundler {}...".format(
            "Enabling" if state else "Disabling",
            name,
            module_name
        ))
    
    if state:
        cm.update(BUNDLER_SECTION, {
            BUNDLER_SUBSECTION: {
                name: {
                    "label": label,
                    "module_name": module_name,
                    "group" : group
                }
            }
        })
    else:
        cm.update(BUNDLER_SECTION, {
            BUNDLER_SUBSECTION: {
                name: None
            }
        })

    return (cm.get(BUNDLER_SECTION)
              .get(BUNDLER_SUBSECTION, {})
              .get(name) is not None) == state
开发者ID:jupyter-incubator,项目名称:contentmanagement,代码行数:60,代码来源:bundlerapp.py

示例15: test_labextensionpy_enable

# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import get [as 别名]
 def test_labextensionpy_enable(self):
     self._inject_mock_extension()
     install_labextension_python('mockextension', user=True)
     enable_labextension_python('mockextension')
     
     config_dir = os.path.join(_get_config_dir(user=True), 'labconfig')
     cm = BaseJSONConfigManager(config_dir=config_dir)
     enabled = cm.get('jupyterlab_config').get('LabApp', {}).get('labextensions', {}).get('mockextension', False)
     assert enabled
开发者ID:aggFTW,项目名称:jupyterlab,代码行数:11,代码来源:test_labextensions.py


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