-
-
Notifications
You must be signed in to change notification settings - Fork 227
Allow for .copier-answers.yaml to be default in backwards-compatible way #2196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to supporting the .yaml suffix in a backwards-compatible way, but I'm afraid the solution is a little more involved.
- See my inline comment about your suggested change.
- The default answers file name/path is hardcoded in a few places: https://github.com/search?q=repo%3Acopier-org%2Fcopier+%22.copier-answers.yml%22+path%3A%2F%5Ecopier%5C%2F%2F&type=code This should be refactored anyway, but with a primary and secondary file name/path, we can't simply use a default value, as there isn't a single one anymore but rather some logic that first tries reading the primary file name/path and falls back to the secondary when the primary doesn't exist. Perhaps the simplest solution is to encode the default answers file name/path as
Noneand only resolveNoneas.copier-answers.ymlor.copier-answers.yamlincopier/_user_data.py::load_answersfile_data.
Whatever the solution looks like in the end, I have three general requests:
- I think the
.ymlsuffix should take precedence over the.yamlsuffix for maximum backwards compatibility. - I think we should check for the existence of both files (
.ymlsuffix and.yamlsuffix) and raise a warning if both exist, just in case, e.g., a project was migrated from.yamlto.ymlbut forgot to remove the.yamlfile. - Please add tests.
WDYT?
| @cached_property | ||
| def subproject(self) -> Subproject: | ||
| """Get related subproject.""" | ||
| default_answers_file = Path(".copier-answers.yaml") if Path(".copier-answers.yaml").exists() else Path(".copier-answers.yml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work because the Path object passed to the answers_relpath argument of Subproject(local_abspath=..., answers_relpath=...) is the path of the answers file relative to local_abspath. Path(".copier-answers.yaml").exists() checks whether .copier-answers.yaml exists in the current working directory, which is not guaranteed to be local_abspath.
Sounds good, unfortunately it will be slightly annoying as we'll have to make sure to look in the "right direction", e.g. in some places you want to check
Makes sense to me.
Will do |
|
coming back to this soon, apologies I got distracted with some other copier stuff. |
|
Awesome presentation @timkpaine! Always nice to see our work presented in conferences π |
This is a very small backwards-compatible change.
Copier uses
.copier-answers.ymlas the default, and supports overriding. As discussed in #1077.ymlis the default suffix, not.yaml. It makes sense to not change the default, but perhaps it would be ok to start to check.copier-answers.yaml? This PR does that very small change, if the user has decided to use the default answers file but with.yamlsuffix instead of.ymlsuffix,copier updatewill work without-a.