Skip to content

Commit

Permalink
fix: Make depends_on check occur before module loading
Browse files Browse the repository at this point in the history
Signed-off-by: Mahid Sheikh <mahid@standingpad.org>
  • Loading branch information
StandingPadAnimations committed Oct 5, 2024
1 parent fac687f commit 41008fd
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions bpy_addon_build/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand All @@ -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
Expand All @@ -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))

Expand Down

0 comments on commit 41008fd

Please sign in to comment.