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