Skip to content

Commit

Permalink
Templating: use '.jinja2' suffix on Jinja2 template files instead of …
Browse files Browse the repository at this point in the history
…generic/ambiguous '_t' suffix
  • Loading branch information
jayaddison committed Feb 3, 2023
1 parent ecfd08d commit 3e735ee
Show file tree
Hide file tree
Showing 122 changed files with 825 additions and 797 deletions.
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

0 comments on commit 3e735ee

Please sign in to comment.