Description
Actual Situation
Jinja doesn't allow variables to contain hyphens (-
), however YAML supports this.
Haven't thought much, I created templates using variables with hyphen. And I used hyphenated variable names in copier.yaml
. But copier
(as a whole) mistreated dataset-name
as dataset - name
. And I had a bit hard time catching and understanding what went wrong.
Desired Situation
What if copier
could perform a check of copier.yaml
before generating a project and raising an error if there is a variable in copier.yaml
that contains a hyphen?
Well, I guess I'm in the minority, not many people are fan or heavy users of hyphens. IDK if it makes sense to solve this issue just for me. But I believe a "semantic check" of a config file seems like a valid and quite useful architectural step.
- accessing Json variable jinja doesn't work when variable has hyphen apache/airflow#8688
- https://stackoverflow.com/questions/52396669/ansible-templating-skips-string-after-a-dash
- variable names with - characters cause exception in some contexts ansible/ansible#3907
All listed software uses Jinja for templating and users accidentally used hyphens in variable names. And were confused.
Proposed solution
Before generating the project, copier
can loop through variables of copier.yaml
and check if the name contains -
, then raise an error.
Though, it shouldn't be just the ordinary Python exception, as it would halt the execution. Let's not act like the current Zig compiler...
You already have InvalidConfigFileError
(https://github.com/copier-org/copier/blob/master/copier/errors.py#L31). Though it only used in parsing YAML files (https://github.com/copier-org/copier/blob/master/copier/template.py#L102)