Skip to content

feat(templating): add ${VAR} template variable substitution for YAML …#21

Merged
rafa-guedes merged 3 commits intomainfrom
cli_render
Feb 17, 2026
Merged

feat(templating): add ${VAR} template variable substitution for YAML …#21
rafa-guedes merged 3 commits intomainfrom
cli_render

Conversation

@tomdurrant
Copy link
Contributor

…configs

Add template variable substitution system supporting environment variables, defaults, and datetime processing in YAML configuration files.

Features:

  • ${VAR} syntax for environment variable substitution
  • ${VAR:-default} for default values
  • Type conversion (int, float, bool) for exact-match expressions
  • Datetime filters: as_datetime, strftime, shift
  • Filter chaining: ${CYCLE|as_datetime|shift:-1d|strftime:%Y%m%d}
  • Recursive processing of dict/list/str structures

Implementation:

  • New module: src/rompy/templating.py (390 lines)
  • Integrated into cli.py load_config() between YAML parse and Pydantic validation
  • Zero external dependencies
  • Comprehensive tests (450+ lines, 60+ test cases)
  • Full documentation with examples

This enables dynamic config generation for operational workflows where file paths, dates, and environment-specific values need to be templated.

Separate from existing cookiecutter ({{...}}) which renders model control files. This handles config-level substitution before Pydantic validation.

…configs

Add template variable substitution system supporting environment variables,
defaults, and datetime processing in YAML configuration files.

Features:
- ${VAR} syntax for environment variable substitution
- ${VAR:-default} for default values
- Type conversion (int, float, bool) for exact-match expressions
- Datetime filters: as_datetime, strftime, shift
- Filter chaining: ${CYCLE|as_datetime|shift:-1d|strftime:%Y%m%d}
- Recursive processing of dict/list/str structures

Implementation:
- New module: src/rompy/templating.py (390 lines)
- Integrated into cli.py load_config() between YAML parse and Pydantic validation
- Zero external dependencies
- Comprehensive tests (450+ lines, 60+ test cases)
- Full documentation with examples

This enables dynamic config generation for operational workflows where
file paths, dates, and environment-specific values need to be templated.

Separate from existing cookiecutter ({{...}}) which renders model control
files. This handles config-level substitution before Pydantic validation.
…d type handling

Fix 3 failing tests in test_templating.py:

- test_parse_invalid_format: Update regex to match 'Cannot parse.*datetime'

- test_shift_invalid_unit: Update expected error from 'Unknown time unit' to 'Invalid shift format'

- test_filter_chain_in_exact_match: Skip type conversion when filters are applied

- This prevents strftime output like '20221231' from being auto-converted to int
@rafa-guedes rafa-guedes merged commit d4c1575 into main Feb 17, 2026
1 check passed
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.

2 participants

Comments