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

Add support for local imports in hooks #2031

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

LKajan
Copy link

@LKajan LKajan commented Mar 8, 2024

Render the whole hook directory to a temporary folder before executing hooks so that it's possible to use local imports in hooks.

I kindly request comments regarding this implementation before finalizing this PR by adding tests and documentation.

A few notes about the implementation:

  • Pre_prompt_hook is still executed from the original location.
  • Relative imports in hooks are not supported. This is because relative imports are not possible if the hook module itself is not imported, hooks are executed as scripts.

A few questions that I have:

  • How much do we care about the backwards compatibility of the API? This leaves the following methods orphaned:
    • run_hook_from_repo_dir()
    • run_hook()
    • run_script_with_context()
  • Should it be possible to modify the post_gen_hook by the pre_gen_hook?
  • Should the repo directory be added to the PYTHONPATH during hook execution so that hooks can access packages from the repo directory?
  • What is Cookiecutter's policy regarding typing annotations? Should those be added to the new code?

Resolves #824

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

Successfully merging this pull request may close these issues.

Cannot use local imports in hooks
1 participant