From 827494d6415b696a98fa195cbd883b50cc893bfc Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 11 Jan 2022 15:47:50 +0000 Subject: [PATCH] doctool: Add templates_dir CLI argument We can find the templates directory using the module file once installed, but when running uninstalled we need to have a way to specify where the templates can be found in the sources directory. --- giscanner/docmain.py | 4 +++- giscanner/docwriter.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/giscanner/docmain.py b/giscanner/docmain.py index dab063ef..88430f05 100644 --- a/giscanner/docmain.py +++ b/giscanner/docmain.py @@ -51,6 +51,8 @@ def doc_main(args): parser.add_argument("-s", "--write-sections-file", action="store_const", dest="format", const="sections", help="Backwards-compatible equivalent to -f sections") + parser.add_argument("--templates-dir", + action="store") args = parser.parse_args(args[1:]) if not args.output: @@ -74,7 +76,7 @@ def doc_main(args): with open(args.output, 'w', encoding='utf-8') as fp: write_sections_file(fp, sections_file) else: - writer = DocWriter(transformer, args.language, args.format) + writer = DocWriter(transformer, args.language, args.format, args.templates_dir) writer.write(args.output) return 0 diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py index d0cd610f..b72ab2ac 100644 --- a/giscanner/docwriter.py +++ b/giscanner/docwriter.py @@ -1288,7 +1288,7 @@ LANGUAGES = { class DocWriter(object): - def __init__(self, transformer, language, output_format): + def __init__(self, transformer, language, output_format, templates_dir=None): self._transformer = transformer try: @@ -1300,18 +1300,20 @@ class DocWriter(object): self._formatter = formatter_class(self._transformer) self._language = self._formatter.language self._output_format = output_format + self._templates_dir = templates_dir self._lookup = self._get_template_lookup() def _get_template_lookup(self): - if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ: + if self._templates_dir is not None: + srcdir = self._templates_dir + elif 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ: top_srcdir = os.environ['UNINSTALLED_INTROSPECTION_SRCDIR'] - srcdir = os.path.join(top_srcdir, 'giscanner') + srcdir = os.path.join(top_srcdir, 'giscanner', 'doctemplates') else: - srcdir = os.path.dirname(__file__) + srcdir = os.path.join(os.path.dirname(__file__), 'doctemplates') - template_dir = os.path.join(srcdir, 'doctemplates', - self._formatter.output_format) + template_dir = os.path.join(srcdir, self._formatter.output_format) return TemplateLookup(directories=[template_dir], module_directory=tempfile.mkdtemp(), -- 2.37.3