From 41008fd617ccaded13f2a394150dae81da7520ba Mon Sep 17 00:00:00 2001 From: Mahid Sheikh Date: Fri, 4 Oct 2024 21:36:43 -0500 Subject: [PATCH] fix: Make depends_on check occur before module loading Signed-off-by: Mahid Sheikh --- bpy_addon_build/api/__init__.py | 37 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/bpy_addon_build/api/__init__.py b/bpy_addon_build/api/__init__.py index d2da71a..a641345 100644 --- a/bpy_addon_build/api/__init__.py +++ b/bpy_addon_build/api/__init__.py @@ -60,6 +60,7 @@ class Api: """ def __init__(self, conf: Config, cli: Args, debug_mode: bool) -> None: + console = Console() if conf.build_actions is not None: self.build_actions = conf.build_actions self.action_mods: dict[str, ModuleType] = {} @@ -69,10 +70,26 @@ def __init__(self, conf: Config, cli: Args, debug_mode: bool) -> None: print(self.actions_to_execute) for action in self.build_actions: - if self.build_actions[action].script is None: - continue if action not in self.actions_to_execute: continue + + depends = self.build_actions[action].depends_on + if depends is not None: + if debug_mode: + print(action, "depends on", depends) + for dep in depends: + if ( + dep in self.actions_to_execute + and self.actions_to_execute.index(dep) + < self.actions_to_execute.index(action) + ): + continue + util.print_error(f"{dep} required to run {action}", console) + util.exit_fail() + + if self.build_actions[action].script is None: + continue + mod = self.add_modules(cli.path, action, debug_mode) if mod is None: continue @@ -81,25 +98,9 @@ def __init__(self, conf: Config, cli: Args, debug_mode: bool) -> None: def add_modules( self, config_path: Path, action: str, debug_mode: bool ) -> Optional[ModuleType]: - console = Console() script = self.build_actions[action].script - depends = self.build_actions[action].depends_on if script is None: return None - if depends is not None: - if debug_mode: - print(action, "depends on", depends) - for dep in depends: - if dep in self.actions_to_execute: - continue - - # Dependencies must execute before their dependents - if self.actions_to_execute.index(dep) < self.actions_to_execute.index( - action - ): - continue - util.print_error(f"{dep} required to run {action}", console) - util.exit_fail() path = config_path.parent.resolve().joinpath(Path(script))