From 285ae7e881c31043592c8aeb62770ac362d57098 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 16 Jun 2018 00:51:21 +0900 Subject: [PATCH 1/6] Fix #5066: html: "relations" sidebar is not shown by default --- CHANGES | 1 + sphinx/builders/html.py | 22 +++++++++++++++------- tests/test_build_html.py | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index 2074d06ea..2d896a3e8 100644 --- a/CHANGES +++ b/CHANGES @@ -29,6 +29,7 @@ Bugs fixed * #5019: autodoc: crashed by Form Feed Character * #5032: autodoc: loses the first staticmethod parameter for old styled classes * #5036: quickstart: Typing Ctrl-U clears the whole of line +* #5066: html: "relations" sidebar is not shown by default Testing -------- diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index fad49486b..f43ac0e4f 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -906,19 +906,27 @@ class StandaloneHTMLBuilder(Builder): def has_wildcard(pattern): # type: (unicode) -> bool return any(char in pattern for char in '*?[') - sidebars = self.theme.get_config('theme', 'sidebars', None) + sidebars = None matched = None customsidebar = None # default sidebars settings for selected theme - theme_default_sidebars = self.theme.get_config('theme', 'sidebars', None) - if theme_default_sidebars: - sidebars = [name.strip() for name in theme_default_sidebars.split(',')] - elif self.theme.name == 'alabaster': + if self.theme.name == 'alabaster': # provide default settings for alabaster (for compatibility) # Note: this will be removed before Sphinx-2.0 - sidebars = ['about.html', 'navigation.html', 'relation.html', - 'searchbox.html', 'donate.html'] + try: + # get default sidebars settings from alabaster (if defined) + theme_default_sidebars = self.theme.config.get('theme', 'sidebars') + if theme_default_sidebars: + sidebars = [name.strip() for name in theme_default_sidebars.split(',')] + except Exception: + # fallback to better default settings + sidebars = ['about.html', 'navigation.html', 'relations.html', + 'searchbox.html', 'donate.html'] + else: + theme_default_sidebars = self.theme.get_config('theme', 'sidebars', None) + if theme_default_sidebars: + sidebars = [name.strip() for name in theme_default_sidebars.split(',')] # user sidebar settings for pattern, patsidebars in iteritems(self.config.html_sidebars): diff --git a/tests/test_build_html.py b/tests/test_build_html.py index bbfd0bc90..fd599c703 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -1230,21 +1230,50 @@ def test_html_remote_images(app, status, warning): @pytest.mark.sphinx('html', testroot='basic') def test_html_sidebar(app, status, warning): + ctx = {} + + # default for alabaster app.builder.build_all() result = (app.outdir / 'index.html').text(encoding='utf8') - assert '

Table Of Contents

' in result + assert ('