Trouble deploying Extra context example using the Advanced Usage docs
See original GitHub issueI am having difficulty running the Advanced example Defaults + Extra Context, using the docs.
I have created a minimal reproducible example using this project.
$ mkdir cookiecutter-fabric-esneor
$ cd cookiecutter-fabric-esneor
$ mkdir {{cookiecutter.directory_name}}
$ cd {{cookiecutter.directory_name}}
Here is my cookiecutter.json
:
{
"fabric_type": "Vbox",
"username": "Tom Smith",
"user": "{{cookiecutter.username.lower().replace(' ','')}}",
"timestamp": "{{cookiecutter.timestamp}}"
}
Here is my cookiecutter_runner.py
(based on this):
from cookiecutter.main import cookiecutter
from datetime import datetime
cookiecutter(
'Hello',
extra_context={'timestamp': datetime.utcnow().isoformat()}
)
My tree is (based on this layout):
$ cd ~
$ tree
cookiecutter-fabric-esneor/
├── {{cookiecutter.directory_name}}/
└── {{cookiecutter.directory_name}}.sh
└── cookiecutter.json
└── cookiecutter_runner.py
This is the contents of {{cookiecutter.directory_name}}.sh
:
#!/bin/bash
echo "{{cookiecutter.timestamp}}"
When I run
$ cd ~
$ cookiecutter cookiecutter-fabric-esneor
I get this:
fabric_type [Vbox]:
username [Tom Smith]:
user [tomsmith]:
directory_name [fab_dir]:
Unable to render variable 'timestamp'
Error message: 'dict object' has no attribute 'timestamp'
Context: {
"cookiecuttter": {
.
.
.
"timestamp": "{{cookiecutter.timestamp}}"
}
}
It’s a pretty basic project and I’ve followed the documentation instructions but it seems like something is missing in the {{cookiecutter.directory_name}}
directory.
Is there another page in the documentation that has a full example of how to use the Extra Context?
- Cookiecutter version: 1.6.0
- Python version: 2.7.14
- Operating System: Ubuntu 17.10
EDIT: I hope you don’t mind me adding the 2 proposed labels to the title. I thought it would be helpful when reading this post.
cookiecutter.json
is missing: "directory_name": "fab_dir"
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Based on the information that you provided
cookiecutter_runner.py
will not be executed when running cookiecutter. What you want to do is run the script directly rather than callingcookiecutter
directly from the CLI and update the template argument accordingly.Apologies for the late reply…this issue was based on an advanced example from the docs. So, I think that it might not be very useful for most uses of
cookiecutter
. Also, there is a new context format in development (see #1566) - it may be a good idea to wait until that is implemented and see if that helps with your workflow (maybe you don’t need to use the approach from this issue when the new format takes effect).