Closed chris-sanders closed 3 years ago
Thanks for testing the alpha and for reporting, I'll add this to the v6 roadmap.
I've been looking at this more and I've now triggered it on the v5 aslo. But I think I see what's actually happening. As part of the update process the template is cloned into an empty directory and then diffed against the actual final directory. During the initial copy into the tmp directory it's running the tasks and I have tasks which expect files in the destination directory which fail.
I'm not sure how to best handle that. I can catch the errors and just exit clean, but I actually wanted to fail if the destination folder doesn't match expectation. I'm applying this template as a delta on top of another folder structure and If the structure doesn't match what I expect I would like it to fail.
There are a couple of ideas that come to my mind.
--search-root
to specify where to look for it. I use it in one of our templates and it works fine.I actually wanted to fail if the destination folder doesn't match expectation
Currently Copier only runs tasks after the copy. What you want is probably a better system that runs them before, to see if the project expectations are matched. That progress is being tracked in #240 and I hope it's ready for v6 final.
You can run the
tox -e integration
and you'll see that it fails when it invokes one of the scripts because it can't find the file, which is in the destination folder the task is just not being run in the correct location.
Tests fail with something that doesn't seem related to copier:
So I ran the test manually:
The interesting part is:
File "/tmp/tmp.srxrxoudz4/dst/tasks.py", line 40, in check_yaml
config = yaml.safe_load(config_file.read_text())
Which shows clearly that invoke finds the tasks.py
file and that it gets executed inside the destination directory.
Also, the failure:
FileNotFoundError: [Errno 2] No such file or directory: 'config.yaml'
Is correct:
╰─ env LANG=C ls dst/config.yaml
ls: cannot access 'dst/config.yaml': No such file or directory
So, AFAICS, all these are bugs in the template itself, not something related to copier.
Regarding the issue at hand, our CI asserts that the tasks are executed in the dst directory always. You can check the test here, and see that it's passing. Unless there's a bug in the test, this issue is fixed in our side: https://github.com/copier-org/copier/blob/93d95a6a7bda7ac3bc201356e63e7cfacd810dad/tests/test_tasks.py#L8-L43
Feel free to reopen if needed 😊
I switched from using copier 5.1.0 to the latest 6.0.0a6 to avoid copier deleting a folder that it didn't create. However with the v6 version I'm having an issue with tasks getting executed by invoke during a copier update.
With version 5 the tasks run as expected, but with v6 during an update tasks that call invoke don't run from the destination folder but from the template sub-folder, where it can't find the expected files.
The template can be found at the v6 branch here: https://github.com/charmed-kubernetes/pytest-operator-template/tree/v6
You can run the
tox -e integration
and you'll see that it fails when it invokes one of the scripts because it can't find the file, which is in the destination folder the task is just not being run in the correct location.