Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support requirements.txt for template hooks #1993

Open
michael-todorovic opened this issue Dec 5, 2023 · 1 comment
Open

Support requirements.txt for template hooks #1993

michael-todorovic opened this issue Dec 5, 2023 · 1 comment

Comments

@michael-todorovic
Copy link

Hello,
We'd like to use python hooks, rather than bash as it supports easy sharable libraries. However, I didn't find a way to manage those dependencies.

Could we imagine that cookiecutter runs a pip install -r requirements.txt contained in a template to install required dependencies for the hooks? Or do you prefer to keep this separated from cookiecutter?

We can likely provide a PR for this feat if you're interested in it 😄

Thanks!

@alanverresen
Copy link
Contributor

Cookiecutter currently does not have any built-in functionality to install packages for your hooks, but it is possible to use packages within your hooks. I'm not a core member of this project, but here's my two cents.

Unless there's something that I'm missing, cookiecutter and its hooks are ran on top of your current environment's Python binary/installation, so if you install the needed dependencies before running cookiecutter, you can import them within the hooks. If you need isolation, you can use pipx, venv, etc. to run cookiecutter in a virtual environment with your dependencies installed.

You can also use cookiecutter's hooks to act as a bootstrap for your actual hook scripts:

  1. create and activate a virtual environment
  2. install the needed dependencies
  3. run your actual hook script

If cookiecutter were to add built-in functionality to install a hook's dependencies, I imagine that it would use a virtual environment to execute the hooks in the same way as I described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants