Skip to content

Commit

Permalink
chore: update local hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Jan 8, 2024
1 parent 9e866ed commit f4b5cc1
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 117 deletions.
198 changes: 94 additions & 104 deletions hooks/docs-gen.yaml
Original file line number Diff line number Diff line change
@@ -1,105 +1,95 @@
# Note: If changing the name of this hook, also update the `import` hook's test since they ref this
gen_docs<-:
exec:
problem_hooks:
# Has "\n" as a default value which messes up table
print: Console

provider_dir->: "{{ cwd }}/providers"
provider_docs_dir->: "{{ cwd }}/docs/providers"
schemas_dir->: "{{ cwd }}/docs/schemas"
templates_dir->: "{{ cwd }}/hooks/templates"

# Directories / files to ignore inside the `tackle/providers` directory
provider_ignore:
- __init__.py
- __pycache__
- .gitignore
- README.md
# WIP
- postgres
- time
- kubernetes

# mkdocs.yml navigation sidebar options - Empty list that will be appended to
mkdocs_nav_list: []
remove old provider docs dir->: remove "{{ item }}" --for ['provider_docs_dir','schemas_dir'] --try

gen->:
# Iterate through the providers via list comprehesion
for: sort(listdir(provider_dir) | reject('in', provider_ignore) | list)
chdir: "{{ provider_dir }}/{{ item }}"
print->: print "Generating {{item}} provider"

# Embedded for loops need to have the iterand `item` referenced if being used in inner loops
provider->: "{{ item }}"

# Get the provider metadata and schemas
render_context->: provider_docs
schemas->: provider_docs --output_schemas

Put schemas in schema directory_>: json {{schemas_dir}}/{{provider}}.json {{schemas}}

# Read the provider metadata
provider_meta:
->: tackle .tackle.meta.yaml
if: isfile('.tackle.meta.yaml')
else:
examples: []

# Build the provider navigation for mkdocs
provider_mkdocs_nav_list:
- Index->: providers/{{ provider | title }}/index.md
append multiple hooks providers:
->: append provider_mkdocs_nav_list
for: render_context.hooks
if: render_context.hooks|length != 1
item:
"{{item.hook_name}}": providers/{{ provider | title }}/{{ item.hook_name }}.md
append to mkdocs_nav_list:
->: append mkdocs_nav_list
item:
"{{provider|title}}": "{{provider_mkdocs_nav_list}}"

# d->: debug render_context
source_code_link_stub->: https://github.com/robcxyz/tackle/blob/main/tackle/providers/{{provider}}/hooks
Generate single hook provider as a single page:
if: render_context['hooks'] | length == 1
->: generate {{templates_dir}}/hook-doc.md.tpl {{provider_docs_dir}}/{{provider|title }}/index.md
extra_context:
- "{{ provider_meta }}"
- "{{ render_context.hooks[0] }}"

# d->: debug render_context

# Generate multiple->:
# if: render_context['hooks'] | length != 1
# Render hook templates from the tackle provider:
# ->: generate {{templates_dir}}/hook-doc.md.tpl {{provider_docs_dir}}/{{provider|title }}/{{ item.hook_name }}.md
# for: render_context['hooks']
# if: item.hook_name not in problem_hooks
# extra_context:
# - "{{ provider_meta }}"
# - "{{ item }}"
# d->: debug render_context

Generate multiple:
when: render_context['hooks'] | length != 1
_>: generate {{templates_dir}}/hook-doc.md.tpl {{provider_docs_dir}}/{{provider|title }}/{{ item.hook_name }}.md
for: render_context['hooks']
if: item.hook_name not in problem_hooks
extra_context:
- "{{ provider_meta }}"
- "{{ item }}"

Render provider template:
->: generate {{templates_dir}}/provider-doc.md.tpl {{provider_docs_dir}}/{{provider|title }}/index.md
extra_context:
- "{{ render_context }}"
- "{{ provider_meta }}"

copy problem hooks:
_>: copy {{templates_dir}}/problem-hooks/{{item}}.md {{provider_docs_dir}}/{{problem_hooks[item]}}/{{item}}.md
for: keys(problem_hooks)

Regenerate mkdocs->: tackle mkdocs.tackle.yml # Already at base
docs_gen()<-:
problem_hooks:
# Has "\n" as a default value which messes up table
print: Console

provider_dir->: "{{ cwd }}/providers"
provider_docs_dir->: "{{ cwd }}/docs/providers"
schemas_dir->: "{{ cwd }}/docs/schemas"
templates_dir->: "{{ cwd }}/hooks/templates"

# Directories / files to ignore inside the `tackle/providers` directory
provider_ignore:
- __init__.py
- __pycache__
- .gitignore
- README.md
- .native

# mkdocs.yml navigation sidebar options - Empty list that will be appended to
mkdocs_nav_list: []
remove old provider docs dir->: remove "{{ item }}" --for ['provider_docs_dir','schemas_dir'] --try

