Skip to content

Commit

Permalink
feat: add hook_dirs field so that tests can import hooks from another…
Browse files Browse the repository at this point in the history
… directory
  • Loading branch information
robcxyz committed Nov 8, 2022
1 parent 047f542 commit c0b16b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tackle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from jinja2.ext import Extension
from typing import Any, Union, Optional, Callable

from tackle.hooks import import_native_providers
from tackle.hooks import import_native_providers, import_hooks_from_dir
from tackle.utils.render import wrap_jinja_braces
from tackle.exceptions import TooManyTemplateArgsException

Expand Down Expand Up @@ -46,7 +46,8 @@ class BaseContext(BaseModel):
key_path: list = []
key_path_block: list = []

public_hooks: dict = {}
# public_hooks: dict = {}
public_hooks: dict = None
private_hooks: dict = None
default_hook: Any = Field(None, exclude=True)

Expand Down Expand Up @@ -87,6 +88,10 @@ class Context(BaseContext):

context_functions: list = None

hook_dirs: list = Field(
None, description="A list of additional directories to import hooks."
)

latest: bool = False
# TODO: Change to version?
checkout: str = Field(
Expand All @@ -108,6 +113,13 @@ def __init__(self, **data: Any):
self.private_hooks = {}
import_native_providers(self)

if self.public_hooks is None:
self.public_hooks = {}

if self.hook_dirs is not None:
for i in self.hook_dirs:
import_hooks_from_dir(context=self, mod_name=i, path=i)

if self.env_ is None:
self.env_ = StrictEnvironment()

Expand Down
1 change: 1 addition & 0 deletions tests/models/hook-dirs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
t->: thing --stuff things
6 changes: 6 additions & 0 deletions tests/models/test_models_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,9 @@ def test_providers_unreleased_import(chdir_fixture, remove_provider):
remove_provider("robcxyz/tackle-fixture-unreleased")
o = tackle("robcxyz/tackle-fixture-unreleased", no_input=True)
assert o['this'] == 'that'


def test_providers_hook_dirs(change_dir):
"""Check that we can import hooks by supplying a directory."""
o = tackle("hook-dirs.yaml", hook_dirs=[str(os.path.join('fixtures', '.hooks'))])
assert o['t'] == 'things'

0 comments on commit c0b16b2

Please sign in to comment.