From b192b3271a06e78bf82ee5b17fb5d8c783abd121 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 20 Mar 2017 01:20:19 +0900 Subject: [PATCH] Add Builder#get_asset_paths() to make less-coupling --- sphinx/application.py | 2 +- sphinx/builders/__init__.py | 5 +++++ sphinx/builders/html.py | 4 ++++ sphinx/environment/__init__.py | 10 +++++----- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/sphinx/application.py b/sphinx/application.py index 638bcdf49..6da8b44bc 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -291,7 +291,7 @@ class Sphinx(object): # type: (bool) -> None if freshenv: self.env = BuildEnvironment(self) - self.env.find_files(self.config, self.builder.name) + self.env.find_files(self.config, self.builder) for domain in self.domains.keys(): self.env.domains[domain] = self.domains[domain](self.env) else: diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 171246162..30c006c32 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -149,6 +149,11 @@ class Builder(object): """ raise NotImplementedError + def get_asset_paths(self): + # type: () -> List[unicode] + """Return list of paths for assets (ex. templates, CSS, etc.).""" + return [] + supported_image_types = [] # type: List[unicode] def post_process_images(self, doctree): diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 8d1c517ae..83c444b80 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -264,6 +264,10 @@ class StandaloneHTMLBuilder(Builder): # source doesn't exist anymore pass + def get_asset_paths(self): + # type: () -> List[unicode] + return self.config.html_extra_path + def render_partial(self, node): # type: (nodes.Nodes) -> Dict[unicode, unicode] """Utility: Render a lone doctree node.""" diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 03301d53c..92d270797 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -405,15 +405,15 @@ class BuildEnvironment(object): enc_rel_fn = rel_fn.encode(sys.getfilesystemencoding()) return rel_fn, path.abspath(path.join(self.srcdir, enc_rel_fn)) - def find_files(self, config, buildername): - # type: (Config, unicode) -> None + def find_files(self, config, builder): + # type: (Config, Builder) -> None """Find all source files in the source dir and put them in self.found_docs. """ matchers = compile_matchers( config.exclude_patterns[:] + config.templates_path + - config.html_extra_path + + builder.get_asset_paths() + ['**/_sources', '.#*', '**/.#*', '*.lproj/**'] ) self.found_docs = set() @@ -430,7 +430,7 @@ class BuildEnvironment(object): # is set for the doc source and the mo file, it is processed again from # the reading phase when mo is updated. In the future, we would like to # move i18n process into the writing phase, and remove these lines. - if buildername != 'gettext': + if builder.name != 'gettext': # add catalog mo file dependency for docname in self.found_docs: catalog_files = find_catalog_files( @@ -522,7 +522,7 @@ class BuildEnvironment(object): # the source and doctree directories may have been relocated self.srcdir = srcdir self.doctreedir = doctreedir - self.find_files(config, self.app.buildername) + self.find_files(config, self.app.builder) self.config = config # this cache also needs to be updated every time