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
Added: Templates inheritance #1485
Added: Templates inheritance #1485
Conversation
4ee385d
to
49434b0
Compare
@cookiecutter friendly ping 😊 |
@cookiecutter Any chance of getting this PR merged? It's exactly what I've been looking for. Thanks @simobasso for implementing it! |
Hey @audreyr @pydanny @hackebrot, any chance of getting this pr reviewed? |
Apologies, but none of us have the unpaid bandwidth to work on this project. I think we need to do another call for maintainers. |
@pydanny, thanks anyway! |
Hi all, I'd like to +1 this proposal because I think it would unlock a very powerful application for cookiecutter: composability. For example, if I want a template to provide my application with an API on AWS Lambda + API Gateway, then I could extend my core "python app" setup by including subtemplates "API" (providing FastAPI and some endpoint stubs and tests) and "AWS Lambda API" implementing the infra. That in turn could inherit from an AWS base template and be a sibling to an API-on-ECS template. Some of the more generic bits could be done by using separate python packages as the engine for composition and of course you could just do a massive batteries-included template and delete the irrelevant bits on a per-project basis But I think generating optional application components (CLI, web API, cloud provider, Slack integration) to be included by flags in cookiecutter.json would be really, really powerful when used creatively and carefully. On the other hand I find Jinja does get much less readable once you move from variable interpolation to control flow and blocks. I'm currently managing this sort of scenario using git-fu, but it takes a lot of attention to detail. I wonder if @timothycrosley or @samj1912 from Cruft would have the skills, interest or time to help with this? I do have one question on the implementation: the PR seems well able to include blocks of file content, but just as important would be the optional inclusion of whole files, directories or trees of directories in the same way (and analogously to the way cookiecutter permits templating in filenames). @simobasso do you have any thoughts on how that would be done? |
@HappyEinara thanks for the shout out! @pydanny I would be more than happy to help out with the maintanance of cookiecutter (I currently maintain http://cruft.github.io/ and https://github.com/samj1912/cookies which heavily rely on cookiecutter internals so I am fairly familiar with the codebase) but I would imagine we would still need more people (at least 1 more active maintainer) to be able to go through the current backlog of PRs and issues. |
@pydanny @samj1912 if this project needs some love, I'm more than happy to give it some :).
That's an interesting question. I will open a new issue to keep this one on track because I think it is a bit far away from the scope of this pr; please have a look at #1517. |
@cookiecutter Any chance for this PR to get merged? Or are there any remaining concerns? It's a really great feature I'd love to see become available. 🙂 |
Hi. Firstly LOVE Cookiecutter!!! If I could ⭐ more than once I would!!! Is there any movement on this PR? I would really love this feature. |
Any status update on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
implement a templates directory so a maintainer can use `extends`, `includes`, `blocks`, `import` and `super` inside the cookiecutter project template using jinja directly. docs: https://jinja.palletsprojects.com/en/2.11.x/templates/#template-inheritance closes: cookiecutter#1484 ref: cookiecutter#706 ref: cookiecutter#59 ref: cookiecutter#1004
49434b0
to
347ac18
Compare
Rebased to master |
@simobasso thank you for contribution and waiting. I will merge it, if you have a time please look at #1694 @sisp, @JWBWork, @tall-josh, @samj1912 this will be in next release |
Hey @cookiecutter,
This implements a templates directory so a maintainer can use
extends
,includes
,blocks
,import
andsuper
inside the cookiecutter project template using jinja.loader: https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.FileSystemLoader
template-inheritance docs: https://jinja.palletsprojects.com/en/2.11.x/templates/#template-inheritance
The ratio is described in:
closes: #1484
other issues on the same topic:
closes: #1495
closes: #818
refs: #409
similar/extendable issues that get an improvement from this pr:
ref: #706
ref: #59
ref: #1004
ref: #364
Thank you!