dictionary variables defined in cookiecutter.json erroring on manual run and templates in context values not working
See original GitHub issue- Cookiecutter version: 1.7.3
- Template project url: n/a
- Python version: 3.9.0
- Operating System: Windows 10
Description:
Fresh install of cookiecutter. When I run the template, I have a default set of defined variables in the cookiecutter.json file, one of which is supposed to be a hidden dictionary variable that the outputs use to lookup what to use in the output file. The problem is it still asks for input to this “hidden” variable as [default] and then errors when I press enter saying “Error: Unable to decode to JSON.” I do not have this issue when executing on my Mac with cookiecutter version 1.6.0. Also if I run the template with the --no-input flag it works fine but the problem then is the variables that I need the user to change from default arent changed because they of course do not get the prompt. Also I am using a template in the context values to set another hidden variable but it also does not work. The output contains the bracketed text as a whole in the output (not the value of the variable I expect). So in my example below, in the output file I get “{{ cookiecutter.olt” and I would expect to get BNG.
What I’ve run:
cookiecutter.json
{
"olt": "BNGOLT4",
<snip>
"_shelter": "{{ cookiecutter.olt[:3] }}",
"_drPair": {
"Lab": {
"dr1": "LABDR1",
"dr2": "LABDR2"
},
"3": {
"dr1": "CODDR3",
"dr2": "FABDR3"
},
"4": {
"dr1": "CODDR4",
"dr2": "FADDR4"
}
}
}
JSON error
$ cookiecutter testTemplate
olt [BNGOLT4]:
<snip>
_drPair [default]:
Error: Unable to decode to JSON.
_drPair [default]:
Error: Unable to decode to JSON.
_drPair [default]:
Error: Unable to decode to JSON.
_drPair [default]:
-v output of the default value of _drPair in cookiecutter.json
('_drPair', OrderedDict([('Lab', OrderedDict([('dr1', 'LABDR1'), ('dr2', 'LABDR2')])), ('3', OrderedDict([('dr1', 'CODDR3'), ('dr2', 'FADDR3')])), ('4', OrderedDict([('dr1', 'CODDR4'), ('dr2', 'FADDR4')])
Screenshot of the invalid output of the _shelter variable not pulling the defined value earlier:
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
The follow-up issue with JSON not being decoded was fixed in #1562, which is also still unreleased.
pip install cookiecutter 'click<8'
would work around this one.I’m not the right person to answer that. @simobasso @ssbarnea @SharpEdgeMarshall might know.