Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3793e0
commit 5c62af6
Showing
8 changed files
with
88 additions
and
37 deletions.
There are no files selected for viewing
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,8 @@ | ||
include LICENSE | ||
include README.md | ||
|
||
recursive-exclude * __pycache__ | ||
recursive-exclude * *.py[co] | ||
|
||
recursive-include funnel *.py | ||
recursive-include funnel *.yaml |
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,47 @@ | ||
import pathlib | ||
import typing | ||
|
||
import dask | ||
import pkg_resources | ||
import pydantic | ||
import yaml | ||
|
||
from .metadata_db.main import MemoryMetadataStore, SQLMetadataStore | ||
from .registry import registry | ||
|
||
default_config_dir = pathlib.Path('~').expanduser() / '.config' / 'funnel' | ||
default_config_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
config_file_path = pathlib.Path(pkg_resources.resource_filename('funnel', 'funnel.yaml')) | ||
default_config_path = default_config_dir / 'funnel.yaml' | ||
|
||
if not default_config_path.exists(): | ||
default_config_path.write_text(config_file_path.read_text()) | ||
|
||
|
||
class Config(pydantic.BaseSettings): | ||
""" | ||
Configuration settings for the Funnel. | ||
""" | ||
|
||
metadata_store: typing.Union[SQLMetadataStore, MemoryMetadataStore] = None | ||
|
||
class Config: | ||
validate_assignment = True | ||
|
||
def load_config(self, config_path: str): | ||
""" | ||
Loads the config from a file. | ||
""" | ||
with open(config_path) as f: | ||
config = dask.config.expand_environment_variables(yaml.safe_load(f)) | ||
metadata_store_type = config['metadata_store']['type'] | ||
del config['metadata_store']['type'] | ||
self.metadata_store = registry.metadata_store.get(metadata_store_type)( | ||
cache_store_options=config['cache_store'], | ||
metadata_store_options=config['metadata_store'], | ||
) | ||
|
||
|
||
config = Config() | ||
config.load_config(default_config_path) |
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,10 @@ | ||
cache_store: | ||
path: $TMPDIR/funnel/cache/ | ||
readonly: false | ||
on_duplicate_key: skip | ||
storage_options: | ||
|
||
metadata_store: | ||
type: sql # memory or sql | ||
readonly: false | ||
database_url: sqlite:///$HOME/.config/funnel/funnel.db |
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,13 @@ | ||
import pydantic | ||
import pytest | ||
|
||
import funnel | ||
|
||
|
||
def test_validate_error(): | ||
with pytest.raises(pydantic.ValidationError): | ||
funnel.config.metadata_store = 5 | ||
|
||
|
||
def test_default_config(): | ||
assert isinstance(funnel.config, pydantic.BaseSettings) |