Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timkpaine
Copy link

This is a very small backwards-compatible change.

Copier uses .copier-answers.yml as the default, and supports overriding. As discussed in #1077 .yml is 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 .yaml suffix instead of .yml suffix, copier update will work without -a.

Copy link
Member

@sisp sisp left a 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.

  1. See my inline comment about your suggested change.
  2. 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 None and only resolve None as .copier-answers.yml or .copier-answers.yaml in copier/_user_data.py::load_answersfile_data.

Whatever the solution looks like in the end, I have three general requests:

  1. I think the .yml suffix should take precedence over the .yaml suffix for maximum backwards compatibility.
  2. I think we should check for the existence of both files (.yml suffix and .yaml suffix) and raise a warning if both exist, just in case, e.g., a project was migrated from .yaml to .yml but forgot to remove the .yaml file.
  3. Please add tests.

WDYT?

@@ -973,9 +973,10 @@ def resolved_vcs_ref(self) -> str | None:
@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")
Copy link
Member

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.

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