Skip to content

Commit 1cd1558

Browse files
add context argument to schema.spawn_missing_classes
1 parent f3e40e1 commit 1cd1558

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

datajoint/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def create_virtual_module(modulename, dbname):
8181
:return: the python module
8282
"""
8383
mod = ModuleType(modulename)
84-
s = schema(dbname, mod.__dict__, create_tables=False)
85-
s.spawn_missing_classes()
84+
s = schema(dbname, create_tables=False)
85+
s.spawn_missing_classes(context=mod.__dict__)
8686
mod.__dict__['schema'] = s
8787
return mod

datajoint/schema.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,20 @@ def repl(s):
140140
for k, v in module_lookup.items()),
141141
body))
142142

143-
def spawn_missing_classes(self):
143+
def spawn_missing_classes(self, context=None):
144144
"""
145145
Creates the appropriate python user relation classes from tables in the database and places them
146146
in the context.
147+
:param context: alternative context to place the missing classes into, e.g. locals()
147148
"""
148-
# if self.context is not set, use the calling namespace
149-
if self.context is not None:
150-
context = self.context
151-
else:
152-
frame = inspect.currentframe().f_back
153-
context = frame.f_locals
154-
del frame
149+
if context is None:
150+
if self.context is not None:
151+
context = self.context
152+
else:
153+
# if context is missing, use the calling namespace
154+
frame = inspect.currentframe().f_back
155+
context = frame.f_locals
156+
del frame
155157
tables = [
156158
row[0] for row in self.connection.query('SHOW TABLES in `%s`' % self.database)
157159
if lookup_class_name('`{db}`.`{tab}`'.format(db=self.database, tab=row[0]), context, 0) is None]

0 commit comments

Comments
 (0)