mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #5909 from tk0miya/refactor_epub2
refactor: Convert Epub3Builder.validate_config_values() to a function
This commit is contained in:
commit
8b6acc05c4
1
CHANGES
1
CHANGES
@ -75,6 +75,7 @@ Deprecated
|
|||||||
``IndexBuilder.feed()`` method is deprecated.
|
``IndexBuilder.feed()`` method is deprecated.
|
||||||
* ``sphinx.addnodes.abbreviation``
|
* ``sphinx.addnodes.abbreviation``
|
||||||
* ``sphinx.application.Sphinx._setting_up_extension``
|
* ``sphinx.application.Sphinx._setting_up_extension``
|
||||||
|
* ``sphinx.builders.epub3.Epub3Builder.validate_config_value()``
|
||||||
* ``sphinx.builders.htmlhelp.HTMLHelpBuilder.open_file()``
|
* ``sphinx.builders.htmlhelp.HTMLHelpBuilder.open_file()``
|
||||||
* ``sphinx.cmd.quickstart.term_decode()``
|
* ``sphinx.cmd.quickstart.term_decode()``
|
||||||
* ``sphinx.cmd.quickstart.TERM_ENCODING``
|
* ``sphinx.cmd.quickstart.TERM_ENCODING``
|
||||||
|
@ -275,6 +275,11 @@ The following is a list of deprecated interfaces.
|
|||||||
- 4.0
|
- 4.0
|
||||||
- ``docutils.nodes.abbreviation``
|
- ``docutils.nodes.abbreviation``
|
||||||
|
|
||||||
|
* - ``sphinx.builders.epub3.Epub3Builder.validate_config_value()``
|
||||||
|
- 2.0
|
||||||
|
- 4.0
|
||||||
|
- ``sphinx.builders.epub3.validate_config_values()``
|
||||||
|
|
||||||
* - ``sphinx.builders.htmlhelp.HTMLHelpBuilder.open_file()``
|
* - ``sphinx.builders.htmlhelp.HTMLHelpBuilder.open_file()``
|
||||||
- 2.0
|
- 2.0
|
||||||
- 4.0
|
- 4.0
|
||||||
|
@ -78,7 +78,6 @@ class Epub3Builder(_epub_base.EpubBuilder):
|
|||||||
def handle_finish(self):
|
def handle_finish(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
"""Create the metainfo files and finally the epub."""
|
"""Create the metainfo files and finally the epub."""
|
||||||
self.validate_config_value()
|
|
||||||
self.get_toc()
|
self.get_toc()
|
||||||
self.build_mimetype()
|
self.build_mimetype()
|
||||||
self.build_container()
|
self.build_container()
|
||||||
@ -89,39 +88,8 @@ class Epub3Builder(_epub_base.EpubBuilder):
|
|||||||
|
|
||||||
def validate_config_value(self):
|
def validate_config_value(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
# <package> lang attribute, dc:language
|
warnings.warn('Epub3Builder.validate_config_value() is deprecated.',
|
||||||
if not self.app.config.epub_language:
|
RemovedInSphinx40Warning, stacklevel=2)
|
||||||
logger.warning(__('conf value "epub_language" (or "language") '
|
|
||||||
'should not be empty for EPUB3'))
|
|
||||||
# <package> unique-identifier attribute
|
|
||||||
if not xmlname_checker().match(self.app.config.epub_uid):
|
|
||||||
logger.warning(__('conf value "epub_uid" should be XML NAME for EPUB3'))
|
|
||||||
# dc:title
|
|
||||||
if not self.app.config.epub_title:
|
|
||||||
logger.warning(__('conf value "epub_title" (or "html_title") '
|
|
||||||
'should not be empty for EPUB3'))
|
|
||||||
# dc:creator
|
|
||||||
if not self.app.config.epub_author:
|
|
||||||
logger.warning(__('conf value "epub_author" should not be empty for EPUB3'))
|
|
||||||
# dc:contributor
|
|
||||||
if not self.app.config.epub_contributor:
|
|
||||||
logger.warning(__('conf value "epub_contributor" should not be empty for EPUB3'))
|
|
||||||
# dc:description
|
|
||||||
if not self.app.config.epub_description:
|
|
||||||
logger.warning(__('conf value "epub_description" should not be empty for EPUB3'))
|
|
||||||
# dc:publisher
|
|
||||||
if not self.app.config.epub_publisher:
|
|
||||||
logger.warning(__('conf value "epub_publisher" should not be empty for EPUB3'))
|
|
||||||
# dc:rights
|
|
||||||
if not self.app.config.epub_copyright:
|
|
||||||
logger.warning(__('conf value "epub_copyright" (or "copyright")'
|
|
||||||
'should not be empty for EPUB3'))
|
|
||||||
# dc:identifier
|
|
||||||
if not self.app.config.epub_identifier:
|
|
||||||
logger.warning(__('conf value "epub_identifier" should not be empty for EPUB3'))
|
|
||||||
# meta ibooks:version
|
|
||||||
if not self.app.config.version:
|
|
||||||
logger.warning(__('conf value "version" should not be empty for EPUB3'))
|
|
||||||
|
|
||||||
def content_metadata(self):
|
def content_metadata(self):
|
||||||
# type: () -> Dict
|
# type: () -> Dict
|
||||||
@ -234,6 +202,46 @@ class Epub3Builder(_epub_base.EpubBuilder):
|
|||||||
self.files.append(outname)
|
self.files.append(outname)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_config_values(app):
|
||||||
|
# type: (Sphinx) -> None
|
||||||
|
if app.builder.name != 'epub':
|
||||||
|
return
|
||||||
|
|
||||||
|
# <package> lang attribute, dc:language
|
||||||
|
if not app.config.epub_language:
|
||||||
|
logger.warning(__('conf value "epub_language" (or "language") '
|
||||||
|
'should not be empty for EPUB3'))
|
||||||
|
# <package> unique-identifier attribute
|
||||||
|
if not xmlname_checker().match(app.config.epub_uid):
|
||||||
|
logger.warning(__('conf value "epub_uid" should be XML NAME for EPUB3'))
|
||||||
|
# dc:title
|
||||||
|
if not app.config.epub_title:
|
||||||
|
logger.warning(__('conf value "epub_title" (or "html_title") '
|
||||||
|
'should not be empty for EPUB3'))
|
||||||
|
# dc:creator
|
||||||
|
if not app.config.epub_author:
|
||||||
|
logger.warning(__('conf value "epub_author" should not be empty for EPUB3'))
|
||||||
|
# dc:contributor
|
||||||
|
if not app.config.epub_contributor:
|
||||||
|
logger.warning(__('conf value "epub_contributor" should not be empty for EPUB3'))
|
||||||
|
# dc:description
|
||||||
|
if not app.config.epub_description:
|
||||||
|
logger.warning(__('conf value "epub_description" should not be empty for EPUB3'))
|
||||||
|
# dc:publisher
|
||||||
|
if not app.config.epub_publisher:
|
||||||
|
logger.warning(__('conf value "epub_publisher" should not be empty for EPUB3'))
|
||||||
|
# dc:rights
|
||||||
|
if not app.config.epub_copyright:
|
||||||
|
logger.warning(__('conf value "epub_copyright" (or "copyright")'
|
||||||
|
'should not be empty for EPUB3'))
|
||||||
|
# dc:identifier
|
||||||
|
if not app.config.epub_identifier:
|
||||||
|
logger.warning(__('conf value "epub_identifier" should not be empty for EPUB3'))
|
||||||
|
# meta ibooks:version
|
||||||
|
if not app.config.version:
|
||||||
|
logger.warning(__('conf value "version" should not be empty for EPUB3'))
|
||||||
|
|
||||||
|
|
||||||
def convert_epub_css_files(app, config):
|
def convert_epub_css_files(app, config):
|
||||||
# type: (Sphinx, Config) -> None
|
# type: (Sphinx, Config) -> None
|
||||||
"""This converts string styled epub_css_files to tuple styled one."""
|
"""This converts string styled epub_css_files to tuple styled one."""
|
||||||
@ -289,6 +297,7 @@ def setup(app):
|
|||||||
|
|
||||||
# event handlers
|
# event handlers
|
||||||
app.connect('config-inited', convert_epub_css_files)
|
app.connect('config-inited', convert_epub_css_files)
|
||||||
|
app.connect('builder-inited', validate_config_values)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'version': 'builtin',
|
'version': 'builtin',
|
||||||
|
Loading…
Reference in New Issue
Block a user