本文整理汇总了Python中traitlets.config.manager.BaseJSONConfigManager.file_name方法的典型用法代码示例。如果您正苦于以下问题:Python BaseJSONConfigManager.file_name方法的具体用法?Python BaseJSONConfigManager.file_name怎么用?Python BaseJSONConfigManager.file_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traitlets.config.manager.BaseJSONConfigManager
的用法示例。
在下文中一共展示了BaseJSONConfigManager.file_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: toggle_install
# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import file_name [as 别名]
def toggle_install(install, user=False, sys_prefix=False, overwrite=False,
symlink=False, prefix=None, nbextensions_dir=None,
logger=None):
"""Install or remove all jupyter_contrib_nbextensions."""
if notebook_is_running():
raise NotebookRunningError(
'Cannot configure while the Jupyter notebook server is running')
user = False if sys_prefix else user
config_dir = nbextensions._get_config_dir(user=user, sys_prefix=sys_prefix)
verb = 'Installing' if install else 'Uninstalling'
if logger:
logger.info(
'{} jupyter_contrib_nbextensions, using config in {}'.format(
verb, config_dir))
# Configure the jupyter_nbextensions_configurator serverextension to load
if install:
serverextensions.toggle_serverextension_python(
'jupyter_nbextensions_configurator',
enabled=True, user=user, sys_prefix=sys_prefix, logger=logger)
# nbextensions:
kwargs = dict(user=user, sys_prefix=sys_prefix, prefix=prefix,
nbextensions_dir=nbextensions_dir, logger=logger)
if install:
nbextensions.install_nbextension_python(
jupyter_contrib_nbextensions.__name__,
overwrite=overwrite, symlink=symlink, **kwargs)
else:
nbextensions.uninstall_nbextension_python(
jupyter_contrib_nbextensions.__name__, **kwargs)
# Set extra template path, pre- and post-processors for nbconvert
cm = BaseJSONConfigManager(config_dir=config_dir)
config_basename = 'jupyter_nbconvert_config'
config = cm.get(config_basename)
# avoid warnings about unset version
config.setdefault('version', 1)
if logger:
logger.info(
u'- Editing config: {}'.format(cm.file_name(config_basename)))
# Set extra template path, pre- and post-processors for nbconvert
if logger:
logger.info('-- Configuring nbconvert template path')
# our templates directory
_update_config_list(config, 'Exporter.template_path', [
'.',
jupyter_contrib_nbextensions.nbconvert_support.templates_directory(),
], install)
# our preprocessors
if logger:
logger.info('-- Configuring nbconvert preprocessors')
proc_mod = 'jupyter_contrib_nbextensions.nbconvert_support'
_update_config_list(config, 'Exporter.preprocessors', [
proc_mod + '.CodeFoldingPreprocessor',
proc_mod + '.PyMarkdownPreprocessor',
], install)
# our postprocessor class
if logger:
logger.info('-- Configuring nbconvert postprocessor_class')
if install:
config.setdefault(
'NbConvertApp', Config())['postprocessor_class'] = (
proc_mod + '.EmbedPostProcessor')
else:
nbconvert_conf = config.get('NbConvertApp', Config())
if (nbconvert_conf.get('postprocessor_class') ==
proc_mod + '.EmbedPostProcessor'):
nbconvert_conf.pop('postprocessor_class')
if len(nbconvert_conf) < 1:
config.pop('NbConvertApp')
if logger:
logger.info(
u'- Writing config: {}'.format(cm.file_name(config_basename)))
_set_managed_config(cm, config_basename, config, logger=logger)
示例2: toggle_install_config
# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import file_name [as 别名]
def toggle_install_config(install, user=False, sys_prefix=False,
skip_running_check=False, logger=None):
"""Install/remove contrib nbextensions to/from jupyter_nbconvert_config."""
_err_on_running(skip_running_check=skip_running_check)
_check_conflicting_kwargs(user=user, sys_prefix=sys_prefix)
config_dir = nbextensions._get_config_dir(user=user, sys_prefix=sys_prefix)
if logger:
logger.info(
'{} jupyter_contrib_nbextensions items {} config in {}'.format(
'Installing' if install else 'Uninstalling',
'to' if install else 'from',
config_dir))
# Configure the jupyter_nbextensions_configurator serverextension to load
if install:
configurator_app = EnableJupyterNbextensionsConfiguratorApp(
user=user, sys_prefix=sys_prefix, logger=logger)
configurator_app.start()
nbextensions.enable_nbextension(
'notebook', 'contrib_nbextensions_help_item/main',
user=user, sys_prefix=sys_prefix, logger=logger)
else:
nbconf_cm = BaseJSONConfigManager(
config_dir=os.path.join(config_dir, 'nbconfig'))
for require, section in {
'contrib_nbextensions_help_item/main': 'notebook'}.items():
if logger:
logger.info('- Disabling {}'.format(require))
logger.info(
'-- Editing config: {}'.format(
nbconf_cm.file_name(section)))
nbconf_cm.update(section, {'load_extensions': {require: None}})
# Set extra template path, pre- and post-processors for nbconvert
cm = BaseJSONConfigManager(config_dir=config_dir)
config_basename = 'jupyter_nbconvert_config'
config = cm.get(config_basename)
# avoid warnings about unset version
config.setdefault('version', 1)
if logger:
logger.info(
u'- Editing config: {}'.format(cm.file_name(config_basename)))
# Set extra template path, pre- and post-processors for nbconvert
if logger:
logger.info('-- Configuring nbconvert template path')
# our templates directory
_update_config_list(config, 'Exporter.template_path', [
'.',
jupyter_contrib_nbextensions.nbconvert_support.templates_directory(),
], install)
# our preprocessors
if logger:
logger.info('-- Configuring nbconvert preprocessors')
proc_mod = 'jupyter_contrib_nbextensions.nbconvert_support'
_update_config_list(config, 'Exporter.preprocessors', [
proc_mod + '.CodeFoldingPreprocessor',
proc_mod + '.PyMarkdownPreprocessor',
], install)
if logger:
logger.info(
u'- Writing config: {}'.format(cm.file_name(config_basename)))
_set_managed_config(cm, config_basename, config, logger=logger)
示例3: _uninstall_pre_config
# 需要导入模块: from traitlets.config.manager import BaseJSONConfigManager [as 别名]
# 或者: from traitlets.config.manager.BaseJSONConfigManager import file_name [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