-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
enhancementThis issue/PR relates to a feature request.This issue/PR relates to a feature request.
Description
It would be nice to be able to do optional pre- and post-processing on a template. Amongst other things this would allow for generation of random hashes for secret keys and other things. Perhaps something like this:
├── cookiecutter.json
├── {{cookiecutter.repo_name}}
├── pre_generate.py (optional)
├── post_generate.py (optional)
Perhaps the pre-generate module would expect a main() callable that returns a dictionary. This dictionary could include things that inject into the cookiecutter context.
For example, this would allow code for generating customized secret keys:
import random
import hashlib
try:
random = random.SystemRandom()
except NotImplementedError:
import warnings
warnings.warn('A secure pseudo-random number generator is not available '
'on your system. Falling back to Mersenne Twister.')
def main():
chars = list('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
random.shuffle(chars)
context = {"secret_key" = "".join(chars)}
return context
if __name__ == "__main__":
main()I could imagine cookiecutter's documentation including a recipe page for pre- and post-generate hooks. 🐹
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementThis issue/PR relates to a feature request.This issue/PR relates to a feature request.