Skip to content

Commit

Permalink
enabled autoload of module parents
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hartmann committed Dec 29, 2020
1 parent 1336938 commit 966c263
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/miniflask/miniflask.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,16 @@ def load(self, module_name, verbose=True, auto_query=True, loading_text=highligh
mod.miniflask_obj = miniflask_wrapper(module_name, self)
mod.miniflask_obj.bind_events = bind_events

# first load all parents
# (starting with root parent, specializing with every step)
if not hasattr(mod, 'register_parents') or mod.register_parents:
module_path = module_name.split(".")
for depth in range(1, len(module_path)):
parent_module = ".".join(module_path[:depth])
if parent_module in self.modules_avail and parent_module not in self.modules_loaded:
parent_as_id = None if as_id is None else ".".join(as_id.split(".")[:-1])
self.load(parent_module, verbose=False, auto_query=False, loading_text=loading_text, as_id=parent_as_id, bind_events=bind_events)

# remember loaded modules
self.modules_loaded[module_name] = mod
self._recently_loaded.append(mod)
Expand Down Expand Up @@ -879,7 +889,9 @@ def load(self, module_name, as_id=None, auto_query=True, **kwargs):
auto_query = not was_relative

# call load (but ensure no querying is made if relative imports were given)
super().load(module_name, auto_query=auto_query, verbose=False, as_id=as_id, **kwargs)
if "verbose" in kwargs:
del kwargs["verbose"]
super().load(module_name, verbose=False, auto_query=auto_query, as_id=as_id, **kwargs)

# overwrite state defaults
def register_event(self, name, fn, **kwargs):
Expand Down

0 comments on commit 966c263

Please sign in to comment.