Skip to content

Commit

Permalink
Move built in hooks to builer constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Dec 16, 2023
1 parent 2847749 commit 63c7f8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
13 changes: 0 additions & 13 deletions toltec/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import sys
from importlib.util import find_spec, spec_from_file_location, module_from_spec
from typing import Dict, List, Optional
import toltec.hooks
from toltec import parse_recipe
from toltec.builder import Builder
from toltec.recipe import Package
Expand Down Expand Up @@ -82,18 +81,6 @@ def main() -> int: # pylint:disable=too-many-branches
recipe_bundle = parse_recipe(args.recipe_dir)

with Builder(args.work_dir, args.dist_dir) as builder:
# Load built in hooks
for hook in toltec.hooks.__all__:
spec = find_spec(f"toltec.hooks.{hook}")
if spec:
module = module_from_spec(spec)
spec.loader.exec_module(module) # type: ignore
module.register(builder) # type: ignore
else:
raise RuntimeError(
f"Hook module 'toltec.hooks.{hook}' couldn’t be loaded"
)

if args.hook:
for ident in args.hook:
if ident and ident[0] in (".", "/"):
Expand Down
16 changes: 15 additions & 1 deletion toltec/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import os
import logging
import textwrap
from importlib.util import find_spec, module_from_spec
import docker
import requests
from . import hooks
from . import bash, util, ipk
from .recipe import RecipeBundle, Recipe, Package
from .version import DependencyKind
Expand Down Expand Up @@ -50,6 +52,17 @@ def __init__(self, work_dir: str, dist_dir: str) -> None:
permissions."
) from err

for hook in hooks.__all__:
spec = find_spec(f"toltec.hooks.{hook}")
if spec:
module = module_from_spec(spec)
spec.loader.exec_module(module) # type: ignore
module.register(self) # type: ignore
else:
raise RuntimeError(
f"Hook module 'toltec.hooks.{hook}' couldn’t be loaded"
)

def __enter__(self) -> "Builder":
return self

Expand Down Expand Up @@ -123,6 +136,7 @@ def make(
self,
recipe_bundle: RecipeBundle,
build_matrix: Optional[Mapping[str, Optional[List[Package]]]] = None,
check_directory: bool = True,
) -> bool:
"""
Build packages defined by a recipe.
Expand All @@ -132,7 +146,7 @@ def make(
(default: all supported packages for each architecture)
:returns: true if all the requested packages were built correctly
"""
if not util.check_directory(
if check_directory and not util.check_directory(
self.work_dir,
f"The build directory '{self.work_dir}' \
already exists.\nWould you like to [c]ancel, [r]emove that directory, \
Expand Down

0 comments on commit 63c7f8f

Please sign in to comment.