diff --git a/ntd2d/ntd2d_action/files/borgedconffile.py b/ntd2d/ntd2d_action/files/borgedconffile.py index 05ff75e..a3d724b 100644 --- a/ntd2d/ntd2d_action/files/borgedconffile.py +++ b/ntd2d/ntd2d_action/files/borgedconffile.py @@ -5,9 +5,9 @@ class BorgedConfFile(ConfFile): """Sphinx configuration file that overlays the html theme.""" - def __init__(self, source_dir, original_docs): + def __init__(self, source_dir, config, original_docs): self.original_docs = original_docs - super().__init__(source_dir=source_dir) + super().__init__(source_dir=source_dir, config=config) self._html_theme = None @property diff --git a/ntd2d/ntd2d_action/files/conffile.py b/ntd2d/ntd2d_action/files/conffile.py index 8c1957e..791ba6b 100644 --- a/ntd2d/ntd2d_action/files/conffile.py +++ b/ntd2d/ntd2d_action/files/conffile.py @@ -22,23 +22,14 @@ def _working_directory(path): class ConfFile(File): """Sphinx configuration file.""" - def __init__(self, source_dir): + def __init__(self, source_dir, config): self.source_dir = pathlib.Path(source_dir) - self.theme = None + self.config = config self._code = None - self._configuration = None - - @property - def configuration(self): - """Text of configuration file.""" - - if self._configuration is None: - self._configuration = self.read() - return self._configuration @property def exclude_patterns(self): - return self.configuration.get("exclude_patterns", []) + return self.config.exclude_patterns @property def html_theme(self): @@ -46,7 +37,7 @@ def html_theme(self): .. _html_theme: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_theme """ - return self.configuration.get("html_theme", "default") + return self.config.html_theme @property def html_theme_path(self): @@ -54,7 +45,7 @@ def html_theme_path(self): .. _html_theme_path: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_theme_path """ - return self.configuration.get("html_theme_path", []) + return self.config.html_theme_path @property def language(self): @@ -62,7 +53,7 @@ def language(self): .. _language: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language """ - return self.configuration.get("language", "en") + return self.config.language @property def original_contents(self): @@ -82,7 +73,7 @@ def project(self): .. _project: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-project """ - return self.configuration["project"] + return self.config.project @property def theme_path(self): diff --git a/ntd2d/ntd2d_action/sphinxdocs.py b/ntd2d/ntd2d_action/sphinxdocs.py index 69661c7..bbb25e1 100644 --- a/ntd2d/ntd2d_action/sphinxdocs.py +++ b/ntd2d/ntd2d_action/sphinxdocs.py @@ -22,6 +22,7 @@ class SphinxDocs: """Sphinx configuration directory.""" def __init__(self, docs_dir): + self._app = None self.docs_dir = pathlib.Path(docs_dir) if (self.docs_dir / "source" / "conf.py").is_file(): @@ -34,7 +35,18 @@ def __init__(self, docs_dir): self.conf = self.make_conf_file() def make_conf_file(self): - return ConfFile(source_dir=self.source_dir) + return ConfFile(source_dir=self.source_dir, + config=self.sphinx_app.config) + + @property + def sphinx_app(self): + if self._app is None: + self._app = Sphinx(srcdir=self.source_dir, + confdir=self.source_dir, + outdir=self.build_dir, + doctreedir=self.build_dir / "doctrees", + buildername="html") + return self._app @property def html_dir(self): @@ -50,13 +62,8 @@ def pdf_file(self): @property def stylesheet(self): - app = Sphinx(srcdir=self.source_dir, - confdir=self.source_dir, - outdir=self.build_dir, - doctreedir=self.build_dir / "doctrees", - buildername="html") - theme_factory = HTMLThemeFactory(app) - theme = theme_factory.create(app.config.html_theme) + theme_factory = HTMLThemeFactory(self.sphinx_app) + theme = theme_factory.create(self.sphinx_app.config.html_theme) return theme.get_config("theme", "stylesheet") @@ -135,6 +142,7 @@ def __init__(self, original_docs): def make_conf_file(self): return BorgedConfFile(source_dir=self.source_dir, + config=self.sphinx_app.config, original_docs=self.original_docs) @property