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

Support and prefer .jinja to _t for static templates #11165

Merged
merged 40 commits into from Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3e735ee
Templating: use '.jinja2' suffix on Jinja2 template files instead of …
jayaddison Jan 31, 2023
5ce9483
ruff suggestion: adopt union typing syntax (with support provided by …
jayaddison Feb 3, 2023
168cb23
Merge branch 'master' into templating/jinja2-suffix
jayaddison Feb 13, 2023
4a8a339
Update file extension: the 'jinja2' project has been renamed to 'jinj…
jayaddison Feb 19, 2023
eb9938a
Merge branch 'master' into templating/jinja2-suffix
jayaddison Feb 19, 2023
43f8b2b
Fixup: ruff lint error (missing trailing comma after multi-line multi…
jayaddison Feb 19, 2023
b2889de
Fixup: adjust trim-length for template suffix (was: seven characters …
jayaddison Feb 19, 2023
a720933
Localization: undo changes to resource files
jayaddison Mar 21, 2023
6f99cef
Merge branch 'master' into templating/jinja2-suffix
jayaddison Mar 21, 2023
d2af9b5
Logic adjustment and refactor: rename '_template_basename' utility me…
jayaddison Apr 6, 2023
526fdc7
Emit a more-generic PendingDeprecationWarning instead of RemovedInSph…
jayaddison Apr 6, 2023
cd0d61f
CHANGES: document the deprecation of the '_t' file-copy template suffix
jayaddison Apr 6, 2023
5ab2226
Code commentary / feature removal timeline: provide two years from to…
jayaddison Apr 6, 2023
b8570ab
Merge branch 'master' into templating/jinja2-suffix
jayaddison Apr 6, 2023
59534ea
CHANGES: Add issue thread number reference
jayaddison Apr 6, 2023
e38e78e
Cleanup: remove unused import
jayaddison Apr 6, 2023
6305f96
Documentation: update hint related to LaTeX template filenames
jayaddison Apr 6, 2023
dc850b7
Babel resource extraction: update latex template method mappings to i…
jayaddison Apr 6, 2023
04aa946
Babel resource extraction: update javascript template method mapping …
jayaddison Apr 6, 2023
8572661
Babel resource extraction: update latex template options to include r…
jayaddison Apr 6, 2023
0eb993d
Revert changes to latex file rendering
jayaddison Apr 6, 2023
0444616
LaTeX templating: re-migrate to preferred '.tex.jinja' template suffi…
jayaddison Apr 6, 2023
29fb6f0
Fixup: migrate imgmath LaTeX template to use .jinja suffix
jayaddison Apr 6, 2023
1630cc8
Test coverage: ensure that we have test coverage for the legacy LaTeX…
jayaddison Apr 6, 2023
d85f016
Fixup: migrate built-in preview.tex LaTeX template
jayaddison Apr 6, 2023
8475023
Merge branch 'master' into templating/jinja2-suffix
AA-Turner Apr 6, 2023
bc43d2e
CHANGES: Update deprecation note to mention built-in templates
jayaddison Apr 6, 2023
06aa004
imgmath LaTeX templating: provide backwards-compatibility in the case…
jayaddison Apr 6, 2023
7b061cf
Safety in code path where a multi-item iterable is expected to be red…
jayaddison Apr 6, 2023
abd8af5
Fixup: add missing import
jayaddison Apr 6, 2023
d8e3fa7
Revert "Logic adjustment and refactor: rename '_template_basename' ut…
jayaddison Apr 6, 2023
30c7318
Fixup: imgmath: fallback to template filename with .jinja suffix
jayaddison Apr 6, 2023
d0aa68a
Template suffix iteration: use the 'tuple' datatype instead of 'list'…
jayaddison Apr 7, 2023
299dbed
Documentation: add explanatory docstring to utility '_template_basena…
jayaddison Apr 7, 2023
c3b5cb9
Adjust date, add helper function
AA-Turner Apr 7, 2023
6600615
Add tests
AA-Turner Apr 7, 2023
9327357
Update ``theming.rst``
AA-Turner Apr 7, 2023
cccdfaf
Update CHANGES
AA-Turner Apr 7, 2023
cb9ea44
left -> removed
AA-Turner Apr 7, 2023
9a4410a
credits
AA-Turner Apr 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions sphinx/builders/_epub_base.py
Expand Up @@ -605,7 +605,8 @@ def build_content(self) -> None:
html.escape(self.refnodes[0]['refuri'])))

# write the project file
copy_asset_file(path.join(self.template_dir, 'content.opf_t'), self.outdir, metadata)
content_t = path.join(self.template_dir, 'content.opf.jinja2')
copy_asset_file(content_t, self.outdir, metadata)

def new_navpoint(self, node: dict[str, Any], level: int, incr: bool = True) -> NavPoint:
"""Create a new entry in the toc from the node at given level."""
Expand Down Expand Up @@ -688,7 +689,7 @@ def build_toc(self) -> None:
navpoints = self.build_navpoints(refnodes)
level = max(item['level'] for item in self.refnodes)
level = min(level, self.config.epub_tocdepth)
copy_asset_file(path.join(self.template_dir, 'toc.ncx_t'), self.outdir,
copy_asset_file(path.join(self.template_dir, 'toc.ncx.jinja2'), self.outdir,
self.toc_metadata(level, navpoints))

def build_epub(self) -> None:
Expand Down
8 changes: 4 additions & 4 deletions sphinx/builders/changes.py
Expand Up @@ -133,10 +133,10 @@ def hl(no: int, line: str) -> str:
f.write(self.templates.render('changes/rstsource.html', ctx))
themectx = {'theme_' + key: val for (key, val) in
self.theme.get_options({}).items()}
copy_asset_file(path.join(package_dir, 'themes', 'default', 'static', 'default.css_t'),
self.outdir, context=themectx, renderer=self.templates)
copy_asset_file(path.join(package_dir, 'themes', 'basic', 'static', 'basic.css'),
self.outdir)
default_t = path.join(package_dir, 'themes', 'default', 'static', 'default.css.jinja2')
copy_asset_file(default_t, self.outdir, context=themectx, renderer=self.templates)
basic = path.join(package_dir, 'themes', 'basic', 'static', 'basic.css')
copy_asset_file(basic, self.outdir)

def hl(self, text: str, version: str) -> str:
text = html.escape(text)
Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/epub3.py
Expand Up @@ -184,7 +184,7 @@ def build_navigation_doc(self) -> None:
# 'includehidden'
refnodes = self.refnodes
navlist = self.build_navlist(refnodes)
copy_asset_file(path.join(self.template_dir, 'nav.xhtml_t'), self.outdir,
copy_asset_file(path.join(self.template_dir, 'nav.xhtml.jinja2'), self.outdir,
self.navigation_doc_metadata(navlist))

# Add nav.xhtml to epub file
Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/gettext.py
Expand Up @@ -280,7 +280,7 @@ def finish(self) -> None:
ensuredir(path.join(self.outdir, path.dirname(textdomain)))

context['messages'] = list(catalog)
content = GettextRenderer(outdir=self.outdir).render('message.pot_t', context)
content = GettextRenderer(outdir=self.outdir).render('message.pot.jinja2', context)

pofn = path.join(self.outdir, textdomain + '.pot')
if should_write(pofn, content):
Expand Down
4 changes: 2 additions & 2 deletions sphinx/builders/latex/__init__.py
Expand Up @@ -403,7 +403,7 @@ def copy_support_files(self) -> None:
# use pre-1.6.x Makefile for make latexpdf on Windows
if os.name == 'nt':
staticdirname = path.join(package_dir, 'texinputs_win')
copy_asset_file(path.join(staticdirname, 'Makefile_t'),
copy_asset_file(path.join(staticdirname, 'Makefile.jinja2'),
self.outdir, context=context)

@progress_message(__('copying additional files'))
Expand Down Expand Up @@ -443,7 +443,7 @@ def write_message_catalog(self) -> None:
if self.context['babel'] or self.context['polyglossia']:
context['addtocaptions'] = r'\addto\captions%s' % self.babel.get_language()

filename = path.join(package_dir, 'templates', 'latex', 'sphinxmessages.sty_t')
filename = path.join(package_dir, 'templates', 'latex', 'sphinxmessages.sty.jinja2')
copy_asset_file(filename, self.outdir, context=context, renderer=LaTeXRenderer())


Expand Down
18 changes: 9 additions & 9 deletions sphinx/cmd/quickstart.py
Expand Up @@ -371,29 +371,29 @@ def write_file(fpath: str, content: str, newline: str | None = None) -> None:
if 'quiet' not in d:
print(__('File %s already exists, skipping.') % fpath)

conf_path = os.path.join(templatedir, 'conf.py_t') if templatedir else None
conf_path = os.path.join(templatedir, 'conf.py.jinja2') if templatedir else None
if not conf_path or not path.isfile(conf_path):
conf_path = os.path.join(package_dir, 'templates', 'quickstart', 'conf.py_t')
conf_path = os.path.join(package_dir, 'templates', 'quickstart', 'conf.py.jinja2')
with open(conf_path, encoding="utf-8") as f:
conf_text = f.read()

write_file(path.join(srcdir, 'conf.py'), template.render_string(conf_text, d))

masterfile = path.join(srcdir, d['master'] + d['suffix'])
if template._has_custom_template('quickstart/master_doc.rst_t'):
if template._has_custom_template('quickstart/master_doc.rst.jinja2'):
msg = ('A custom template `master_doc.rst_t` found. It has been renamed to '
'`root_doc.rst_t`. Please rename it on your project too.')
print(colorize('red', msg))
write_file(masterfile, template.render('quickstart/master_doc.rst_t', d))
write_file(masterfile, template.render('quickstart/master_doc.rst.jinja2', d))
else:
write_file(masterfile, template.render('quickstart/root_doc.rst_t', d))
write_file(masterfile, template.render('quickstart/root_doc.rst.jinja2', d))

if d.get('make_mode') is True:
makefile_template = 'quickstart/Makefile.new_t'
batchfile_template = 'quickstart/make.bat.new_t'
makefile_template = 'quickstart/Makefile.new.jinja2'
batchfile_template = 'quickstart/make.bat.new.jinja2'
else:
makefile_template = 'quickstart/Makefile_t'
batchfile_template = 'quickstart/make.bat_t'
makefile_template = 'quickstart/Makefile.jinja2'
batchfile_template = 'quickstart/make.bat.jinja2'

if d['makefile'] is True:
d['rsrcdir'] = 'source' if d['sep'] else '.'
Expand Down
7 changes: 4 additions & 3 deletions sphinx/ext/apidoc.py
Expand Up @@ -102,7 +102,7 @@ def create_module_file(package: str, basename: str, opts: Any,
'qualname': qualname,
'automodule_options': options,
}
text = ReSTRenderer([user_template_dir, template_dir]).render('module.rst_t', context)
text = ReSTRenderer([user_template_dir, template_dir]).render('module.rst.jinja2', context)
write_file(qualname, text, opts)


Expand Down Expand Up @@ -138,7 +138,8 @@ def create_package_file(root: str, master_package: str, subroot: str, py_files:
'show_headings': not opts.noheadings,
'maxdepth': opts.maxdepth,
}
text = ReSTRenderer([user_template_dir, template_dir]).render('package.rst_t', context)
engine = ReSTRenderer([user_template_dir, template_dir])
text = engine.render('package.rst.jinja2', context)
write_file(pkgname, text, opts)

if submodules and opts.separatemodules:
Expand All @@ -163,7 +164,7 @@ def create_modules_toc_file(modules: list[str], opts: Any, name: str = 'modules'
'maxdepth': opts.maxdepth,
'docnames': modules,
}
text = ReSTRenderer([user_template_dir, template_dir]).render('toc.rst_t', context)
text = ReSTRenderer([user_template_dir, template_dir]).render('toc.rst.jinja2', context)
write_file(name, text, opts)


Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/imgmath.py
Expand Up @@ -91,9 +91,9 @@ def generate_latex_macro(image_format: str,
}

if config.imgmath_use_preview:
template_name = 'preview.tex_t'
template_name = 'preview.tex.jinja2'
else:
template_name = 'template.tex_t'
template_name = 'template.tex.jinja2'

for template_dir in config.templates_path:
template = path.join(confdir, template_dir, template_name)
Expand Down
24 changes: 12 additions & 12 deletions sphinx/locale/ar/LC_MESSAGES/sphinx.po
Expand Up @@ -1106,7 +1106,7 @@ msgid "\"latex_documents\" config value references unknown document %s"
msgstr ""

#: sphinx/builders/latex/__init__.py:184 sphinx/domains/std.py:596
#: sphinx/templates/latex/latex.tex_t:97
#: sphinx/templates/latex/latex.tex.jinja2:97
#: sphinx/themes/basic/genindex-single.html:30
#: sphinx/themes/basic/genindex-single.html:55
#: sphinx/themes/basic/genindex-split.html:11
Expand All @@ -1117,7 +1117,7 @@ msgstr ""
msgid "Index"
msgstr ""

#: sphinx/builders/latex/__init__.py:187 sphinx/templates/latex/latex.tex_t:82
#: sphinx/builders/latex/__init__.py:187 sphinx/templates/latex/latex.tex.jinja2:82
msgid "Release"
msgstr ""

Expand Down Expand Up @@ -2394,7 +2394,7 @@ msgid "unknown index entry type %r"
msgstr ""

#: sphinx/environment/adapters/indexentries.py:166
#: sphinx/templates/latex/sphinxmessages.sty_t:11
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:11
msgid "Symbols"
msgstr ""

Expand Down Expand Up @@ -3208,25 +3208,25 @@ msgstr "نصيحة"
msgid "Warning"
msgstr "تحذير"

#: sphinx/templates/latex/longtable.tex_t:23
#: sphinx/templates/latex/sphinxmessages.sty_t:8
#: sphinx/templates/latex/longtable.tex.jinja2:23
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:8
msgid "continued from previous page"
msgstr ""

#: sphinx/templates/latex/longtable.tex_t:29
#: sphinx/templates/latex/sphinxmessages.sty_t:9
#: sphinx/templates/latex/longtable.tex.jinja2:29
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:9
msgid "continues on next page"
msgstr "استمرار في الصفحة التالية"

#: sphinx/templates/latex/sphinxmessages.sty_t:10
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:10
msgid "Non-alphabetical"
msgstr ""

#: sphinx/templates/latex/sphinxmessages.sty_t:12
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:12
msgid "Numbers"
msgstr "أرقام"

#: sphinx/templates/latex/sphinxmessages.sty_t:13
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:13
msgid "page"
msgstr "صفحة"

Expand Down Expand Up @@ -3458,11 +3458,11 @@ msgid "Hide Search Matches"
msgstr ""

#: sphinx/themes/classic/layout.html:20
#: sphinx/themes/classic/static/sidebar.js_t:57
#: sphinx/themes/classic/static/sidebar.js.jinja2:57
msgid "Collapse sidebar"
msgstr ""

#: sphinx/themes/classic/static/sidebar.js_t:48
#: sphinx/themes/classic/static/sidebar.js.jinja2:48
msgid "Expand sidebar"
msgstr ""

Expand Down
24 changes: 12 additions & 12 deletions sphinx/locale/bg/LC_MESSAGES/sphinx.po
Expand Up @@ -1104,7 +1104,7 @@ msgid "\"latex_documents\" config value references unknown document %s"
msgstr ""

#: sphinx/builders/latex/__init__.py:184 sphinx/domains/std.py:596
#: sphinx/templates/latex/latex.tex_t:97
#: sphinx/templates/latex/latex.tex.jinja2:97
#: sphinx/themes/basic/genindex-single.html:30
#: sphinx/themes/basic/genindex-single.html:55
#: sphinx/themes/basic/genindex-split.html:11
Expand All @@ -1115,7 +1115,7 @@ msgstr ""
msgid "Index"
msgstr ""

#: sphinx/builders/latex/__init__.py:187 sphinx/templates/latex/latex.tex_t:82
#: sphinx/builders/latex/__init__.py:187 sphinx/templates/latex/latex.tex.jinja2:82
msgid "Release"
msgstr ""

Expand Down Expand Up @@ -2392,7 +2392,7 @@ msgid "unknown index entry type %r"
msgstr ""

#: sphinx/environment/adapters/indexentries.py:166
#: sphinx/templates/latex/sphinxmessages.sty_t:11
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:11
msgid "Symbols"
msgstr ""

Expand Down Expand Up @@ -3206,25 +3206,25 @@ msgstr ""
msgid "Warning"
msgstr ""

#: sphinx/templates/latex/longtable.tex_t:23
#: sphinx/templates/latex/sphinxmessages.sty_t:8
#: sphinx/templates/latex/longtable.tex.jinja2:23
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:8
msgid "continued from previous page"
msgstr ""

#: sphinx/templates/latex/longtable.tex_t:29
#: sphinx/templates/latex/sphinxmessages.sty_t:9
#: sphinx/templates/latex/longtable.tex.jinja2:29
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:9
msgid "continues on next page"
msgstr ""

#: sphinx/templates/latex/sphinxmessages.sty_t:10
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:10
msgid "Non-alphabetical"
msgstr ""

#: sphinx/templates/latex/sphinxmessages.sty_t:12
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:12
msgid "Numbers"
msgstr ""

#: sphinx/templates/latex/sphinxmessages.sty_t:13
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:13
msgid "page"
msgstr ""

Expand Down Expand Up @@ -3456,11 +3456,11 @@ msgid "Hide Search Matches"
msgstr ""

#: sphinx/themes/classic/layout.html:20
#: sphinx/themes/classic/static/sidebar.js_t:57
#: sphinx/themes/classic/static/sidebar.js.jinja2:57
msgid "Collapse sidebar"
msgstr ""

#: sphinx/themes/classic/static/sidebar.js_t:48
#: sphinx/themes/classic/static/sidebar.js.jinja2:48
msgid "Expand sidebar"
msgstr ""

Expand Down
24 changes: 12 additions & 12 deletions sphinx/locale/bn/LC_MESSAGES/sphinx.po
Expand Up @@ -1105,7 +1105,7 @@ msgid "\"latex_documents\" config value references unknown document %s"
msgstr ""

#: sphinx/builders/latex/__init__.py:184 sphinx/domains/std.py:596
#: sphinx/templates/latex/latex.tex_t:97
#: sphinx/templates/latex/latex.tex.jinja2:97
#: sphinx/themes/basic/genindex-single.html:30
#: sphinx/themes/basic/genindex-single.html:55
#: sphinx/themes/basic/genindex-split.html:11
Expand All @@ -1116,7 +1116,7 @@ msgstr ""
msgid "Index"
msgstr "ইনডেক্স"

#: sphinx/builders/latex/__init__.py:187 sphinx/templates/latex/latex.tex_t:82
#: sphinx/builders/latex/__init__.py:187 sphinx/templates/latex/latex.tex.jinja2:82
msgid "Release"
msgstr "রিলিজ"

Expand Down Expand Up @@ -2393,7 +2393,7 @@ msgid "unknown index entry type %r"
msgstr ""

#: sphinx/environment/adapters/indexentries.py:166
#: sphinx/templates/latex/sphinxmessages.sty_t:11
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:11
msgid "Symbols"
msgstr ""

Expand Down Expand Up @@ -3207,25 +3207,25 @@ msgstr "পরামর্শ"
msgid "Warning"
msgstr "সতর্কতা"

#: sphinx/templates/latex/longtable.tex_t:23
#: sphinx/templates/latex/sphinxmessages.sty_t:8
#: sphinx/templates/latex/longtable.tex.jinja2:23
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:8
msgid "continued from previous page"
msgstr "পূর্ববর্তী পাতা হতে চলমান"

#: sphinx/templates/latex/longtable.tex_t:29
#: sphinx/templates/latex/sphinxmessages.sty_t:9
#: sphinx/templates/latex/longtable.tex.jinja2:29
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:9
msgid "continues on next page"
msgstr ""

#: sphinx/templates/latex/sphinxmessages.sty_t:10
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:10
msgid "Non-alphabetical"
msgstr ""

#: sphinx/templates/latex/sphinxmessages.sty_t:12
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:12
msgid "Numbers"
msgstr ""

#: sphinx/templates/latex/sphinxmessages.sty_t:13
#: sphinx/templates/latex/sphinxmessages.sty.jinja2:13
msgid "page"
msgstr ""

Expand Down Expand Up @@ -3457,11 +3457,11 @@ msgid "Hide Search Matches"
msgstr "অনুসন্ধানের ম্যাচগুলো লুকান"

#: sphinx/themes/classic/layout.html:20
#: sphinx/themes/classic/static/sidebar.js_t:57
#: sphinx/themes/classic/static/sidebar.js.jinja2:57
msgid "Collapse sidebar"
msgstr ""

#: sphinx/themes/classic/static/sidebar.js_t:48
#: sphinx/themes/classic/static/sidebar.js.jinja2:48
msgid "Expand sidebar"
msgstr ""

Expand Down