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
Cannot use local imports in hooks #824
Comments
I stumbled upon the same issue. The reason why local imports don't work is that the "hook" script you write is meant to be executed as a standalone script, because it's actually a template that is processed by Jinja2, written to a temporary file (with an arbitrary name) and then executed. How Can We Fix This?To solve this situation, all files from the A positive "side-effect" of this would be that we would retain the filename of the hooks (that can then still be accessed via |
We could add the @henrahmagix, @bittner: would either of you be interested in putting together a PR for this change? |
@michaeljoseph Manipulating the Re preparing a PR: I have accepted the way |
@bittner, we don't need to generate all the files in We have the cookiecutter template checked-out somewhere ( |
@michaeljoseph Ack! My response email has been in my drafts! Sorry I didn't notice until now. Here it is...
Alas, my Python skills are beginner and I haven't read through this project's code very much (yet!) So whilst I will certainly look (and have been looking) into it, I wouldn't be a reliable implementer =) |
@theodesp would you like to have a go at implementing this? 🙏 |
OK I will give it a go |
PR #980 |
Thanks @theodesp! |
Hi, this issue is still exists? |
Any updates on this issue? |
As discussed, I get around this by configuring the PYTHONPATH: git clone https://github.com/org/template.git
export PYTHONPATH=$PYTHONPATH:`pwd`/template/hooks
cookiecutter ./template It's not ideal for public templates though, preferably end users don't need to clone and delete the repository themselves. Automatically configuring the PYTHONPATH for the execution of the template would be awesome. |
1.4.0
2.7
and3.4.3
(installed viapyenv
)Description:
In
hooks/pre_gen_project.py
, I am trying to importhooks/utils.py
, but it errors as below.Admittedly, the amount of code in
hooks/utils.py
isn't very much, and it's not being used inhooks/post_gen_project.py
(though at first I thought it would need to be), so there's no current advantage to having a separate file. However, it would be nice if local imports were able to be supported, or the documentation explained that they cannot be used.What I've run:
The text was updated successfully, but these errors were encountered: