copier-org / copier

Library and command-line utility for rendering projects templates.
https://readthedocs.org/projects/copier/
MIT License
2.06k stars 182 forks source link

Make computed fields available in the answer files #1857

Closed NF-ada closed 1 week ago

NF-ada commented 1 week ago

Actual Situation

When creating computed fields with when: false, make it possible to have them accessible in the answer files.

I'm using copier to setup a project with a python script and copier is called within that script with run_copy. That way allows to access computed values without issues.

I'd like my users to install copier globally though, call it from the CLI and have further setups be handled by custom scripts. As such, I need to access some computed values afterwards, from the YAML answers file.

Desired Situation

Adding an export: true or something similar when when: false is set such that it makes it possible to export some variables to the answers files. I think doing it per variable is best as it wouldn't impact existing usage.

Proposed solution

When creating the answers file, check for fields that are both when: false & export: true and add them to the answers file.

sisp commented 1 week ago

Before considering to add a new feature related to computed values, is it an option for you to "export" computed values manually by adding a file like .copier-computed-values.yaml (or any filename you like) like this:

my_computed_value: "{{ my_computed_value }}"
# ...
NF-ada commented 1 week ago

Thanks, it'll be a sufficient solution!