feat(templating): add ${VAR} template variable substitution for YAML …#21
Merged
rafa-guedes merged 3 commits intomainfrom Feb 17, 2026
Merged
feat(templating): add ${VAR} template variable substitution for YAML …#21rafa-guedes merged 3 commits intomainfrom
rafa-guedes merged 3 commits intomainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…configs
Add template variable substitution system supporting environment variables, defaults, and datetime processing in YAML configuration files.
Features:
Implementation:
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.