diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-11-15 23:40:49 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-11-21 00:32:36 +0900 |
commit | 1e700fa70cc71071aff5fa6b91911d57285c5f93 (patch) | |
tree | 717b4855c61390bcd407f4b5bf8a5dd9e78d0a77 /sphinx/config.py | |
parent | 5d2d4e04778c5cbdb89c29d62d5a30cc2c23e76d (diff) | |
download | sphinx-git-1e700fa70cc71071aff5fa6b91911d57285c5f93.tar.gz |
Add a handler to migrate master_doc from "contents" to "index"
Diffstat (limited to 'sphinx/config.py')
-rw-r--r-- | sphinx/config.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/sphinx/config.py b/sphinx/config.py index d64c049ad..2509e0b1b 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -29,8 +29,9 @@ from sphinx.util.pycompat import execfile_, NoneType if False: # For type annotation - from typing import Any, Callable, Dict, Generator, Iterator, List, Tuple, Union # NOQA + from typing import Any, Callable, Dict, Generator, Iterator, List, Set, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA + from sphinx.environment import BuildEnvironment # NOQA from sphinx.util.tags import Tags # NOQA logger = logging.getLogger(__name__) @@ -508,6 +509,21 @@ def check_primary_domain(app, config): config.primary_domain = None # type: ignore +def check_master_doc(app, env, added, changed, removed): + # type: (Sphinx, BuildEnvironment, Set[unicode], Set[unicode], Set[unicode]) -> Set[unicode] # NOQA + """Adjust master_doc to 'contents' to support an old project which does not have + no master_doc setting. + """ + if (app.config.master_doc == 'index' and + 'index' not in app.project.docnames and + 'contents' in app.project.docnames): + logger.warning(__('Since v2.0, Sphinx uses "index" as master_doc by default. ' + 'Please add "master_doc = \'contents\'" to your conf.py.')) + app.config.master_doc = "contents" # type: ignore + + return changed + + def setup(app): # type: (Sphinx) -> Dict[unicode, Any] app.connect('config-inited', convert_source_suffix) @@ -515,6 +531,7 @@ def setup(app): app.connect('config-inited', correct_copyright_year) app.connect('config-inited', check_confval_types) app.connect('config-inited', check_primary_domain) + app.connect('env-get-outdated', check_master_doc) return { 'version': 'builtin', |