Skip to content

Commit

Permalink
feat: add initial support to load custom code
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Jan 14, 2023
1 parent 6f82020 commit 9404ecc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions makejinja/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ def main(config: Config):
for path in _collect_files(config.data_paths):
if loader := DATA_LOADERS.get(path.suffix):
data.update(loader(path))

# TODO: Maybe remove `collect_files` and import as real module instead
for file in _collect_files(config.custom_code, "**/*.py"):
mod = _import_module(file)
env.globals.update(mod.globals)
env.filters.update(mod.filters)
data.update(mod.data)

if config.output_path.is_dir():
print(f"Remove '{config.output_path}' from previous run")
shutil.rmtree(config.output_path)
Expand Down
7 changes: 7 additions & 0 deletions makejinja/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class Config:
If multiple files are supplied, beware that previous declarations will be overwritten by newer ones.
""",
)
custom_code: list[Path] = ts.option(
factory=list,
click={"type": click.Path(exists=True, path_type=Path)},
help="""
Load custom code into the program. TODO: More details
""",
)
extension_names: list[str] = ts.option(
factory=list,
click={"param_decls": "--extension-name"},
Expand Down

0 comments on commit 9404ecc

Please sign in to comment.