diff --git a/CHANGES b/CHANGES index c501a879d..cd23f04e3 100644 --- a/CHANGES +++ b/CHANGES @@ -33,6 +33,7 @@ Bugs fixed * #4209: intersphinx: In link title, "v" should be optional if target has no version * #4230: slowdown in writing pages with sphinx 1.6 +* #4522: epub: document is not rebuilt even if config changed Testing -------- diff --git a/sphinx/builders/_epub_base.py b/sphinx/builders/_epub_base.py index a110a873e..d44e7f2be 100644 --- a/sphinx/builders/_epub_base.py +++ b/sphinx/builders/_epub_base.py @@ -19,7 +19,7 @@ from docutils import nodes from docutils.utils import smartquotes from sphinx import addnodes -from sphinx.builders.html import StandaloneHTMLBuilder +from sphinx.builders.html import BuildInfo, StandaloneHTMLBuilder from sphinx.util import logging from sphinx.util import status_iterator from sphinx.util.fileutil import copy_asset_file @@ -159,6 +159,10 @@ class EpubBuilder(StandaloneHTMLBuilder): self.id_cache = {} # type: Dict[unicode, unicode] self.use_index = self.get_builder_config('use_index', 'epub') + def create_build_info(self): + # type: () -> BuildInfo + return BuildInfo(self.config, self.tags, ['html', 'epub']) + def get_theme_config(self): # type: () -> Tuple[unicode, Dict] return self.config.epub_theme, self.config.epub_theme_options diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index 7b4dcaf37..bb18e9c9b 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -228,15 +228,15 @@ def setup(app): # config values app.add_config_value('epub_basename', lambda self: make_filename(self.project), None) - app.add_config_value('epub_theme', 'epub', 'html') - app.add_config_value('epub_theme_options', {}, 'html') - app.add_config_value('epub_title', lambda self: self.html_title, 'html') - app.add_config_value('epub_author', 'unknown', 'html') - app.add_config_value('epub_language', lambda self: self.language or 'en', 'html') - app.add_config_value('epub_publisher', 'unknown', 'html') - app.add_config_value('epub_copyright', lambda self: self.copyright, 'html') - app.add_config_value('epub_identifier', 'unknown', 'html') - app.add_config_value('epub_scheme', 'unknown', 'html') + app.add_config_value('epub_theme', 'epub', 'epub') + app.add_config_value('epub_theme_options', {}, 'epub') + app.add_config_value('epub_title', lambda self: self.html_title, 'epub') + app.add_config_value('epub_author', 'unknown', 'epub') + app.add_config_value('epub_language', lambda self: self.language or 'en', 'epub') + app.add_config_value('epub_publisher', 'unknown', 'epub') + app.add_config_value('epub_copyright', lambda self: self.copyright, 'epub') + app.add_config_value('epub_identifier', 'unknown', 'epub') + app.add_config_value('epub_scheme', 'unknown', 'epub') app.add_config_value('epub_uid', 'unknown', 'env') app.add_config_value('epub_cover', (), 'env') app.add_config_value('epub_guide', (), 'env') @@ -248,8 +248,8 @@ def setup(app): app.add_config_value('epub_tocscope', 'default', 'env') app.add_config_value('epub_fix_images', False, 'env') app.add_config_value('epub_max_image_width', 0, 'env') - app.add_config_value('epub_show_urls', 'inline', 'html') - app.add_config_value('epub_use_index', lambda self: self.html_use_index, 'html') + app.add_config_value('epub_show_urls', 'inline', 'epub') + app.add_config_value('epub_use_index', lambda self: self.html_use_index, 'epub') app.add_config_value('epub_description', 'unknown', 'epub', string_classes) app.add_config_value('epub_contributor', 'unknown', 'epub', string_classes) app.add_config_value('epub_writing_mode', 'horizontal', 'epub', diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index bb6818af7..e2f3909cc 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -171,13 +171,13 @@ class BuildInfo(object): except Exception as exc: raise ValueError('build info file is broken: %r' % exc) - def __init__(self, config=None, tags=None): - # type: (Config, Tags) -> None + def __init__(self, config=None, tags=None, config_categories=[]): + # type: (Config, Tags, List[unicode]) -> None self.config_hash = u'' self.tags_hash = u'' if config: - values = dict((c.name, c.value) for c in config.filter('html')) + values = dict((c.name, c.value) for c in config.filter(config_categories)) self.config_hash = get_stable_hash(values) if tags: @@ -246,7 +246,7 @@ class StandaloneHTMLBuilder(Builder): def init(self): # type: () -> None - self.build_info = BuildInfo(self.config, self.tags) + self.build_info = self.create_build_info() # basename of images directory self.imagedir = '_images' # section numbers for headings in the currently visited document @@ -274,6 +274,10 @@ class StandaloneHTMLBuilder(Builder): 'is old. Docutils\' version should be 0.13 or newer, but %s.') % docutils.__version__) + def create_build_info(self): + # type: () -> BuildInfo + return BuildInfo(self.config, self.tags, ['html']) + def _get_translations_js(self): # type: () -> unicode candidates = [path.join(dir, self.config.language, diff --git a/sphinx/config.py b/sphinx/config.py index e4dee0756..1f80ab366 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -342,5 +342,7 @@ class Config(object): self.values[name] = (default, rebuild, types) def filter(self, rebuild): - # type: (str) -> Iterator[ConfigValue] - return (value for value in self if value.rebuild == rebuild) # type: ignore + # type: (Union[unicode, List[unicode]]) -> Iterator[ConfigValue] + if isinstance(rebuild, string_types): + rebuild = [rebuild] + return (value for value in self if value.rebuild in rebuild) # type: ignore