本文整理匯總了Python中traitlets.config.loader.PyFileConfigLoader方法的典型用法代碼示例。如果您正苦於以下問題:Python loader.PyFileConfigLoader方法的具體用法?Python loader.PyFileConfigLoader怎麽用?Python loader.PyFileConfigLoader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類traitlets.config.loader
的用法示例。
在下文中一共展示了loader.PyFileConfigLoader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_jupytext_configuration_file
# 需要導入模塊: from traitlets.config import loader [as 別名]
# 或者: from traitlets.config.loader import PyFileConfigLoader [as 別名]
def load_jupytext_configuration_file(jupytext_config_file):
"""Read a Jupytext config file, and return a JupytextConfig object"""
if jupytext_config_file.endswith((".toml", "jupytext")):
import toml
config = toml.load(jupytext_config_file)
return JupytextConfiguration(**config)
if jupytext_config_file.endswith((".yml", ".yaml")):
with open(jupytext_config_file) as stream:
config = yaml.safe_load(stream)
return JupytextConfiguration(**config)
if jupytext_config_file.endswith(".py"):
return JupytextConfiguration(
**PyFileConfigLoader(jupytext_config_file).load_config()
)
return JupytextConfiguration(
**JSONFileConfigLoader(jupytext_config_file).load_config()
)
示例2: get_config_from_file
# 需要導入模塊: from traitlets.config import loader [as 別名]
# 或者: from traitlets.config.loader import PyFileConfigLoader [as 別名]
def get_config_from_file(path, content):
# Write config file
filename = 'config.py'
config_file = path / filename
config_file.write_text(content)
# Load written file.
loader = PyFileConfigLoader(filename, path=str(path))
cfg = loader.load_config()
return cfg
示例3: _binderhub_config
# 需要導入模塊: from traitlets.config import loader [as 別名]
# 或者: from traitlets.config.loader import PyFileConfigLoader [as 別名]
def _binderhub_config():
"""Load the binderhub configuration
Currently separate from the app fixture
so that it can have a different scope (only once per session).
"""
cfg = PyFileConfigLoader(minikube_testing_config).load_config()
cfg.BinderHub.build_namespace = TEST_NAMESPACE
global KUBERNETES_AVAILABLE
try:
kubernetes.config.load_kube_config()
except Exception:
cfg.BinderHub.builder_required = False
KUBERNETES_AVAILABLE = False
if ON_TRAVIS:
pytest.fail("Kubernetes should be available on Travis")
else:
KUBERNETES_AVAILABLE = True
if REMOTE_BINDER:
return
# check if Hub is running and ready
try:
requests.get(cfg.BinderHub.hub_url, timeout=5, allow_redirects=False)
except Exception as e:
print(f"JupyterHub not available at {cfg.BinderHub.hub_url}: {e}")
if ON_TRAVIS:
pytest.fail("JupyterHub should be available on Travis")
cfg.BinderHub.hub_url = ''
else:
print(f"JupyterHub available at {cfg.BinderHub.hub_url}")
return cfg
示例4: app
# 需要導入模塊: from traitlets.config import loader [as 別名]
# 或者: from traitlets.config.loader import PyFileConfigLoader [as 別名]
def app(request, io_loop, _binderhub_config):
"""Launch the BinderHub app
Currently reads minikube test config from the repo.
TODO: support input of test config files.
Detects whether kubernetes is available, and if not disables build.
Detects whether jupyterhub is available, and if not disables launch.
app.url will contain the base URL of binderhub.
"""
if REMOTE_BINDER:
app = RemoteBinderHub()
# wait for the remote binder to be up
remaining = 30
deadline = time.monotonic() + remaining
success = False
last_error = None
while remaining:
try:
requests.get(BINDER_URL, timeout=remaining)
except Exception as e:
print(f"Waiting for binder: {e}")
last_error = e
time.sleep(1)
remaining = deadline - time.monotonic()
else:
success = True
break
if not success:
raise last_error
app.url = BINDER_URL
app._configured_bhub = BinderHub(config=_binderhub_config)
return app
if hasattr(request, 'param') and request.param is True:
# load conf for auth test
cfg = PyFileConfigLoader(minikube_testing_auth_config).load_config()
_binderhub_config.merge(cfg)
bhub = BinderHub.instance(config=_binderhub_config)
bhub.initialize([])
bhub.start(run_loop=False)
# instantiating binderhub configures this
# override again
AsyncHTTPClient.configure(MockAsyncHTTPClient)
def cleanup():
bhub.stop()
BinderHub.clear_instance()
request.addfinalizer(cleanup)
# convenience for accessing binder in tests
bhub.url = f'http://127.0.0.1:{bhub.port}{bhub.base_url}'.rstrip('/')
return bhub