-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This extends the view API to allow for the registration of multiple views using custom names. It also introduces an option to overwrite the default storage model used by the storage abstraction. Together this allows to fully customize and extend the storage interface.
- Loading branch information
Showing
11 changed files
with
189 additions
and
104 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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from .storage import Storage | ||
from .view import View | ||
|
||
|
||
def get_component(url): | ||
|
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 |
---|---|---|
@@ -1 +1 @@ | ||
from .model import StorageComponentModel, StorageExperimentModel, StorageModel | ||
from .models import StorageComponentModel, StorageExperimentModel, StorageModel |
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 was deleted.
Oops, something went wrong.
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 @@ | ||
from .views import StorageExperimentView, StorageComponentView, StorageView |
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,72 @@ | ||
import inspect | ||
|
||
from ...core.mixin import Mixin, MixinInstance | ||
from ...utils.importing import ModuleClass | ||
|
||
_register = { | ||
"experiment": {}, | ||
"component": {}, | ||
} | ||
|
||
|
||
def get(view_type, instance, name=None): | ||
try: | ||
return MixinInstance(instance, _register[view_type][name], attribute=name) | ||
except KeyError: | ||
return None | ||
|
||
|
||
class StorageView: | ||
@classmethod | ||
def clear(cls, types=None): | ||
if types is None: | ||
types = ["experiment", "component"] | ||
if isinstance(types, str): | ||
types = [types] | ||
for k in types: | ||
_register[k] = {} | ||
|
||
@classmethod | ||
def component(cls, view=None, *, name=None): | ||
if name is not None: | ||
name = "_" + name + "_" | ||
|
||
def _decorate(f): | ||
if isinstance(f, str): | ||
f = ModuleClass(f, baseclass=StorageComponentView) | ||
else: | ||
if not inspect.isclass(f): | ||
raise ValueError(f"View has to be a class") | ||
_register["component"][name] = f | ||
|
||
if view: | ||
return _decorate(view) | ||
|
||
return _decorate | ||
|
||
@classmethod | ||
def experiment(cls, view=None, *, name=None): | ||
if name is not None: | ||
name = "_" + name + "_" | ||
|
||
def _decorate(f): | ||
if isinstance(f, str): | ||
f = ModuleClass(f, baseclass=StorageExperimentView) | ||
else: | ||
if not inspect.isclass(f): | ||
raise ValueError(f"View has to be a class") | ||
|
||
_register["experiment"][name] = f | ||
|
||
if view: | ||
return _decorate(view) | ||
|
||
return _decorate | ||
|
||
|
||
class StorageExperimentView(Mixin): | ||
pass | ||
|
||
|
||
class StorageComponentView(Mixin): | ||
pass |
Oops, something went wrong.