-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Support and prefer .jinja
to _t
for static templates
#11165
Support and prefer .jinja
to _t
for static templates
#11165
Conversation
This would break all extensions that use the So please don't do that. |
Thanks @mgeier - I wasn't aware of that. I think that results in two possible paths to follow: either I'll abandon these changes, or I'll include compatibility with the existing suffix for extensions that rely on that. (I'm leaning towards the former at the moment, but will spend some more time thinking about it) |
I support the change but we'd have to include a deprecation period of perhaps a year or longer. A |
…generic/ambiguous '_t' suffix
3bfb7b4
to
3e735ee
Compare
…PEP0563 for pre-py310)
Although this is ready-for-review, I'm also trying to gauge my level of commitment in terms of supporting and migrating existing extensions. Generally I think the best approach would be to try to identify as many extensions as possible that are reliant on the existing template suffix format and to offer pull requests with relevant migrations for them (hopefully in most cases those would be straightforward). I might need to spend a bit of time to recharge before starting that analysis, though. |
…a', so let's simplify the filename extension accordingly
…-argument method call parameter list)
…for '.jinja2', is now: six characters for '.jinja') Note: cannot yet simplify this code by using str.removesuffix, since that was introduced in py39 and we are maintaining py38 support
I've run some (admittedly legacy) GitHub code searches to find potentially-affected extensions. Very few use the In cases that are So far I don't think that there are many valid use cases for dynamic content rendering during asset file copying, but there may be valid use cases I'm yet to learn about. |
Following on from that: I'm still unaware of many good use cases for this copy-and-apply-templating in the Sphinx That's making me wonder whether instead of suggesting a |
The suggested change here will not only affect extensions that use It will even not only affect extensions, but also themes and plain old Sphinx users who want to overwrite an existing file in Here are examples for the (at least) three different cases:
Those are just examples where I myself have used the I was wondering though: since it seems to be reasonably simple to support both |
Thank you for looking into this further @mgeier. I became sidetracked by one particular detail, as I often do, and forgot to look at the rest of the picture.
That seems like a good approach to me 👍 |
… to hold the suffix string elements Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
A pedantic observation:
I don't think that's likely to cause huge problems; on case-sensitive filesystems I doubt that people would prefer to use |
I don't think it's worth the additional filesystem existence checks to look for these. If someone does encounter a problem due to uppercase file extensions on a case-sensitive system, then hopefully they can resolve that locally and harmlessly by renaming the files. If not, then with an issue report we can consider adjusting the code appropriately. |
Ok, thanks for bearing with me while I hold tedious public conversations with myself @AA-Turner. I think I'm now comfortable that this changeset is ready to merge 👍 |
CHANGES
Outdated
@@ -23,6 +23,9 @@ Deprecated | |||
---------- | |||
|
|||
* #11247: Deprecate the legacy ``intersphinx_mapping`` format | |||
* #11165: The ``_t`` suffix for templating (``sphinx.util.copy_asset()``, | |||
``sphinx.util.copy_asset_file()`` and built-in templates) is now deprecated. |
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.
I would prefer if they would not yet be called "deprecated".
I think consensus was to mark them as "pending deprecation"?
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.
Ok, yep: I'll update the CHANGES
entry (and this pull request title) to say "pending deprecation" instead.
Sorta-related: reading back through some of the previous commentary, it looks like I misread one of your previous messages:
I was wondering though: since it seems to be reasonably simple to support both _t and .jinja for a deprecation period, why not support both indefinitely and never deprecate them?
That seems like a good approach to me 👍
Somehow I didn't read/understand the never deprecate them
part of that.
To me, the goal here is to make the purpose and content of the template files less ambiguous. Currently _t
indicates that they're templates, but doesn't say much about what kind of templating that is. .jinja
indicates both template, and a templating language that's in use.
(so, correcting myself: supporting both sounds good, but I would like to suggest deprecating _t
at some point)
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.
If we supported both suffixes _t
and .jinja
equally: would there be any situations where we'd recommend using _t
instead of .jinja
?
sphinx/ext/imgmath.py
Outdated
return LaTeXRenderer().render(template, variables) | ||
|
||
return LaTeXRenderer(templates_path).render(template_name, variables) | ||
# TODO: remove "_t" template suffix support after 2025-04-06 |
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.
I think support should not be removed at that time, but the deprecation period should start at that time!
At the given date, a DeprecationWarning
should be created, and after another year or two support for _t
can be removed.
sphinx/util/fileutil.py
Outdated
"""Given an input filename: | ||
If the input looks like a template, then return the filename output should | ||
be written to. Otherwise, return no result (None).""" | ||
# TODO: remove "_t" template suffix support after 2025-04-06 |
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.
See above, the deprecation period should start at that date.
sphinx/util/fileutil.py
Outdated
# TODO: remove "_t" template suffix support after 2025-04-06 | ||
if filename.lower().endswith('_t'): | ||
warnings.warn( | ||
f"{filename!r}: filename suffix '_t' for templates is deprecated. " |
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.
f"{filename!r}: filename suffix '_t' for templates is deprecated. " | |
f"{filename!r}: filename suffix '_t' for templates will become deprecated. " |
sphinx/writers/latex.py
Outdated
template_name) | ||
if path.exists(template): | ||
return renderer.render(template, variables) | ||
# TODO: remove "_t" template suffix support after 2025-04-06 |
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.
As above, this should be the start of the deprecation period.
tests/test_build_latex.py
Outdated
@@ -1379,6 +1379,10 @@ def test_latex_table_custom_template_caseA(app, status, warning): | |||
result = (app.outdir / 'python.tex').read_text(encoding='utf8') | |||
assert 'SALUT LES COPAINS' in result | |||
|
|||
# # TODO: remove "_t" template suffix support after 2025-04-06 |
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.
same as above
tests/test_util_fileutil.py
Outdated
|
||
|
||
def test_legacy_template_basename(): | ||
# TODO: remove "_t" template suffix support after 2025-04-06 |
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.
same as above
Is it really necessary to ever remove support for It looks like minimal additional code, and the whole deprecation mechanism sure seems much more complicated than simply keeping both |
I've centralised the 'deprecation' calls to I've also updated the documentation in (what will become) https://www.sphinx-doc.org/en/master/development/theming.html. A |
.jinja
to _t
for static templates
Thanks @jayaddison! A |
Thanks again @AA-Turner - I'll stay around to watch for issues related to this (and should probably re-read the deprecation policy a few times during the process). |
I've begun thinking about an edge-case today that I haven't yet found in practice, but it does still worry me: What if some Sphinx sites/extensions contain static files that intentionally already use a With this change, those files would be evaluated and the results written to a file without the extension, possibly a breaking change in those cases. |
Even though I'd be slightly annoyed with myself for reverting this change (for clearly not planning it thoroughly), perhaps this should not be included in 6.2.0 - with my previous comment in mind, I think a better way to phase it in would be:
Step one would allow time for people who do use Reasoning: Perhaps I'm overthinking it, but since this is something I'm contributing in personal time (I do make contributions that I consider work-related here too, but this isn't one of them), and would continue to complete this in personal time, I'd prefer to choose a path that's likely to be as minimally-stressful for users (and therefore myself) as possible, even if that takes longer. If it is included in 6.2.0 anyway though, I'll make time available to support these changes as best possible. |
…phinx-doc#11165)" This reverts commit 5d13215.
…phinx-doc#11165)" This reverts commit 5d13215.
@jayaddison Thanks for all your work on this. I understand your concern and maybe indeed we can delay it so I will add a LGTM to your reverting PR, and wait for @AA-Turner opinion. My presence here will be very sparse for about 4 weeks. |
Thank you, @jfbu. |
Feature or Bugfix
Purpose
This is a pedantic change that relates to nedbat/coveragepy#1488, where
coveragepy
emits some warnings because it's unclear based on the file suffix whether some template files that contain Python code (and are processed by Jinja) indeed are Python code.The suggested changes here probably only make sense if the corresponding templates are only expected to be used internally by Sphinx itself. If the template filenames are part of any kind of implicit interface for external libraries/applications, then this change might be more disruptive than the small benefit that it could provide.
Detail
_t
suffix exist that contain Jinja templates, replace the suffix with.jinja2
.j2
was considered as an alternative suffix -.jinja2
seems less ambiguousRelates