refactor: clean up secret questions management #1209
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've cleaned up the internal bookkeeping logic for secret questions. The new structure will simplify raising an error when a secret question has no default value, which we discussed in #1177 (comment).
There are two ways to declare a question as secret:
secret: true
in the config of a question._secret_questions
list. This option is needed when a question that uses the<name>: <default value>
syntax shall be secret.Internally, Copier uses the a secret questions list to omit answers to secret questions from the answers file. This list contains the variable names of all secret questions independent of how they are declared as secret, so questions with
secret: true
are added to this list internally.Before, adding questions with the
secret: true
setting to the_secret_questions
list took place both intemplate.py:filter_config()
and intemplate.py:Template.secret_questions
which was redundant and also a bit error-prone because there was no clear separation of concerns where this information shall be synced.I've decided to let
template.py:filter_config()
only handle separating config and questions data as its docstring suggests, and sync the secret information intemplate.py:Template.secret_questions
(as it has been done already, so no change) andtemplate.py:Template.questions_data
.In addition, I've fixed some minor oddities:
{}
was used as a default value for getting the_secret_questions
list, which should be alist
.{"secret_questions": set()}
which makes not much sense (or is at least unnecessary).Those changes are purely internal though.