I'm developing a cookiecutter template. My template has some dependencies. For example, in hooks/post_gen_project.py I want to show a message using rich.print. How can I satisfy such a requirement?
Also, I've seen many cookiecutter templates with either setup.py, pyproject.toml, or setup.cfg files included in their root directory. What is the point of that?! At first, I thought that might be a way to add dependencies to my template but that didn't work and wondering about the whole idea behind that. Unfortunately, cookiecutter has a weak documentation describing all these concepts and details!
Thanks.
Solution 1
A practice would be installing the dependencies within the
pre_gen_project.pyhook file.This way, right before when
post_gen_projectgets triggered, it installsrichso that you can userich.printinpost_gen_project.pywith no issues.Solution 2
Another solution would be to keep a
cc_requirements.txtfile within your{{cookiecutter.project_slug}}/(or wherever you keep the template files) and put all your dependencies there.Then, in
post_gen_project.pyfile, use the following instruction to..cc_requirements.txtfile.Here would be the content of
post_gen_project.pyfile.setup.py,setup.cfg,pyproject.tomlThese files are often there for the sake of managing the metadata corresponding to the template. Some specific metadata keywords are just needed from those files such as
versionand not all of them. For instance, if you look around thepackageskeyword in those files, they are empty most of the time meaning when someone tries installing them, ultimately, nothing (functional) actually gets shipped!