-
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.
Merge pull request #9 from spapa013/main
reorganize api.config, add api.schemas, change how base imports api
- Loading branch information
Showing
19 changed files
with
119 additions
and
164 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
120 changes: 31 additions & 89 deletions
120
python/microns-morphology-api/microns_morphology_api/config/__init__.py
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,95 +1,37 @@ | ||
""" | ||
Configuration package/module for microns-morphology. | ||
""" | ||
|
||
import inspect | ||
import traceback | ||
from enum import Enum | ||
import datajoint.datajoint_plus as djp | ||
from microns_utils.config_utils import SchemaConfig | ||
from . import adapters | ||
from . import externals | ||
from . import bases | ||
try: | ||
import datajoint as dj | ||
except: | ||
traceback.print_exc() | ||
raise ImportError('DataJoint package not found.') | ||
from microns_utils import config_utils | ||
|
||
|
||
config_utils.enable_datajoint_flags() | ||
|
||
|
||
def register_externals(schema_name:str): | ||
""" | ||
Registers the external stores for a schema_name in this module. | ||
""" | ||
external_stores = config_mapping[SCHEMAS(schema_name)]["externals"] | ||
|
||
if external_stores is not None: | ||
config_utils.register_externals(external_stores) | ||
|
||
|
||
def register_adapters(schema_name:str, context=None): | ||
""" | ||
Imports the adapters for a schema_name into the global namespace. | ||
""" | ||
adapter_objects = config_mapping[SCHEMAS(schema_name)]["adapters"] | ||
|
||
if adapter_objects is not None: | ||
config_utils.register_adapters(adapter_objects, context=context) | ||
|
||
|
||
def register_bases(schema_name:str, module): | ||
""" | ||
Maps base classes to DataJoint tables. | ||
""" | ||
bases = config_mapping[SCHEMAS(schema_name)]["bases"] | ||
|
||
if bases is not None: | ||
for base in bases: | ||
config_utils.register_bases(base, module) | ||
return module | ||
|
||
|
||
def create_vm(schema_name:str): | ||
""" | ||
Creates a virtual module after registering the external stores, adapter objects, DatajointPlus and base classes. | ||
""" | ||
schema = SCHEMAS(schema_name) | ||
vm = config_utils._create_vm(schema.value, external_stores=config_mapping[schema]["externals"], adapter_objects=config_mapping[schema]["adapters"]) | ||
config_utils.add_datajoint_plus(vm) | ||
register_bases(schema_name, vm) | ||
return vm | ||
|
||
|
||
class SCHEMAS(Enum): | ||
H01_MORPHOLOGY = "microns_h01_morphology" | ||
MINNIE65_AUTO_PROOFREADING = "microns_minnie65_auto_proofreading" | ||
H01_AUTO_PROOFREADING = "microns_h01_auto_proofreading" | ||
MINNIE65_MORPHOLOGY = "microns_minnie65_morphology" | ||
|
||
|
||
config_mapping = { | ||
SCHEMAS.H01_MORPHOLOGY: { | ||
"externals": externals.h01_morphology, | ||
"adapters": adapters.h01_morphology_adapter_objects, | ||
"bases": None | ||
}, | ||
SCHEMAS.H01_AUTO_PROOFREADING: { | ||
"externals": externals.h01_auto_proofreading, | ||
"adapters": adapters.h01_auto_proofreading_adapter_objects, | ||
"bases": None | ||
}, | ||
SCHEMAS.MINNIE65_AUTO_PROOFREADING: { | ||
"externals": externals.minnie65_auto_proofreading, | ||
"adapters": adapters.minnie65_auto_proofreading_adapter_objects, | ||
"bases": None | ||
}, | ||
SCHEMAS.MINNIE65_MORPHOLOGY: { | ||
"externals": externals.minnie65_morphology, | ||
"adapters": adapters.minnie65_morphology_adapter_objects, | ||
"bases": None | ||
|
||
}, | ||
|
||
} | ||
djp.enable_datajoint_flags() | ||
|
||
h01_morphology_config = SchemaConfig( | ||
module_name='h01_morphology', | ||
schema_name='microns_h01_morphology', | ||
externals=externals.h01_morphology, | ||
adapters=adapters.h01_morphology | ||
) | ||
|
||
minnie65_auto_proofreading_config = SchemaConfig( | ||
module_name='minnie65_auto_proofreading', | ||
schema_name='microns_minnie65_auto_proofreading', | ||
externals=externals.minnie65_auto_proofreading, | ||
adapters=adapters.minnie65_auto_proofreading | ||
) | ||
|
||
h01_auto_proofreading_config = SchemaConfig( | ||
module_name='h01_auto_proofreading', | ||
schema_name='microns_h01_auto_proofreading', | ||
externals=externals.h01_auto_proofreading, | ||
adapters=adapters.h01_auto_proofreading | ||
) | ||
|
||
minnie65_morphology_config = SchemaConfig( | ||
module_name='minnie65_morphology', | ||
schema_name='microns_minnie65_morphology', | ||
externals=externals.minnie65_morphology, | ||
adapters=adapters.minnie65_morphology | ||
) |
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
3 changes: 0 additions & 3 deletions
3
python/microns-morphology-api/microns_morphology_api/config/bases.py
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
Empty file.
13 changes: 13 additions & 0 deletions
13
python/microns-morphology-api/microns_morphology_api/schemas/h01_auto_proofreading.py
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 datajoint as dj | ||
from datajoint import datajoint_plus as djp | ||
|
||
from ..config import h01_auto_proofreading_config | ||
|
||
h01_auto_proofreading_config.register_adapters(context=locals()) | ||
h01_auto_proofreading_config.register_externals() | ||
|
||
schema = dj.schema(h01_auto_proofreading_config.schema_name) | ||
|
||
schema.spawn_missing_classes() | ||
schema.connection.dependencies.load() | ||
|
12 changes: 12 additions & 0 deletions
12
python/microns-morphology-api/microns_morphology_api/schemas/h01_morphology.py
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,12 @@ | ||
import datajoint as dj | ||
from datajoint import datajoint_plus as djp | ||
|
||
from ..config import h01_morphology_config | ||
|
||
h01_morphology_config.register_adapters(context=locals()) | ||
h01_morphology_config.register_externals() | ||
|
||
schema = dj.schema(h01_morphology_config.schema_name) | ||
|
||
schema.spawn_missing_classes() | ||
schema.connection.dependencies.load() |
12 changes: 12 additions & 0 deletions
12
python/microns-morphology-api/microns_morphology_api/schemas/minnie65_auto_proofreading.py
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,12 @@ | ||
import datajoint as dj | ||
from datajoint import datajoint_plus as djp | ||
|
||
from ..config import minnie65_auto_proofreading_config | ||
|
||
minnie65_auto_proofreading_config.register_adapters(context=locals()) | ||
minnie65_auto_proofreading_config.register_externals() | ||
|
||
schema = dj.schema(minnie65_auto_proofreading_config.schema_name) | ||
|
||
schema.spawn_missing_classes() | ||
schema.connection.dependencies.load() |
12 changes: 12 additions & 0 deletions
12
python/microns-morphology-api/microns_morphology_api/schemas/minnie65_morphology.py
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,12 @@ | ||
import datajoint as dj | ||
from datajoint import datajoint_plus as djp | ||
|
||
from ..config import minnie65_morphology_config | ||
|
||
minnie65_morphology_config.register_adapters(context=locals()) | ||
minnie65_morphology_config.register_externals() | ||
|
||
schema = dj.schema(minnie65_morphology_config.schema_name) | ||
|
||
schema.spawn_missing_classes() | ||
schema.connection.dependencies.load() |
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
6 changes: 3 additions & 3 deletions
6
python/microns-morphology/microns_morphology/auto_proofreading/__init__.py
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,5 @@ | ||
from microns_morphology_api import config | ||
import datajoint.datajoint_plus as djp | ||
from . import h01_auto_proofreading, minnie65_auto_proofreading | ||
|
||
config.register_bases(config.SCHEMAS.H01_AUTO_PROOFREADING, h01_auto_proofreading) | ||
config.register_bases(config.SCHEMAS.MINNIE65_AUTO_PROOFREADING, minnie65_auto_proofreading) | ||
djp.reassign_master_attribute(h01_auto_proofreading) | ||
djp.reassign_master_attribute(minnie65_auto_proofreading) |
9 changes: 1 addition & 8 deletions
9
python/microns-morphology/microns_morphology/auto_proofreading/h01_auto_proofreading.py
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,12 +1,5 @@ | ||
import datajoint as dj | ||
from datajoint import datajoint_plus as djp | ||
|
||
from microns_morphology_api import config | ||
schema_obj = config.SCHEMAS.H01_AUTO_PROOFREADING | ||
|
||
config.register_adapters(schema_obj, context=locals()) | ||
config.register_externals(schema_obj) | ||
|
||
schema = dj.schema(schema_obj.value) | ||
schema.spawn_missing_classes() | ||
from microns_morphology_api.schemas import h01_auto_proofreading | ||
|
10 changes: 1 addition & 9 deletions
10
python/microns-morphology/microns_morphology/auto_proofreading/minnie65_auto_proofreading.py
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,12 +1,4 @@ | ||
import datajoint as dj | ||
from datajoint import datajoint_plus as djp | ||
|
||
from microns_morphology_api import config | ||
schema_obj = config.SCHEMAS.MINNIE65_AUTO_PROOFREADING | ||
|
||
config.register_adapters(schema_obj, context=locals()) | ||
config.register_externals(schema_obj) | ||
|
||
schema = dj.schema(schema_obj.value) | ||
schema.spawn_missing_classes() | ||
|
||
from microns_morphology_api.schemas import minnie65_auto_proofreading |
4 changes: 2 additions & 2 deletions
4
python/microns-morphology/microns_morphology/h01_morphology/__init__.py
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,4 +1,4 @@ | ||
from microns_morphology_api import config | ||
import datajoint.datajoint_plus as djp | ||
from . import h01_morphology | ||
|
||
config.register_bases(config.SCHEMAS.H01_MORPHOLOGY, h01_morphology) | ||
djp.reassign_master_attribute(h01_morphology) |
9 changes: 1 addition & 8 deletions
9
python/microns-morphology/microns_morphology/h01_morphology/h01_morphology.py
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,11 +1,4 @@ | ||
import datajoint as dj | ||
from datajoint import datajoint_plus as djp | ||
|
||
from microns_morphology_api import config | ||
schema_obj = config.SCHEMAS.H01_MORPHOLOGY | ||
|
||
config.register_adapters(schema_obj, context=locals()) | ||
config.register_externals(schema_obj) | ||
|
||
schema = dj.schema(schema_obj.value) | ||
schema.spawn_missing_classes() | ||
from microns_morphology_api.schemas import h01_morphology |
4 changes: 2 additions & 2 deletions
4
python/microns-morphology/microns_morphology/minnie_morphology/__init__.py
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,4 +1,4 @@ | ||
from microns_morphology_api import config | ||
import datajoint.datajoint_plus as djp | ||
from . import minnie65_morphology | ||
|
||
config.register_bases(config.SCHEMAS.MINNIE65_MORPHOLOGY, minnie65_morphology) | ||
djp.reassign_master_attribute(minnie65_morphology) |
9 changes: 1 addition & 8 deletions
9
python/microns-morphology/microns_morphology/minnie_morphology/minnie65_morphology.py
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,11 +1,4 @@ | ||
import datajoint as dj | ||
from datajoint import datajoint_plus as djp | ||
|
||
from microns_morphology_api import config | ||
schema_obj = config.SCHEMAS.MINNIE65_MORPHOLOGY | ||
|
||
config.register_adapters(schema_obj, context=locals()) | ||
config.register_externals(schema_obj) | ||
|
||
schema = dj.schema(schema_obj.value) | ||
schema.spawn_missing_classes() | ||
from microns_morphology_api.schemas import minnie65_morphology |
Oops, something went wrong.