Skip to content

Commit

Permalink
Use configuration from Sphinx object
Browse files Browse the repository at this point in the history
  • Loading branch information
guyer committed Oct 5, 2023
1 parent 1706c8f commit 3038c8c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ntd2d/ntd2d_action/files/borgedconffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 7 additions & 16 deletions ntd2d/ntd2d_action/files/conffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,38 @@ 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):
"""html_theme_ Sphinx configuration value.
.. _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):
"""html_theme_path_ Sphinx configuration value.
.. _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):
"""language_ Sphinx configuration value.
.. _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):
Expand All @@ -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):
Expand Down
24 changes: 16 additions & 8 deletions ntd2d/ntd2d_action/sphinxdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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):
Expand All @@ -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")

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3038c8c

Please sign in to comment.