gen->:
# Iterate through the providers via list comprehesion
for: provider in sort(listdir(provider_dir) | reject('in', provider_ignore) | list)
chdir: "{{ provider_dir }}/{{ provider }}"
print->: "Generating {{provider}} provider"

# Get the provider metadata and schemas
render_context->: provider_docs
schemas->: provider_docs --output_schemas

Put schemas in schema directory_>: json {{schemas_dir}}/{{provider}}.json {{schemas}}

# Read the provider metadata
provider_meta:
->: tackle .tackle.meta.yaml
if: isfile('.tackle.meta.yaml')
else:
examples: []

# Build the provider navigation for mkdocs
provider_mkdocs_nav_list:
- Index->: providers/{{ provider | title }}/index.md
append multiple hooks providers:
->: append provider_mkdocs_nav_list
for: hook in render_context.hooks
if: render_context.hooks|length != 1
item:
"{{hook.hook_name}}": providers/{{ provider | title }}/{{ hook.hook_name }}.md
append to mkdocs_nav_list:
->: append mkdocs_nav_list
item:
"{{provider|title}}": "{{provider_mkdocs_nav_list}}"

source_code_link_stub->: https://github.com/robcxyz/tackle/blob/main/providers/{{provider}}/hooks
Generate single hook provider as a single page:
if: render_context['hooks'] | length == 1
->: generate {{templates_dir}}/hook-doc.md.tpl {{provider_docs_dir}}/{{provider|title }}/index.md
extra_context:
- "{{ provider_meta }}"
- "{{ render_context.hooks[0] }}"

# Generate multiple->:
# if: render_context['hooks'] | length != 1
# Render hook templates from the tackle provider:
# ->: generate {{templates_dir}}/hook-doc.md.tpl {{provider_docs_dir}}/{{provider|title }}/{{ item.hook_name }}.md
# for: render_context['hooks']
# if: item.hook_name not in problem_hooks
# extra_context:
# - "{{ provider_meta }}"
# - "{{ item }}"
# d->: debug render_context

Generate multiple:
when: render_context['hooks'] | length != 1
for: hook in render_context['hooks']
_>: generate {{templates_dir}}/hook-doc.md.tpl {{provider_docs_dir}}/{{provider|title }}/{{ hook.hook_name }}.md
if: hook.hook_name not in problem_hooks
extra_context:
- "{{ provider_meta }}"
- "{{ hook }}"

Render provider template:
->: generate {{templates_dir}}/provider-doc.md.tpl {{provider_docs_dir}}/{{provider|title }}/index.md
extra_context:
- "{{ render_context }}"
- "{{ provider_meta }}"

copy problem hooks:
_>: copy {{templates_dir}}/problem-hooks/{{hook}}.md {{provider_docs_dir}}/{{problem_hooks[hook]}}/{{hook}}.md
for: hook in keys(problem_hooks)

Regenerate mkdocs->: tackle mkdocs.tackle.yml # Already at base
11 changes: 8 additions & 3 deletions hooks/model_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

from pydantic import BaseModel

from tackle import BaseHook, Context
from tackle import BaseHook, HookCallInput
from tackle.pydantic.config import DclHookModelConfig
from tackle.pydantic.field_types import FieldInput

MODELS = [
BaseHook,
Context,
HookCallInput,
FieldInput,
DclHookModelConfig,
]


Expand Down Expand Up @@ -40,6 +44,7 @@ def extract_model_data(self, model: Type[BaseModel]) -> dict[str, ModelOutput]:

def exec(self) -> dict:
output = {}
output[BaseHook.__name__] = self.extract_model_data(BaseHook)
for M in MODELS:
output[M.__name__] = self.extract_model_data(M)

return output
13 changes: 5 additions & 8 deletions hooks/tests/test_model_data.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from tackle import get_hook, tackle


def test_model_data_get(base_hooks_dir):
output = tackle(raw_input={'data->': 'model_data'})

assert 'BaseHook' in output['data']
from tackle import get_hook


def test_model_data_hook():
Hook = get_hook('model_data')
output = Hook().exec()

assert output
assert 'BaseHook' in output
assert 'HookCallInput' in output
assert 'FieldInput' in output
assert 'DclHookModelConfig' in output
4 changes: 2 additions & 2 deletions hooks/tests/test_provider_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_provider_paths(provider_name: str = None):

@pytest.mark.parametrize("provider_path", get_provider_paths())
def test_provider_docs_hook(provider_path):
"""Check that we can run the collections provider."""
"""Check that we can gather metadata from each native provider."""
Hook = get_hook('provider_docs')
output = Hook(path=provider_path).exec(context=Context())

Expand All @@ -29,7 +29,7 @@ def test_provider_docs_hook(provider_path):

def test_local_hooks_generate_provider_docs():
"""Generate the provider docs."""
output = tackle('gen_docs')
output = tackle('docs_gen')
paths = [
'provider_dir',
'provider_docs_dir',
Expand Down

0 comments on commit f4b5cc1

Please sign in to comment.