Skip to content

Commit a6c2bdd

Browse files
authored
Rename template files in Sphinx to use the .jinja extension (#12364)
1 parent e38a60d commit a6c2bdd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+60
-53
lines changed

doc/man/sphinx-apidoc.rst

Lines changed: 9 additions & 9 deletions

doc/man/sphinx-quickstart.rst

Lines changed: 6 additions & 6 deletions

sphinx/builders/_epub_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def build_content(self) -> None:
615615
html.escape(self.refnodes[0]['refuri'])))
616616

617617
# write the project file
618-
copy_asset_file(path.join(self.template_dir, 'content.opf_t'), self.outdir, metadata)
618+
copy_asset_file(path.join(self.template_dir, 'content.opf.jinja'), self.outdir, metadata) # NoQA: E501
619619

620620
def new_navpoint(self, node: dict[str, Any], level: int, incr: bool = True) -> NavPoint:
621621
"""Create a new entry in the toc from the node at given level."""
@@ -698,7 +698,7 @@ def build_toc(self) -> None:
698698
navpoints = self.build_navpoints(refnodes)
699699
level = max(item['level'] for item in self.refnodes)
700700
level = min(level, self.config.epub_tocdepth)
701-
copy_asset_file(path.join(self.template_dir, 'toc.ncx_t'), self.outdir,
701+
copy_asset_file(path.join(self.template_dir, 'toc.ncx.jinja'), self.outdir,
702702
self.toc_metadata(level, navpoints))
703703

704704
def build_epub(self) -> None:

sphinx/builders/changes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def hl(no: int, line: str) -> str:
140140
f.write(self.templates.render('changes/rstsource.html', ctx))
141141
themectx = {'theme_' + key: val for (key, val) in
142142
self.theme.get_options({}).items()}
143-
copy_asset_file(path.join(package_dir, 'themes', 'default', 'static', 'default.css_t'),
143+
copy_asset_file(path.join(package_dir, 'themes', 'default', 'static', 'default.css.jinja'), # NoQA: E501
144144
self.outdir, context=themectx, renderer=self.templates)
145145
copy_asset_file(path.join(package_dir, 'themes', 'basic', 'static', 'basic.css'),
146146
self.outdir)

sphinx/builders/epub3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def build_navigation_doc(self) -> None:
194194
# 'includehidden'
195195
refnodes = self.refnodes
196196
navlist = self.build_navlist(refnodes)
197-
copy_asset_file(path.join(self.template_dir, 'nav.xhtml_t'), self.outdir,
197+
copy_asset_file(path.join(self.template_dir, 'nav.xhtml.jinja'), self.outdir,
198198
self.navigation_doc_metadata(navlist))
199199

200200
# Add nav.xhtml to epub file

sphinx/builders/gettext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def finish(self) -> None:
287287
ensuredir(path.join(self.outdir, path.dirname(textdomain)))
288288

289289
context['messages'] = list(catalog)
290-
content = GettextRenderer(outdir=self.outdir).render('message.pot_t', context)
290+
content = GettextRenderer(outdir=self.outdir).render('message.pot.jinja', context)
291291

292292
pofn = path.join(self.outdir, textdomain + '.pot')
293293
if should_write(pofn, content):

sphinx/builders/latex/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def copy_support_files(self) -> None:
417417
# use pre-1.6.x Makefile for make latexpdf on Windows
418418
if os.name == 'nt':
419419
staticdirname = path.join(package_dir, 'texinputs_win')
420-
copy_asset_file(path.join(staticdirname, 'Makefile_t'),
420+
copy_asset_file(path.join(staticdirname, 'Makefile.jinja'),
421421
self.outdir, context=context)
422422

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

459-
filename = path.join(package_dir, 'templates', 'latex', 'sphinxmessages.sty_t')
459+
filename = path.join(package_dir, 'templates', 'latex', 'sphinxmessages.sty.jinja')
460460
copy_asset_file(filename, self.outdir, context=context, renderer=LaTeXRenderer())
461461

462462

sphinx/cmd/quickstart.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,32 +372,32 @@ def write_file(fpath: str, content: str, newline: str | None = None) -> None:
372372
if 'quiet' not in d:
373373
print(__('File %s already exists, skipping.') % fpath)
374374

375-
conf_path = os.path.join(templatedir, 'conf.py_t') if templatedir else None
375+
conf_path = os.path.join(templatedir, 'conf.py.jinja') if templatedir else None
376376
if not conf_path or not path.isfile(conf_path):
377-
conf_path = os.path.join(package_dir, 'templates', 'quickstart', 'conf.py_t')
377+
conf_path = os.path.join(package_dir, 'templates', 'quickstart', 'conf.py.jinja')
378378
with open(conf_path, encoding="utf-8") as f:
379379
conf_text = f.read()
380380

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

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

392392
if d.get('make_mode'):
393-
makefile_template = 'quickstart/Makefile.new_t'
394-
batchfile_template = 'quickstart/make.bat.new_t'
393+
makefile_template = 'quickstart/Makefile.new.jinja'
394+
batchfile_template = 'quickstart/make.bat.new.jinja'
395395
else:
396396
# xref RemovedInSphinx80Warning
397397
msg = "Support for '--no-use-make-mode' will be removed in Sphinx 8."
398398
print(colorize('red', msg))
399-
makefile_template = 'quickstart/Makefile_t'
400-
batchfile_template = 'quickstart/make.bat_t'
399+
makefile_template = 'quickstart/Makefile.jinja'
400+
batchfile_template = 'quickstart/make.bat.jinja'
401401

402402
if d['makefile'] is True:
403403
d['rsrcdir'] = 'source' if d['sep'] else '.'

sphinx/ext/apidoc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def create_module_file(
114114
template_path = [user_template_dir, template_dir]
115115
else:
116116
template_path = [template_dir]
117-
text = ReSTRenderer(template_path).render('module.rst_t', context)
117+
text = ReSTRenderer(template_path).render('module.rst.jinja', context)
118118
return write_file(qualname, text, opts)
119119

120120

@@ -172,7 +172,7 @@ def create_package_file(
172172

173173
written: list[Path] = []
174174

175-
text = ReSTRenderer(template_path).render('package.rst_t', context)
175+
text = ReSTRenderer(template_path).render('package.rst.jinja', context)
176176
written.append(write_file(pkgname, text, opts))
177177

178178
if submodules and opts.separatemodules:
@@ -209,7 +209,7 @@ def create_modules_toc_file(
209209
template_path = [user_template_dir, template_dir]
210210
else:
211211
template_path = [template_dir]
212-
text = ReSTRenderer(template_path).render('toc.rst_t', context)
212+
text = ReSTRenderer(template_path).render('toc.rst.jinja', context)
213213
return write_file(name, text, opts)
214214

215215

sphinx/ext/imgmath.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,17 @@ def generate_latex_macro(image_format: str,
103103
}
104104

105105
if config.imgmath_use_preview:
106-
template_name = 'preview.tex_t'
106+
template_name = 'preview.tex'
107107
else:
108-
template_name = 'template.tex_t'
108+
template_name = 'template.tex'
109109

110110
for template_dir in config.templates_path:
111-
template = path.join(confdir, template_dir, template_name)
112-
if path.exists(template):
113-
return LaTeXRenderer().render(template, variables)
111+
for template_suffix in ('.jinja', '_t'):
112+
template = path.join(confdir, template_dir, template_name + template_suffix)
113+
if path.exists(template):
114+
return LaTeXRenderer().render(template, variables)
114115

115-
return LaTeXRenderer(templates_path).render(template_name, variables)
116+
return LaTeXRenderer(templates_path).render(template_name + '.jinja', variables)
116117

117118

118119
def ensure_tempdir(builder: Builder) -> str:

0 commit comments

Comments
 (0)