summaryrefslogtreecommitdiff
path: root/sphinx/builders/html.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-06-18 01:20:12 +0900
committerGitHub <noreply@github.com>2019-06-18 01:20:12 +0900
commit3047bd211ff3de173d7af817d84118c8ad776772 (patch)
tree32b0e2b3242464e9d559d4149899ea318ef5d2ae /sphinx/builders/html.py
parent9314e5c38cf3ab235bd8ef446e17ea9e7d2d2562 (diff)
parentfe0f83daf8f00a2838711d988cb6bd1a89242a20 (diff)
downloadsphinx-git-3047bd211ff3de173d7af817d84118c8ad776772.tar.gz
Merge pull request #6496 from tk0miya/refactor_html_builder2
Refactor html builder: validate config values on config-inited event
Diffstat (limited to 'sphinx/builders/html.py')
-rw-r--r--sphinx/builders/html.py50
1 files changed, 36 insertions, 14 deletions
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 1fd9e6cac..c8d330d2d 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -783,27 +783,19 @@ class StandaloneHTMLBuilder(Builder):
excluded = Matcher(self.config.exclude_patterns + ["**/.*"])
for static_path in self.config.html_static_path:
entry = path.join(self.confdir, static_path)
- if not path.exists(entry):
- logger.warning(__('html_static_path entry %r does not exist'), entry)
- continue
copy_asset(entry, path.join(self.outdir, '_static'), excluded,
context=ctx, renderer=self.templates)
# copy logo and favicon files if not already in static path
if self.config.html_logo:
logobase = path.basename(self.config.html_logo)
logotarget = path.join(self.outdir, '_static', logobase)
- if not path.isfile(path.join(self.confdir, self.config.html_logo)):
- logger.warning(__('logo file %r does not exist'), self.config.html_logo)
- elif not path.isfile(logotarget):
+ if not path.isfile(logotarget):
copyfile(path.join(self.confdir, self.config.html_logo),
logotarget)
if self.config.html_favicon:
iconbase = path.basename(self.config.html_favicon)
icontarget = path.join(self.outdir, '_static', iconbase)
- if not path.isfile(path.join(self.confdir, self.config.html_favicon)):
- logger.warning(__('favicon file %r does not exist'),
- self.config.html_favicon)
- elif not path.isfile(icontarget):
+ if not path.isfile(icontarget):
copyfile(path.join(self.confdir, self.config.html_favicon),
icontarget)
logger.info(__('done'))
@@ -818,10 +810,6 @@ class StandaloneHTMLBuilder(Builder):
for extra_path in self.config.html_extra_path:
entry = path.join(self.confdir, extra_path)
- if not path.exists(entry):
- logger.warning(__('html_extra_path entry %r does not exist'), entry)
- continue
-
copy_asset(entry, self.outdir, excluded)
logger.info(__('done'))
except OSError as err:
@@ -1166,6 +1154,36 @@ def validate_math_renderer(app: Sphinx) -> None:
raise ConfigError(__('Unknown math_renderer %r is given.') % name)
+def validate_html_extra_path(app: Sphinx, config: Config) -> None:
+ """Check html_extra_paths setting."""
+ for entry in config.html_extra_path[:]:
+ if not path.exists(path.join(app.confdir, entry)):
+ logger.warning(__('html_extra_path entry %r does not exist'), entry)
+ config.html_extra_path.remove(entry)
+
+
+def validate_html_static_path(app: Sphinx, config: Config) -> None:
+ """Check html_static_paths setting."""
+ for entry in config.html_static_path[:]:
+ if not path.exists(path.join(app.confdir, entry)):
+ logger.warning(__('html_static_path entry %r does not exist'), entry)
+ config.html_static_path.remove(entry)
+
+
+def validate_html_logo(app: Sphinx, config: Config) -> None:
+ """Check html_logo setting."""
+ if config.html_logo and not path.isfile(path.join(app.confdir, config.html_logo)):
+ logger.warning(__('logo file %r does not exist'), config.html_logo)
+ config.html_logo = None # type: ignore
+
+
+def validate_html_favicon(app: Sphinx, config: Config) -> None:
+ """Check html_favicon setting."""
+ if config.html_favicon and not path.isfile(path.join(app.confdir, config.html_favicon)):
+ logger.warning(__('favicon file %r does not exist'), config.html_favicon)
+ config.html_favicon = None # type: ignore
+
+
# for compatibility
import sphinx.builders.dirhtml # NOQA
import sphinx.builders.singlehtml # NOQA
@@ -1221,6 +1239,10 @@ def setup(app: Sphinx) -> Dict[str, Any]:
# event handlers
app.connect('config-inited', convert_html_css_files)
app.connect('config-inited', convert_html_js_files)
+ app.connect('config-inited', validate_html_extra_path)
+ app.connect('config-inited', validate_html_static_path)
+ app.connect('config-inited', validate_html_logo)
+ app.connect('config-inited', validate_html_favicon)
app.connect('builder-inited', validate_math_renderer)
app.connect('html-page-context', setup_js_tag_helper)