Skip to content

Conversation

@jangevaare
Copy link
Member

@jangevaare jangevaare commented Nov 12, 2025

Alternative to #93

This pull request introduces a major overhaul to how template customization and selection works in the pipeline, enabling dynamic loading of PHU-specific templates and assets at runtime. The changes allow organizations to maintain their own template directories (with custom branding, layouts, and assets) without modifying core code, and improve documentation and error handling for template management. The CLI is updated to support a --template argument, and the codebase now supports dynamic template discovery and loading.

Template system and CLI improvements:

  • Added support for PHU-specific template directories (phu_templates/) with customizable language modules, Typst config, and assets. Templates are loaded dynamically at runtime via build_language_renderers() in generate_notices.py. The CLI now accepts a --template argument to select a template directory. Documentation in AGENTS.MD, README.md, and the new phu_templates/README.md explains usage, requirements, and error handling. [1] [2] [3] [4]

Dynamic template loading and error handling:

  • Refactored template loading in pipeline/generate_notices.py to use load_template_module() and build_language_renderers() for dynamic discovery of available templates. Improved error messages for missing templates or assets, and made it possible for PHUs to provide templates for only a subset of supported languages.

  • Updated the rendering pipeline to pass the dynamic renderer dictionary to notice rendering functions, ensuring the correct template is used per organization and language. Improved error handling for missing language templates and assets.

Typst compilation and asset resolution:

  • Clarified documentation and parameter usage in pipeline/compile_notices.py to distinguish between the template directory (for dynamic template loading) and the Typst root directory (for compilation). Improved asset path resolution to support both relative and absolute paths, enabling use of custom assets outside the project root. [1] [2] [3] [4] [5] [6] [7]

Documentation and onboarding:

  • Added and updated documentation files (README.md, AGENTS.MD, phu_templates/README.md) to explain the new template system, CLI usage, template directory structure, asset requirements, and error handling for missing templates/assets. [1] [2]

Codebase cleanup and extensibility:

  • Removed hardcoded imports for default templates and replaced with dynamic loading, making the codebase more extensible and maintainable for future template additions or changes.

These changes make the pipeline significantly more flexible and user-friendly for organizations needing custom branding and layouts, while maintaining robust error handling and clear documentation.

@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 69.64286% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pipeline/orchestrator.py 22.22% 12 Missing and 2 partials ⚠️
pipeline/generate_notices.py 94.11% 1 Missing and 1 partial ⚠️
pipeline/compile_notices.py 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

----------
artifact_dir : Path
Directory containing Typst artifacts (.typ files).
Directory containing Typst template files
Copy link
Member Author

@jangevaare jangevaare Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was previous documentation was better? Here .typs are treated as client specific artifacts. These are by definition typst template files, but we use the term template in the repository in other ways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like use of word template better. Maybe a hybrid?

"Directory containing Typst template files (.typ)."

@kassyray
Copy link
Member

@jangevaare are we still using the --test-mode flag from my original work? Or now no need?


# Typst compilation always uses PROJECT_ROOT to find both templates and output artifacts.
# template_dir parameter is for dynamic template loading in generate_notices, not for Typst --root.
root_dir = ROOT_DIR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary if a constant?

Path to parameters.yaml configuration file.
template_dir : Path, optional
Template directory containing conf.typ and assets/. Used as Typst --root.
If not provided, defaults to project root.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If not provided, defaults to project root.
If not provided, defaults to project root, runs in test mode

spec.loader.exec_module(module)

# Validate render_notice() exists
if not hasattr(module, "render_notice"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be checked upon loading (load_template_module)?

renderers = {}
for lang in Language:
module_path = template_dir / f"{lang.value}_template.py"
# Only load if template file exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this should be checked on load if it is a necessary component?

f"Available languages: {available}\n"
f"Ensure your template directory contains {language.value}_template.py"
)
return renderers[language.value]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why this is separate from build? May suggest considering combining the two for simplicity.

def run_step_4_generate_notices(
output_dir: Path,
run_id: str,
assets_dir: Path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assets_dir would still exist?

The way I have it set up is phu_templates/phu_acronym/assets ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now this is addressed down more.

help=f"Config directory (default: {DEFAULT_CONFIG_DIR})",
)
parser.add_argument(
"--template",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether we call this --template_acronym or --phu_acronym for clarity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about --phu_template, which matches the parent folder name (minus the s)

* **Orchestrator:** `pipeline/orchestrator.py` is the `viper` CLI entry point and coordinates 9 steps.
* **Steps:** Modules are organized by steps 1–9, not by functional themes.
* **Templates:** `templates/` contains `en_template.py`, `fr_template.py`. Import via `from templates import ...`. Typesetting is separate from orchestration.
* **Templates:** `templates/` contains default language templates (`en_template.py`, `fr_template.py`), Typst config (`conf.typ`), and assets. `phu_templates/` is the container for PHU-specific template customizations (gitignored). Templates are loaded dynamically at runtime via `build_language_renderers()` in `generate_notices.py`. The `--template` CLI argument expects a template name within `phu_templates/` (e.g., `--template wdgph``phu_templates/wdgph/`). Template names cannot contain path separators (no nesting). Each template module must define a `render_notice()` function. Template directory isolation: templates, conf.typ, and assets stay together. Typesetting is separate from orchestration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really thinking that we may need to clarify template name to the phu acronym!

Co-authored-by: Kassy Raymond <44474665+kassyray@users.noreply.github.com>
@jangevaare
Copy link
Member Author

@jangevaare are we still using the --test-mode flag from my original work? Or now no need?

No need now

@jangevaare
Copy link
Member Author

Wondering if we use term "demo" instead of "test" when referring to example templates we provide?

@kassyray
Copy link
Member

Wondering if we use term "demo" instead of "test" when referring to example templates we provide?

That sounds like a good idea.

@jangevaare jangevaare merged commit 51dfffa into main Nov 13, 2025
1 of 2 checks passed
@jangevaare jangevaare deleted the refactor/cli-template-dir branch November 13, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants