From 91995230d43cb9bd9d67cf4469856bd186d1142e Mon Sep 17 00:00:00 2001 From: Ian McEwan <105806+ijm@users.noreply.github.com> Date: Sun, 7 Sep 2025 20:36:21 -0700 Subject: [PATCH 1/4] Resolved a TMPLDIR inconsistency and added some error reporting. --- sphinx/cmd/quickstart.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index a11856e497a..402e3b9e428 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -25,6 +25,8 @@ from sphinx.util.osutil import ensuredir from sphinx.util.template import SphinxRenderer +TMPLSUBDIR = 'quickstart' + if TYPE_CHECKING: from collections.abc import Callable, Sequence from typing import Any @@ -194,16 +196,18 @@ def _has_custom_template(self, template_name: str) -> bool: Note: Please don't use this function from extensions. It will be removed in the future without deprecation period. """ - template = os.path.join(self.templatedir, os.path.basename(template_name)) + template = os.path.join(self.templatedir, template_name) return bool(self.templatedir) and os.path.exists(template) def render(self, template_name: str, context: dict[str, Any]) -> str: if self._has_custom_template(template_name): custom_template = os.path.join( - self.templatedir, os.path.basename(template_name) + self.templatedir, template_name ) return self.render_from_file(custom_template, context) else: + if (bool(self.templatedir)): + print(__('Ignoreing TEMPLATEDIR=%s for %s') % (self.templatedir, template_name)) return super().render(template_name, context) @@ -472,10 +476,12 @@ 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.jinja') if templatedir else None + conf_path = os.path.join(templatedir, TMPLSUBDIR, 'conf.py.jinja') if templatedir else None if not conf_path or not os.path.isfile(conf_path): + if (bool(templatedir)): + print(__("%s does not exist, reverting to default template.") % (conf_path,)) conf_path = os.path.join( - package_dir, 'templates', 'quickstart', 'conf.py.jinja' + package_dir, 'templates', TMPLSUBDIR, 'conf.py.jinja' ) with open(conf_path, encoding='utf-8') as f: conf_text = f.read() @@ -483,13 +489,13 @@ def write_file(fpath: str, content: str, newline: str | None = None) -> None: write_file(os.path.join(srcdir, 'conf.py'), template.render_string(conf_text, d)) masterfile = os.path.join(srcdir, d['master'] + d['suffix']) - if template._has_custom_template('quickstart/master_doc.rst.jinja'): - write_file(masterfile, template.render('quickstart/master_doc.rst.jinja', d)) + if template._has_custom_template(f'{TMPLSUBDIR}/master_doc.rst.jinja'): + write_file(masterfile, template.render(f'{TMPLSUBDIR}/master_doc.rst.jinja', d)) else: - write_file(masterfile, template.render('quickstart/root_doc.rst.jinja', d)) + write_file(masterfile, template.render(f'{TMPLSUBDIR}/root_doc.rst.jinja', d)) - makefile_template = 'quickstart/Makefile.new.jinja' - batchfile_template = 'quickstart/make.bat.new.jinja' + makefile_template = f'{TMPLSUBDIR}/Makefile.new.jinja' + batchfile_template = f'{TMPLSUBDIR}/make.bat.new.jinja' if d['makefile'] is True: d['rsrcdir'] = 'source' if d['sep'] else '.' @@ -721,7 +727,7 @@ def get_parser() -> argparse.ArgumentParser: '--templatedir', metavar='TEMPLATEDIR', dest='templatedir', - help=__('template directory for template files'), + help=__('template directory for %s/*.jinja template files') % (TMPLSUBDIR,), ) group.add_argument( '-d', From 495d2d8fee937d7c3657603a1b7748f2926a828b Mon Sep 17 00:00:00 2001 From: Ian McEwan <105806+ijm@users.noreply.github.com> Date: Sun, 7 Sep 2025 22:16:14 -0700 Subject: [PATCH 2/4] Resolved style lint errors. --- sphinx/cmd/quickstart.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 402e3b9e428..57921c9a713 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -207,7 +207,8 @@ def render(self, template_name: str, context: dict[str, Any]) -> str: return self.render_from_file(custom_template, context) else: if (bool(self.templatedir)): - print(__('Ignoreing TEMPLATEDIR=%s for %s') % (self.templatedir, template_name)) + print(__('Ignoreing TEMPLATEDIR=%s for %s') % + (self.templatedir, template_name)) return super().render(template_name, context) @@ -479,7 +480,7 @@ def write_file(fpath: str, content: str, newline: str | None = None) -> None: conf_path = os.path.join(templatedir, TMPLSUBDIR, 'conf.py.jinja') if templatedir else None if not conf_path or not os.path.isfile(conf_path): if (bool(templatedir)): - print(__("%s does not exist, reverting to default template.") % (conf_path,)) + print(__('%s does not exist, reverting to default template.') % (conf_path,)) conf_path = os.path.join( package_dir, 'templates', TMPLSUBDIR, 'conf.py.jinja' ) From b59a498d0b3cc46adf4fd016cc6f7847802df786 Mon Sep 17 00:00:00 2001 From: Ian McEwan <105806+ijm@users.noreply.github.com> Date: Sun, 7 Sep 2025 22:28:23 -0700 Subject: [PATCH 3/4] Resolved ruff style errors. --- sphinx/cmd/quickstart.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 57921c9a713..c0a71296327 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -201,14 +201,14 @@ def _has_custom_template(self, template_name: str) -> bool: def render(self, template_name: str, context: dict[str, Any]) -> str: if self._has_custom_template(template_name): - custom_template = os.path.join( - self.templatedir, template_name - ) + custom_template = os.path.join(self.templatedir, template_name) return self.render_from_file(custom_template, context) else: if (bool(self.templatedir)): - print(__('Ignoreing TEMPLATEDIR=%s for %s') % - (self.templatedir, template_name)) + print( + __('Ignoreing TEMPLATEDIR=%s for %s') + % (self.templatedir, template_name) + ) return super().render(template_name, context) @@ -477,13 +477,15 @@ 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, TMPLSUBDIR, 'conf.py.jinja') if templatedir else None + conf_path = ( + os.path.join(templatedir, TMPLSUBDIR, 'conf.py.jinja') if templatedir else None + ) if not conf_path or not os.path.isfile(conf_path): - if (bool(templatedir)): - print(__('%s does not exist, reverting to default template.') % (conf_path,)) - conf_path = os.path.join( - package_dir, 'templates', TMPLSUBDIR, 'conf.py.jinja' - ) + if bool(templatedir): + print( + __('%s does not exist, reverting to default template.') % (conf_path,) + ) + conf_path = os.path.join(package_dir, 'templates', TMPLSUBDIR, 'conf.py.jinja') with open(conf_path, encoding='utf-8') as f: conf_text = f.read() From 9c5e12eb0730e8037aaee636446c3392331c055a Mon Sep 17 00:00:00 2001 From: Ian McEwan <105806+ijm@users.noreply.github.com> Date: Sun, 7 Sep 2025 22:31:32 -0700 Subject: [PATCH 4/4] Resolved ruff style errors (2). --- sphinx/cmd/quickstart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index c0a71296327..fcd1e418ed2 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -204,7 +204,7 @@ def render(self, template_name: str, context: dict[str, Any]) -> str: custom_template = os.path.join(self.templatedir, template_name) return self.render_from_file(custom_template, context) else: - if (bool(self.templatedir)): + if bool(self.templatedir): print( __('Ignoreing TEMPLATEDIR=%s for %s') % (self.templatedir, template_name)