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

Added: Templates inheritance #1485

Merged

Conversation

simobasso
Copy link
Member

@simobasso simobasso commented Jan 2, 2021

Hey @cookiecutter,
This implements a templates directory so a maintainer can use extends, includes, blocks, import and super 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!

@simobasso simobasso force-pushed the feature/add_templates_inheritance branch from 4ee385d to 49434b0 Compare January 2, 2021 18:13
@simobasso
Copy link
Member Author

@cookiecutter friendly ping 😊

@sisp
Copy link

sisp commented Mar 12, 2021

@cookiecutter Any chance of getting this PR merged? It's exactly what I've been looking for. Thanks @simobasso for implementing it!

@simobasso
Copy link
Member Author

Hey @audreyr @pydanny @hackebrot, any chance of getting this pr reviewed?

@pydanny
Copy link
Member

pydanny commented Apr 2, 2021

Apologies, but none of us have the unpaid bandwidth to work on this project.

I think we need to do another call for maintainers.

@simobasso
Copy link
Member Author

@pydanny, thanks anyway!

@HappyEinara
Copy link

HappyEinara commented Apr 12, 2021

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?

@samj1912
Copy link

samj1912 commented Apr 12, 2021

@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.

@simobasso
Copy link
Member Author

simobasso commented Apr 12, 2021

@pydanny @samj1912 if this project needs some love, I'm more than happy to give it some :).

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?

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.

@sisp
Copy link

sisp commented Aug 3, 2021

@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. 🙂

@tall-josh
Copy link

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.

@JWBWork
Copy link

JWBWork commented Jan 6, 2022

Any status update on this?

Copy link

@JWBWork JWBWork left a 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
@insspb insspb force-pushed the feature/add_templates_inheritance branch from 49434b0 to 347ac18 Compare June 6, 2022 09:47
@insspb
Copy link
Member

insspb commented Jun 6, 2022

Rebased to master

docs/advanced/templates.rst Outdated Show resolved Hide resolved
docs/advanced/templates.rst Outdated Show resolved Hide resolved
@insspb
Copy link
Member

insspb commented Jun 6, 2022

@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

@insspb insspb added the feature This issue/PR relates to major feature request. label Jun 6, 2022
@insspb insspb changed the title Introduces templates inheritance Added: Templates inheritance Jun 6, 2022
@insspb insspb merged commit 558f440 into cookiecutter:master Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to major feature request.
Projects
None yet
8 participants