Make template-local extensions available to cookiecutter executions #1291
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As I am currently writing and refactoring my first cookiecutter template, chances are quite good I am missing on some already existing functionality. 馃檪 So please tell me if what I am trying to achieve is already possible.
Situation
While refactoring my template, I tried extracting common functionality (like formatting and conversion functions) into custom extensions. An example of such a conversion would be to reformat a given project name into a valid Python module name (no leading non-word characters, no leading numbers, non-word characters replaced by underscores). I created an
extensions
below my template's root, made it a module (added__init__.py
), and wrote said extensions. Finally, I added the extensions to mycookiecutter.json
's_extensions
list; e.g.,"extensions": ["extensions.naming.ModuleNameExtension"]
.Issue
As
extensions
is not within my PYTHONPATH, cookiecutter fails to find my modules (custom extensions).Proposal
Auto-prepend
repo_dir
tosys.path
in order to make custom Python modules (e.g., extensions) available to cookiecutter.Downside: Custom modules might shadow other identically-named modules.