Skip to content

Check copier.yaml for hyphenated variables #2031

Open
@InAnYan

Description

@InAnYan

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.

Actually, this is a "common" (in some sense of common) user story:

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions