Access the Context dict in the Pre/Post-Generate Hook scripts
See original GitHub issueHey, just want to start off by saying thanks for making this awesome project!
The title says it all–is there any way to access the context dict provided by the cli cookiecutter
command in the pre_gen_project.py
and post_gen_project.py
hook scripts? I want to be able to add an extra context variable (a timestamp just like the example), but without having to write my own script that wraps the cookiecutter.main.cookiecutter
function. I also wanted to be able to reassign the context variables if validation fails (instead of just raising an exception).
Any help is greatly appreciated. Keep up the good work! 😃
Issue Analytics
- State:
- Created 7 years ago
- Reactions:35
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Access the Context dict in the Pre/Post-Generate Hook scripts
The title says it all--is there any way to access the context dict provided by the cli cookiecutter command in the pre_gen_project.py and ......
Read more >Using Pre/Post-Generate Hooks - Cookiecutter - Read the Docs
This makes it easy for a post-generate hook to find generated files using relative paths. Template variables are rendered in the script¶. Just...
Read more >How do I access a dictionary key in a context variable that gets ...
You have added new variable in a context called categories so you can access its value through iterating categories {% for key, value...
Read more >Cookiecutter Documentation: Release 1.7.2 | PDF - Scribd
Direct access to the Cookiecutter API allows for injection of extra context. • Pre- and post-generate hooks: Python or shell scripts to run...
Read more >Awesome Bookmarks: My Collection - Cody Hiar
Ruslan's Blog · Looking up words in a Dictionary using Python ... Incrementally improving the performance of a python script, until nothing ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Asking a similar question. I wanted to use cookie cutter to deploy applications that require a lot of configuration and was hoping to use cookiecutter to templatize the deployment. I want to add variables that are like {{cookiecutter.current_directory}} or {{cookiecutter.current_user}} without needing to pass these in from the command line. I was hoping there was a hook somewhere that I could set these but I guess not.
I could pass these as extra context using the python api, but that requires a user calling a python script that calls out to the cookiecutter function which requires them to do more pre-installation. Would be great if there was a hook where I could modify the cookiecutter jinja variables.
See my reply at - https://github.com/cookiecutter/cookiecutter/issues/364#issuecomment-678683237 and the demo repo https://github.com/samj1912/cookiecutter-advanced-demo
That allows you to modify the cookiecutter context from pre gen hooks on cookiecutter v0.7+ with some advanced jinja hackery.
Advanced context modification for cookiecutter.