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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make template-local extensions available to cookiecutter executions #1291

Closed

Conversation

croesnick
Copy link
Contributor

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 my cookiecutter.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 to sys.path in order to make custom Python modules (e.g., extensions) available to cookiecutter.

Downside: Custom modules might shadow other identically-named modules.

... by prepending the respective cookiecutter template folder to sys.path.
@croesnick
Copy link
Contributor Author

Duplicate of #1240

@insspb
Copy link
Member

insspb commented Feb 1, 2020

@croesnick thank you for contribution, but as you mentioned above it is duplicate.
Original issue already in plan.
Not sure about time forsing for original issue, but will look on it again, after dealing with current repo status.

@insspb insspb closed this Feb 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants