Merge pull request #4530 from tk0miya/4522_epub_rebuild

Fix #4522: epub: document is not rebuilt even if config changed
This commit is contained in:
Takeshi KOMIYA 2018-01-31 22:21:52 +09:00 committed by GitHub
commit e0daaf3975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 18 deletions

View File

@ -33,6 +33,7 @@ Bugs fixed
* #4209: intersphinx: In link title, "v" should be optional if target has no * #4209: intersphinx: In link title, "v" should be optional if target has no
version version
* #4230: slowdown in writing pages with sphinx 1.6 * #4230: slowdown in writing pages with sphinx 1.6
* #4522: epub: document is not rebuilt even if config changed
Testing Testing
-------- --------

View File

@ -19,7 +19,7 @@ from docutils import nodes
from docutils.utils import smartquotes from docutils.utils import smartquotes
from sphinx import addnodes 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 logging
from sphinx.util import status_iterator from sphinx.util import status_iterator
from sphinx.util.fileutil import copy_asset_file from sphinx.util.fileutil import copy_asset_file
@ -159,6 +159,10 @@ class EpubBuilder(StandaloneHTMLBuilder):
self.id_cache = {} # type: Dict[unicode, unicode] self.id_cache = {} # type: Dict[unicode, unicode]
self.use_index = self.get_builder_config('use_index', 'epub') 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): def get_theme_config(self):
# type: () -> Tuple[unicode, Dict] # type: () -> Tuple[unicode, Dict]
return self.config.epub_theme, self.config.epub_theme_options return self.config.epub_theme, self.config.epub_theme_options

View File

@ -228,15 +228,15 @@ def setup(app):
# config values # config values
app.add_config_value('epub_basename', lambda self: make_filename(self.project), None) 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', 'epub', 'epub')
app.add_config_value('epub_theme_options', {}, 'html') app.add_config_value('epub_theme_options', {}, 'epub')
app.add_config_value('epub_title', lambda self: self.html_title, 'html') app.add_config_value('epub_title', lambda self: self.html_title, 'epub')
app.add_config_value('epub_author', 'unknown', 'html') app.add_config_value('epub_author', 'unknown', 'epub')
app.add_config_value('epub_language', lambda self: self.language or 'en', 'html') app.add_config_value('epub_language', lambda self: self.language or 'en', 'epub')
app.add_config_value('epub_publisher', 'unknown', 'html') app.add_config_value('epub_publisher', 'unknown', 'epub')
app.add_config_value('epub_copyright', lambda self: self.copyright, 'html') app.add_config_value('epub_copyright', lambda self: self.copyright, 'epub')
app.add_config_value('epub_identifier', 'unknown', 'html') app.add_config_value('epub_identifier', 'unknown', 'epub')
app.add_config_value('epub_scheme', 'unknown', 'html') app.add_config_value('epub_scheme', 'unknown', 'epub')
app.add_config_value('epub_uid', 'unknown', 'env') app.add_config_value('epub_uid', 'unknown', 'env')
app.add_config_value('epub_cover', (), 'env') app.add_config_value('epub_cover', (), 'env')
app.add_config_value('epub_guide', (), '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_tocscope', 'default', 'env')
app.add_config_value('epub_fix_images', False, '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_max_image_width', 0, 'env')
app.add_config_value('epub_show_urls', 'inline', 'html') app.add_config_value('epub_show_urls', 'inline', 'epub')
app.add_config_value('epub_use_index', lambda self: self.html_use_index, 'html') 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_description', 'unknown', 'epub', string_classes)
app.add_config_value('epub_contributor', 'unknown', 'epub', string_classes) app.add_config_value('epub_contributor', 'unknown', 'epub', string_classes)
app.add_config_value('epub_writing_mode', 'horizontal', 'epub', app.add_config_value('epub_writing_mode', 'horizontal', 'epub',

View File

@ -171,13 +171,13 @@ class BuildInfo(object):
except Exception as exc: except Exception as exc:
raise ValueError('build info file is broken: %r' % exc) raise ValueError('build info file is broken: %r' % exc)
def __init__(self, config=None, tags=None): def __init__(self, config=None, tags=None, config_categories=[]):
# type: (Config, Tags) -> None # type: (Config, Tags, List[unicode]) -> None
self.config_hash = u'' self.config_hash = u''
self.tags_hash = u'' self.tags_hash = u''
if config: 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) self.config_hash = get_stable_hash(values)
if tags: if tags:
@ -246,7 +246,7 @@ class StandaloneHTMLBuilder(Builder):
def init(self): def init(self):
# type: () -> None # type: () -> None
self.build_info = BuildInfo(self.config, self.tags) self.build_info = self.create_build_info()
# basename of images directory # basename of images directory
self.imagedir = '_images' self.imagedir = '_images'
# section numbers for headings in the currently visited document # 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.') % 'is old. Docutils\' version should be 0.13 or newer, but %s.') %
docutils.__version__) docutils.__version__)
def create_build_info(self):
# type: () -> BuildInfo
return BuildInfo(self.config, self.tags, ['html'])
def _get_translations_js(self): def _get_translations_js(self):
# type: () -> unicode # type: () -> unicode
candidates = [path.join(dir, self.config.language, candidates = [path.join(dir, self.config.language,

View File

@ -342,5 +342,7 @@ class Config(object):
self.values[name] = (default, rebuild, types) self.values[name] = (default, rebuild, types)
def filter(self, rebuild): def filter(self, rebuild):
# type: (str) -> Iterator[ConfigValue] # type: (Union[unicode, List[unicode]]) -> Iterator[ConfigValue]
return (value for value in self if value.rebuild == rebuild) # type: ignore if isinstance(rebuild, string_types):
rebuild = [rebuild]
return (value for value in self if value.rebuild in rebuild) # type: ignore