sudoblockio / tackle

Tackle is a programmable configuration language for building modular utilities, code generators, and CLIs with schema validation baked in.
Apache License 2.0
51 stars 2 forks source link

Declarative Hook Config #231

Open robcxyz opened 8 months ago

robcxyz commented 8 months ago

Declarative Hook Config

Allow hooks to have a model_config parameter exposing pydantic config params

Overview

We should be able to customize the config on a declarative hook since it is possible with a python hook. For this though, we need to worry about order of operations as:

  1. The config is normally set on the base hook so we'll need to override that

  2. The config and base fields are natively not allowed to be set together

    • Creating custom create_model function will allow this
  3. Can't simply set the config via SomeModel.model_config

Solution seems to be #2 which will allow creation of the model with a custom config.

Potential Forms


S<-:

  foo: bar

  # 1

  __config__:

    extra: allow

  # 2

  Config:

    extra: allow

  # 3

  config:

    extra: allow

  # 4

  _config:

    extra: allow

  # 4

  config<-:

    extra: allow

  # 5

  Config<-:

    extra: allow
  1. config
  1. Config

RESOLUTION - Use Config and create custom pydantic Config object which can be used to access any of the hook's config parameters

New Hook Design


from tackle import BaseHook, Field

def SomeHook(BaseHook):

    hook_name: str

    a_field: str = Field()  # Custom Field

    class Config:

        # Classic pydantic config params

        extra = 'allow'

        # Custom params

        args = ['a_field']

        is_public = True

SomeHook<-:

  foo: str

  Config:

    extra: allow

    args: ['foo']

Alias

Implementation