Python traitlets.config.Config() Examples
The following are 30
code examples of traitlets.config.Config().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
traitlets.config
, or try the search function
.
Example #1
Source File: utils_test.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, **kwargs): c = Config() c.DaskGateway.backend_class = InProcessBackend config2 = kwargs.pop("config", None) c.DaskGateway.address = "127.0.0.1:0" c.Proxy.address = "127.0.0.1:0" c.DaskGateway.authenticator_class = ( "dask_gateway_server.auth.SimpleAuthenticator" ) c.DaskGateway.update(kwargs) if config2: c.merge(config2) self.config = c
Example #2
Source File: test_auth.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_basic_auth_password(): config = Config() config.DaskGateway.authenticator_class = ( "dask_gateway_server.auth.SimpleAuthenticator" ) config.SimpleAuthenticator.password = "mypass" async with temp_gateway(config=config) as g: auth = BasicAuth() async with g.gateway_client(auth=auth) as gateway: with pytest.raises(Exception): await gateway.list_clusters() auth.password = "mypass" await gateway.list_clusters()
Example #3
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_idle_timeout(): config = Config() config.ClusterConfig.idle_timeout = 2 async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: # Start a cluster cluster = await gateway.new_cluster() # Add some workers await cluster.scale(2) await wait_for_workers(cluster, atleast=1) waited = 0 while await gateway.list_clusters(): await asyncio.sleep(0.25) waited += 0.25 if waited >= 5: assert False, "Failed to automatically shutdown in time" # Calling shutdown doesn't break anything await cluster.shutdown()
Example #4
Source File: test_auth.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_kerberos_auth(): config = Config() config.Proxy.address = "master.example.com:0" config.DaskGateway.authenticator_class = ( "dask_gateway_server.auth.KerberosAuthenticator" ) config.KerberosAuthenticator.keytab = KEYTAB_PATH async with temp_gateway(config=config) as g: async with g.gateway_client(auth="kerberos") as gateway: kdestroy() with pytest.raises(Exception): await gateway.list_clusters() kinit() await gateway.list_clusters() kdestroy()
Example #5
Source File: eventlog.py From telemetry with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _load_config(self, cfg, section_names=None, traits=None): """Load EventLog traits from a Config object, patching the handlers trait in the Config object to avoid deepcopy errors. """ my_cfg = self._find_my_config(cfg) handlers = my_cfg.pop("handlers", []) # Turn handlers list into a pickeable function def get_handlers(): return handlers my_cfg["handlers"] = get_handlers # Build a new eventlog config object. eventlog_cfg = Config({"EventLog": my_cfg}) super(EventLog, self)._load_config(eventlog_cfg, section_names=None, traits=None)
Example #6
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_worker_fails_after_connect(): config = Config() config.DaskGateway.backend_class = TracksStopWorkerCalls config.TracksStopWorkerCalls.cluster_heartbeat_period = 1 config.TracksStopWorkerCalls.check_timeouts_period = 0.5 async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: async with gateway.new_cluster() as cluster: await cluster.scale(1) await wait_for_workers(cluster, atleast=1) # Close the worker worker = list(g.gateway.backend.workers.values())[0] await worker.close(1) # Stop cluster called to cleanup after failure await asyncio.wait_for(g.gateway.backend.stop_worker_called, 30)
Example #7
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_worker_fails_during_start(fail_stage): config = Config() config.DaskGateway.backend_class = WorkerFailsDuringStart config.WorkerFailsDuringStart.fail_stage = fail_stage async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: async with gateway.new_cluster() as cluster: await cluster.scale(1) # Wait for worker failure await asyncio.wait_for(g.gateway.backend.stop_worker_called, 5) # Stop worker called with last reported state res = {} if fail_stage == 0 else {"i": fail_stage - 1} assert g.gateway.backend.stop_worker_state == res
Example #8
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_slow_worker_start(start_timeout, state): config = Config() config.DaskGateway.backend_class = WorkerSlowToStart config.WorkerSlowToStart.worker_start_timeout = start_timeout config.WorkerSlowToStart.check_timeouts_period = 0.05 async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: async with gateway.new_cluster() as cluster: await cluster.scale(1) # Wait for worker failure await asyncio.wait_for(g.gateway.backend.stop_worker_called, 5) # Stop worker called with last reported state assert g.gateway.backend.stop_worker_state == {"i": state}
Example #9
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_cluster_fails_after_connect(): config = Config() config.DaskGateway.backend_class = ClusterFailsAfterConnect config.DaskGateway.log_level = "DEBUG" config.ClusterFailsAfterConnect.cluster_heartbeat_period = 1 config.ClusterFailsAfterConnect.check_timeouts_period = 0.5 async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: # Cluster starts successfully async with gateway.new_cluster() as cluster: # Kill scheduler scheduler = g.gateway.backend.schedulers[cluster.name] await scheduler.close(fast=True) scheduler.stop() # Gateway notices and cleans up cluster in time await asyncio.wait_for(g.gateway.backend.stop_cluster_called, 5)
Example #10
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_cluster_fails_between_start_and_connect(): config = Config() config.DaskGateway.backend_class = ClusterFailsBetweenStartAndConnect config.ClusterFailsBetweenStartAndConnect.cluster_status_period = 0.1 async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: # Submit cluster cluster_id = await gateway.submit() # Connect and wait for start failure with pytest.raises(GatewayClusterError) as exc: await asyncio.wait_for(gateway.connect(cluster_id), 5) assert cluster_id in str(exc.value) assert "failed to start" in str(exc.value) assert g.gateway.backend.status == "stopped"
Example #11
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_cluster_fails_during_start(fail_stage): config = Config() config.DaskGateway.backend_class = ClusterFailsDuringStart config.ClusterFailsDuringStart.fail_stage = fail_stage async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: # Submission fails due to error during start cluster_id = await gateway.submit() with pytest.raises(GatewayClusterError) as exc: async with gateway.connect(cluster_id): pass assert cluster_id in str(exc.value) # Stop cluster called with last reported state res = {} if fail_stage == 0 else {"i": fail_stage - 1} assert g.gateway.backend.stop_cluster_state == res
Example #12
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_slow_cluster_connect(): config = Config() config.DaskGateway.backend_class = ClusterSlowToStart config.ClusterSlowToStart.check_timeouts_period = 0.05 config.ClusterSlowToStart.cluster_start_timeout = 0.1 config.ClusterSlowToStart.pause_time = 0 config.DaskGateway.log_level = "DEBUG" async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: # Submission fails due to connect timeout cluster_id = await gateway.submit() with pytest.raises(GatewayClusterError) as exc: async with gateway.connect(cluster_id): pass assert cluster_id in str(exc.value) # Stop cluster called with last reported state assert g.gateway.backend.stop_cluster_state == {"state": 3}
Example #13
Source File: config.py From phy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def load_master_config(config_dir=None): """Load a master Config file from the user configuration file (by default, this is `~/.phy/phy_config.py`).""" config_dir = config_dir or phy_config_dir() path = config_dir / 'phy_config.py' # Create a default config file if necessary. if not path.exists(): ensure_dir_exists(path.parent) logger.debug("Creating default phy config file at `%s`.", path) path.write_text(_default_config(config_dir=config_dir)) assert path.exists() try: return load_config(path) except Exception as e: # pragma: no cover logger.error(e) return {}
Example #14
Source File: test_deprecations.py From dockerspawner with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_deprecated_config(caplog): cfg = Config() cfg.DockerSpawner.image_whitelist = {"1.0": "jupyterhub/singleuser:1.0"} log = logging.getLogger("testlog") spawner = DockerSpawner(config=cfg, log=log) assert caplog.record_tuples == [ ( log.name, logging.WARNING, 'DockerSpawner.image_whitelist is deprecated in DockerSpawner 0.12.0, use ' 'DockerSpawner.allowed_images instead', ) ] assert spawner.allowed_images == {"1.0": "jupyterhub/singleuser:1.0"}
Example #15
Source File: asciidoc.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def default_config(self): c = Config({ 'NbConvertBase': { 'display_data_priority': ['text/html', 'text/markdown', 'image/svg+xml', 'image/png', 'image/jpeg', 'text/plain', 'text/latex' ] }, 'ExtractOutputPreprocessor': {'enabled': True}, 'HighlightMagicsPreprocessor': { 'enabled':True }, }) c.merge(super(ASCIIDocExporter, self).default_config) return c
Example #16
Source File: latex.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def default_config(self): c = Config({ 'NbConvertBase': { 'display_data_priority' : ['text/latex', 'application/pdf', 'image/png', 'image/jpeg', 'image/svg+xml', 'text/markdown', 'text/plain'] }, 'ExtractOutputPreprocessor': { 'enabled':True }, 'SVG2PDFPreprocessor': { 'enabled':True }, 'LatexPreprocessor': { 'enabled':True }, 'SphinxPreprocessor': { 'enabled':True }, 'HighlightMagicsPreprocessor': { 'enabled':True } }) c.merge(super(LatexExporter,self).default_config) return c
Example #17
Source File: test_spawner.py From kubespawner with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_deprecated_config(): """Deprecated config is handled correctly""" with pytest.warns(DeprecationWarning): c = Config() # both set, non-deprecated wins c.KubeSpawner.singleuser_fs_gid = 5 c.KubeSpawner.fs_gid = 10 # only deprecated set, should still work c.KubeSpawner.hub_connect_ip = '10.0.1.1' c.KubeSpawner.singleuser_extra_pod_config = extra_pod_config = {"key": "value"} c.KubeSpawner.image_spec = 'abc:123' spawner = KubeSpawner(hub=Hub(), config=c, _mock=True) assert spawner.hub.connect_ip == '10.0.1.1' assert spawner.fs_gid == 10 assert spawner.extra_pod_config == extra_pod_config # deprecated access gets the right values, too assert spawner.singleuser_fs_gid == spawner.fs_gid assert spawner.singleuser_extra_pod_config == spawner.extra_pod_config assert spawner.image == 'abc:123'
Example #18
Source File: exporter.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, config=None, **kw): """ Public constructor Parameters ---------- config : :class:`~traitlets.config.Config` User configuration instance. `**kw` Additional keyword arguments passed to parent __init__ """ with_default_config = self.default_config if config: with_default_config.merge(config) super(Exporter, self).__init__(config=with_default_config, **kw) self._init_preprocessors()
Example #19
Source File: markdown.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def default_config(self): c = Config({ 'ExtractOutputPreprocessor': {'enabled': True}, 'NbConvertBase': { 'display_data_priority': ['text/html', 'text/markdown', 'image/svg+xml', 'text/latex', 'image/png', 'image/jpeg', 'text/plain' ] }, 'HighlightMagicsPreprocessor': { 'enabled':True }, }) c.merge(super(MarkdownExporter, self).default_config) return c
Example #20
Source File: controllers.py From indico-plugins with MIT License | 6 votes |
def _process(self): config = Config() config.HTMLExporter.preprocessors = [CppHighlighter] config.HTMLExporter.template_file = 'basic' with self.attachment.file.open() as f: notebook = nbformat.read(f, as_version=4) html_exporter = HTMLExporter(config=config) body, resources = html_exporter.from_notebook_node(notebook) css_code = '\n'.join(resources['inlining'].get('css', [])) nonce = str(uuid4()) html = render_template('previewer_jupyter:ipynb_preview.html', attachment=self.attachment, html_code=body, css_code=css_code, nonce=nonce) response = current_app.response_class(html) # Use CSP to restrict access to possibly malicious scripts or inline JS csp_header = "script-src cdn.mathjax.org 'nonce-{}';".format(nonce) response.headers['Content-Security-Policy'] = csp_header response.headers['X-Webkit-CSP'] = csp_header # IE10 doesn't have proper CSP support, so we need to be more strict response.headers['X-Content-Security-Policy'] = "sandbox allow-same-origin;" return response
Example #21
Source File: html.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def default_config(self): c = Config({ 'NbConvertBase': { 'display_data_priority' : ['application/vnd.jupyter.widget-state+json', 'application/vnd.jupyter.widget-view+json', 'application/javascript', 'text/html', 'text/markdown', 'image/svg+xml', 'text/latex', 'image/png', 'image/jpeg', 'text/plain' ] }, 'CSSHTMLHeaderPreprocessor':{ 'enabled':True }, 'HighlightMagicsPreprocessor': { 'enabled':True } }) c.merge(super(HTMLExporter,self).default_config) return c
Example #22
Source File: templateexporter.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def default_config(self): c = Config({ 'RegexRemovePreprocessor': { 'enabled': True }, 'TagRemovePreprocessor': { 'enabled': True } }) c.merge(super(TemplateExporter, self).default_config) return c
Example #23
Source File: config.py From phy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def save_config(path, config): """Save a Config instance to a JSON file.""" import json config['version'] = 1 with open(path, 'w') as f: json.dump(config, f)
Example #24
Source File: conftest.py From elyra with Apache License 2.0 | 5 votes |
def init_elyra(configurable_serverapp, argv): app = configurable_serverapp(config=Config({'NotebookApp': {"nbserver_extensions": {"elyra": True}}}), argv=argv) yield app app.remove_server_info_file() app.remove_browser_open_file() app.cleanup_kernels()
Example #25
Source File: exporter.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def default_config(self): return Config()
Example #26
Source File: test_db_backend.py From dask-gateway with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_worker_start_failure_limit(): config = Config() config.DaskGateway.backend_class = WorkerFailsDuringStart async with temp_gateway(config=config) as g: async with g.gateway_client() as gateway: async with gateway.new_cluster() as cluster: await cluster.scale(1) # Wait for cluster failure await asyncio.wait_for(g.gateway.backend.stop_cluster_called, 10)
Example #27
Source File: ipynb_to_html.py From blogger-cli with MIT License | 5 votes |
def gen_exporter(): config = TraitletsConfig() config.htmlexporter.preprocessors = [ "nbconvert.preprocessors.extractoutputpreprocessor" ] html_exporter = HTMLExporter(config=config) html_exporter.template_file = "basic" return html_exporter
Example #28
Source File: test_auth.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def jupyterhub_auth() -> Authenticator: config = Config() config.Authenticator.plugin_class = JupyterHubAuthPlugin auth = Authenticator(config=config) return auth
Example #29
Source File: config.py From phy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def load_config(path=None): """Load a Python or JSON config file and return a `Config` instance.""" if not path: return Config() path = Path(path) if not path.exists(): # pragma: no cover return Config() file_ext = path.suffix logger.debug("Load config file `%s`.", path) if file_ext == '.py': config = PyFileConfigLoader(path.name, str(path.parent), log=logger).load_config() elif file_ext == '.json': config = JSONFileConfigLoader(path.name, str(path.parent), log=logger).load_config() return config
Example #30
Source File: test_clearsolutions.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_old_config(self): """Are deprecations handled cleanly?""" c = Config() c.ClearSolutions.code_stub = "foo" pp = ClearSolutions(config=c) assert pp.code_stub == dict(python="foo")