Skip to content
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

Updating the project creates a new .copier-answer.yml file #1617

Closed
slocoro opened this issue Apr 30, 2024 · 3 comments
Closed

Updating the project creates a new .copier-answer.yml file #1617

slocoro opened this issue Apr 30, 2024 · 3 comments
Labels
bug triage Trying to make sure if this is valid or not

Comments

@slocoro
Copy link

slocoro commented Apr 30, 2024

Describe the problem

Hi, I have a project cloned from a local template. Both are version controlled with git. When I add a new file in my template and cd into my project and run copier update the project updates but creates a new .copier-answer.yml file and adds the new file in the wrong location.

Here's a visual of what's happening:

Original template structure:

.
├── .gitignore
├── copier.yml
└── templates
    └── vertex_batch
        └── {{repo_id}}
            ├── .github
            │   └── workflows
            │       └── build.yaml
            ├── .gitignore.jinja
            ├── {% if use_gx %}gx{% endif %}
            │   └── expectations
            │       └── file.json
            ├── {{_copier_conf.answers_file}}.jinja
            └── {{python_module_name}}
                └── main.py

Original project structure (the root of the template is at templates/vertex_batch):

.
├── .copier-answers.yml
├── .github
│   └── workflows
│       └── build.yaml
├── .gitignore
├── gx
│   └── expectations
│       └── file.json
└── test_repo
    └── main.py

Original template structure with new file:

.
├── .gitignore
├── copier.yml
└── templates
    └── vertex_batch
        └── {{repo_id}}
            ├── .github
            │   └── workflows
            │       └── build.yaml
            ├── .gitignore.jinja
            ├── README.md   -------------- (NEW FILE)
            ├── {% if use_gx %}gx{% endif %}
            │   └── expectations
            │       └── file.json
            ├── {{_copier_conf.answers_file}}.jinja
            └── {{python_module_name}}
                └── main.py

Updated project structure after running copier upate from the root of the project:

.
├── .copier-answers.yml
├── .github
│   └── workflows
│       └── build.yaml
├── .gitignore
├── gx
│   └── expectations
│       └── file.json
└── test_repo
    ├── .copier-answers.yml  -------------- (unexpected new file)
    ├── README.md   -------------- (NEW FILE in wrong location)
    └── main.py

My copier.yml:

_subdirectory: templates/vertex_batch

repo_id:
    type: str
    help: What is your repo name?

python_module_name:
    default: "{{repo_id}}"
    # prevent from being prompted for this
    when: false

use_gx:
  type: bool
  default: yes

Template

local template

To Reproduce

No response

Logs

No response

Expected behavior

The updating of the project should maintain the same structure as the template and there shouldn't add a new .copier-answer.yml file.

Screenshots/screencasts/logs

No response

Operating system

macOS

Operating system distribution and version

Ventura 13.5

Copier version

9.2.0

Python version

CPython 3.10

Installation method

pipx+pypi

Additional context

No response

@slocoro slocoro added bug triage Trying to make sure if this is valid or not labels Apr 30, 2024
@pawamoy
Copy link
Contributor

pawamoy commented Apr 30, 2024

└── templates
    └── vertex_batch
        └── {{repo_id}}
_subdirectory: templates/vertex_batch

repo_id:
    type: str
    help: What is your repo name?

That's a misuse IMO. You're trying to force the name of the output directory. It's confirmed by the fact that you put the copier-answers file into it, and only shows the contents of this {{repo_id}} folder as your "project":

.
├── .copier-answers.yml

If you then update in this directory, which is not the root directory of the generated project, then the project gets generated again in a subdirectory of the project, in this case test_repo, because test_repo is the value of {{python_module_name}} which defaults to {{repo_id}}. I suppose you entered test_repo as repo ID.

The solution is: don't try to force the name of the output directory. You can't: users will always, always be able to decide of their directory name. And you shouldn't: the directory name of a project shouldn't matter.

Simply remove the {{repo_id}} layer from your file tree:

.
├── .gitignore
├── copier.yml
└── templates
    └── vertex_batch
        ├── .github
        │   └── workflows
        │       └── build.yaml
        ├── .gitignore.jinja
        ├── README.md   -------------- (NEW FILE)
        ├── {% if use_gx %}gx{% endif %}
        │   └── expectations
        │       └── file.json
        ├── {{_copier_conf.answers_file}}.jinja
        └── {{python_module_name}}
            └── main.py

@slocoro
Copy link
Author

slocoro commented May 1, 2024

Ok I see, I didn't realise this was a misuse. I'm looking for a replacement for Cruft which allows the name of the output directory to be dynamic. Will move the copier-answers file to the root

@pawamoy
Copy link
Contributor

pawamoy commented May 1, 2024

Thanks for your understanding 😄 You can advise your users to use copier copy your-template their-directory instead of copier copy your-template .. Closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Trying to make sure if this is valid or not
Projects
None yet
Development

No branches or pull requests

2 participants