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

Layered Jinja templates with the same name #17

Closed
jayvdb opened this issue May 12, 2018 · 5 comments
Closed

Layered Jinja templates with the same name #17

jayvdb opened this issue May 12, 2018 · 5 comments
Labels
Milestone

Comments

@jayvdb
Copy link
Member

jayvdb commented May 12, 2018

I must admit I am not sure this is a great idea...but IMO is worth discussing.

Currently it is not possible to have two templates with the same name. That prevents a local one vs a global one.

One example:

  1. local .moban.dt/MANIFEST.in.jj2 with block 'more_options'
  2. https://github.com/moremoban/pypi-mobans/blob/master/templates/MANIFEST.in.jj2

Another:

  1. local .moban.dt/setup.py.jj2 with blocks
  2. https://github.com/moremoban/pypi-mobans/blob/master/templates/setup.py.jj2

That could be confusing, but then creating local templates with variant template names is also confusing, and annoying as they will have a common and unnecessary prefix.

@chfw
Copy link
Member

chfw commented May 12, 2018

django templating system has solved this problem. Let me check if jinja2 has anything similiar.

@chfw
Copy link
Member

chfw commented May 13, 2018

I got no luck with jinja2. The closest choice was ChoiceLoader but it is clever enough to understand setup.py.jj2 extends another setup.py.jj2, which locates in a different but sequential ordered folder.

The work around would be putting files under a special directory:

.moban.dt/local-override/setup.py.jj2

And then use this configuration

configuration:
  configuration_dir: "commons/config"
  template_dir:
    - ".moban.dt"
    - "commons/templates"
    - "setupmobans/templates"
  configuration: your.yml
targets:
  - setup.py: local-override/setup.py.jj2

Well, technically, there could be one more choice is to implement such a overlapping template loader by extending jinja2's baseloader. However, this may take some unknown time.

@jayvdb
Copy link
Member Author

jayvdb commented May 14, 2018

ChoiceLoader sounds perfect, with each item in template_dir becomes a choice in ChoiceLoader.
The order is then respected and important. It sounds 100% backwards compatible.

I did some quick hacking a few months ago and found jinja kept want to recurse, forever. I could see an easy hook into jinja to help it.

The 'two local subdirectories' workaround occurred to me, and .. eww. A worse workaround is to add . as a template_dir and then use setup.py : .moban.dt/setup.py.jj2 .. and I dont want to consider that either.

But, a different solution is to allow setup.py : .moban.dt/setup.py.jj2 if that template it is in one template_dir , and then moban can create a new temp dir with .moban.dt/setup.py.jj2 in it.
This only works for the initial template, and so isnt truly layered, but it solves the most common case. The error messages can then be revised to reflect the real filename.

@jayvdb jayvdb changed the title Layered templates with the same name Layered Jinja templates with the same name Jun 7, 2018
@chfw
Copy link
Member

chfw commented Jul 15, 2018

This won't be solved easily in near term. Let me sort out the easy ones first.

@chfw
Copy link
Member

chfw commented Aug 17, 2019

we are now using jinja2-fsloader. I am sure we will work this out ever. Hence, I am closing this issue.

@chfw chfw closed this as completed Aug 17, 2019
@chfw chfw added the wontfix label Aug 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants