-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from tangkong/enh_config_client
ENH: Add ability to instantiate Client from configuration file
- Loading branch information
Showing
7 changed files
with
282 additions
and
12 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
docs/source/upcoming_release_notes/54-enh_config_client.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
54 enh_config_client | ||
#################### | ||
|
||
API Breaks | ||
---------- | ||
- N/A | ||
|
||
Features | ||
-------- | ||
- Adds ability for Client to search for configuration files, and load settings from them. | ||
|
||
Bugfixes | ||
-------- | ||
- N/A | ||
|
||
Maintenance | ||
----------- | ||
- N/A | ||
|
||
Contributors | ||
------------ | ||
- tangkong |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
__all__ = ['BACKENDS'] | ||
|
||
import logging | ||
from typing import Dict | ||
|
||
from .core import _Backend | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
BACKENDS: Dict[str, _Backend] = {} | ||
|
||
|
||
def _get_backend(backend: str) -> _Backend: | ||
if backend == 'filestore': | ||
from .filestore import FilestoreBackend | ||
return FilestoreBackend | ||
if backend == 'test': | ||
from .test import TestBackend | ||
return TestBackend | ||
|
||
raise ValueError(f"Unknown backend {backend}") | ||
|
||
|
||
def _init_backends() -> Dict[str, _Backend]: | ||
backends = {} | ||
|
||
try: | ||
backends['filestore'] = _get_backend('filestore') | ||
except ImportError as ex: | ||
logger.debug(f"Filestore Backend unavailable: {ex}") | ||
|
||
try: | ||
backends['test'] = _get_backend('test') | ||
except ImportError as ex: | ||
logger.debug(f"Test Backend unavailable: {ex}") | ||
|
||
return backends | ||
|
||
|
||
def get_backend(backend_name: str) -> _Backend: | ||
try: | ||
backend = BACKENDS[backend_name] | ||
except KeyError: | ||
# try to load it | ||
try: | ||
BACKENDS[backend_name] = _get_backend(backend_name) | ||
backend = BACKENDS[backend_name] | ||
except ValueError: | ||
raise ValueError(f'Backend {backend_name} not supported. Available ' | ||
f'backends include: ({list(BACKENDS.keys())})') | ||
except ImportError as ex: | ||
raise ValueError(f'Backend {(backend_name)} failed to load: {ex}') | ||
|
||
return backend | ||
|
||
|
||
BACKENDS = _init_backends() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[backend] | ||
type = filestore | ||
path = ./db/filestore.json | ||
|
||
[control_layer] | ||
ca = true | ||
pva = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters