Skip to content

Commit

Permalink
Merge pull request #5 from spapa013/main
Browse files Browse the repository at this point in the history
Bug fixes, feature additions
  • Loading branch information
spapa013 authored May 16, 2022
2 parents aa8ec1a + 27fd703 commit 7a91f7d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 449 deletions.
4 changes: 2 additions & 2 deletions datajoint_plus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'list_schemas', 'config',
'DataJointPlusModule', 'create_djp_module',
'reassign_master_attribute', 'add_datajoint_plus',
'Lookup', 'Computed', 'Part',
'Lookup', 'Computed', 'Part', 'Manual',
'add_objects', 'check_if_latest_version', 'enable_datajoint_flags',
'format_table_name', 'split_full_table_name', 'make_store_dict', 'register_externals',
'generate_hash', 'validate_and_generate_hash', 'parse_definition',
Expand Down Expand Up @@ -41,7 +41,7 @@
from .logging import LogFileManager, basicConfig, getLogger
from .schema import DataJointPlusModule, Schema
from .table import FreeTable as free_table
from .user_tables import Computed, Lookup, Part
from .user_tables import Computed, Lookup, Part, Manual
from .utils import (add_objects, check_if_latest_version,
enable_datajoint_flags, format_table_name, make_store_dict,
register_externals, split_full_table_name)
Expand Down
4 changes: 2 additions & 2 deletions datajoint_plus/motif.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from collections import namedtuple
import inspect
import logging
from .logging import getLogger
import re
import datajoint as dj
import numpy as np
Expand All @@ -16,7 +16,7 @@
from .base import BaseMaster, BasePart
from .utils import classproperty, safedict, unwrap, wrap

logger = logging.getLogger(__name__)
logger = getLogger(__name__)



Expand Down
106 changes: 54 additions & 52 deletions datajoint_plus/motif_base.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
"""
Motif tables for DataJointPlus
Base motif classes
"""
from .logging import getLogger
import inspect
from .base import Base
from datajoint.expression import Projection
from .utils import classproperty

from datajoint_plus.user_tables import UserTable
from datajoint_plus.utils import classproperty
import datajoint as dj
logger = getLogger(__name__)


class Motif(UserTable):
@classmethod
def is_motif_table(cls):
return issubclass(Motif)

class StrToTable:
"""
Abstract class -1
"""
def __init__(self, **kwargs):
if isinstance(self.table, Base):
self.base_table = self.table.__class__()

elif isinstance(self.table, Projection):
self.base_table = self.table._arg.__class__()

else:
msg = f'Unable to instantiate table of type {self.table.__class__.__qualname__}.'
logger.error(msg)
raise NotImplementedError(msg)

@property
def table(self):
try:
table = eval(self._table, self.declaration_context)
if inspect.isclass(table):
return table()
else:
return table
except:
msg = f'Unable to instantiate {self.__class__.__qualname__}.'
logger.exception(msg)
raise NotImplementedError(msg)

def __repr__(self):
return f'{self.__class__.__qualname__}({self._table})'

def __call__(self):
return self.table

class MotifMaster(Motif):
@classproperty
def definition(cls):
return f"""
#{cls().class_name}
{cls.hash_name} : varchar({cls.hash_len}) # hash
"""

class Motif:
"""
Class level: -2
"""

class Nested(Motif):
@classmethod
def is_nested(cls):
return issubclass(cls, Nested)
def _init_validation(cls, **kwargs):
if (cls.hash_name is None) and (cls.lookup_name is None):
raise NotImplementedError('Subclasses of Motif must implement "lookup_name" or "hash_name".')

def delete_from_master(self):
# with dj.conn().transaction:
keys = self.fetch('KEY')
(self.master & keys).delete()

def delete_quick_from_master(self):
# with dj.conn().transaction:
keys = self.fetch('KEY')
self.delete_quick()
(self.master & keys).delete_quick()

def delete_quick(self, delete_from_master=True):
if delete_from_master:
self.delete_quick_from_master()
else:
super().delete_quick()

def delete(self, delete_from_master=True):
if delete_from_master:
self.delete_from_master()
else:
super().delete()

def drop(self, force=False):
if force:
super(UserTable, self).drop()
else:
raise dj.DataJointError('Cannot drop a Part directly. Delete from master instead')
@classproperty
def lookup_name(cls):
return cls.hash_name if cls.hash_name is not None else logger.error('"lookup_name" not defined.')

def drop_quick(self, force=False):
if force:
return super(UserTable, self).drop_quick()
else:
raise dj.DataJointError('Cannot drop a Part directly. Delete from master instead')
@classmethod
def lookup_as(cls, table):
return cls.proj(..., **{table.lookup_name: cls.lookup_name})



Loading

0 comments on commit 7a91f7d

Please sign in to comment.