Add Builder#get_asset_paths() to make less-coupling

This commit is contained in:
Takeshi KOMIYA 2017-03-20 01:20:19 +09:00
parent cd3f48bb76
commit b192b3271a
4 changed files with 15 additions and 6 deletions

View File

@ -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:

View File

@ -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):

View File

@ -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."""

View File

@ -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