Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No config exception handling #17

Open
wants to merge 2 commits into
base: top-level_refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dacapo/store/config_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class ConfigStore(ABC):
"""Base class for configuration stores.
"""

@abstractmethod
def no_such_config_exception_handler(func):
"""Error handling when config name not found"""
pass

@abstractmethod
def store_run_config(self, run_config):
"""Store a run config. This should also store the configs that are part
Expand Down
19 changes: 19 additions & 0 deletions dacapo/store/mongo_config_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,26 @@ def __init__(self, db_host, db_name):
self.__open_collections()
self.__init_db()

def no_such_config_exception_handler(func):

def inner_function(*args, **kwargs):

try:
return func(*args, **kwargs)
except TypeError:
config_type = func.__name__.split("_")[1]
raise Exception(
f"{config_type}: {args[1]} not present in config store "
f"during call to {func.__name__}")

return inner_function

def store_run_config(self, run_config):

run_doc = converter.unstructure(run_config)
self.__save_insert(self.runs, run_doc)

@no_such_config_exception_handler
def retrieve_run_config(self, run_name):

run_doc = self.runs.find_one(
Expand All @@ -55,6 +70,7 @@ def store_task_config(self, task_config):
task_doc = converter.unstructure(task_config)
self.__save_insert(self.tasks, task_doc)

@no_such_config_exception_handler
def retrieve_task_config(self, task_name):

task_doc = self.tasks.find_one(
Expand All @@ -74,6 +90,7 @@ def store_architecture_config(self, architecture_config):
architecture_doc = converter.unstructure(architecture_config)
self.__save_insert(self.architectures, architecture_doc)

@no_such_config_exception_handler
def retrieve_architecture_config(self, architecture_name):

architecture_doc = self.architectures.find_one(
Expand All @@ -93,6 +110,7 @@ def store_trainer_config(self, trainer_config):
trainer_doc = converter.unstructure(trainer_config)
self.__save_insert(self.trainers, trainer_doc)

@no_such_config_exception_handler
def retrieve_trainer_config(self, trainer_name):

trainer_doc = self.trainers.find_one(
Expand All @@ -112,6 +130,7 @@ def store_dataset_config(self, dataset_config):
dataset_doc = converter.unstructure(dataset_config)
self.__save_insert(self.datasets, dataset_doc)

@no_such_config_exception_handler
def retrieve_dataset_config(self, dataset_name):

dataset_doc = self.datasets.find_one(
Expand Down