pawamoy/copier-pdm

Update fails (unbound local error / subprocess error)

pawamoy opened this issue · 1 comments

I just published version 0.8.0 which brings actual support for Copier v6. While there shouldn't be any issue when generating new projects and updating them, an issue can arise when you try to update a pre-existing project from pre 0.8.0 to 0.8.0+ while your installed Copier version is very recent, like 6.0.0a9. In that case, just downgrade your Copier version to 6.0.0a5 (maybe a6 and a7 work too, didn't try), run the update, and you can upgrade Copier again. In my case, I use pipx:

% copier -f update
...
UnboundLocalError: local variable 'use_precommit' referenced before assignment
...
subprocess.CalledProcessError: Command 'python scripts/post_generation.py' returned non-zero exit status 1.

% pipx install -f copier==6.0.0a0
% pipx inject copier 'markupsafe<2.1'
...
% copier -f -r 0.10.0 update
...  # OK
% pipx uninstall copier
% pipx install copier
...  # upgrade again to latest

The explanation is that since a7 or a8 (commit copier-org/copier@d86c88d), Copier stopped automatically setting the previous Jinja envops ([[, ]], [%, etc.) when _min_copier_version is not present in copier.yml. Copier does set these settings if you have _min_copier_version: 5.1.0 in copier.yml, which I didn't have. My bad for not catching it before!

/cc @yajo as it could be of interest to you 🙂

yajo commented

Thank you. For these use cases, I think the easiest upgrade path is to just do a recopy with the latest copier and the latest template, and keep on updating from there.