From 65750f4e20cb3573ac51aa7a30e6e977ef67743d Mon Sep 17 00:00:00 2001 From: Christer van der Meeren Date: Tue, 9 Jun 2015 14:59:24 +0200 Subject: [PATCH 1/2] add option to use sphinx readthedocs theme locally --- CHANGELOG.rst | 1 + README.rst | 5 +++++ ci/setup.cfg | 3 +++ cookiecutter.json | 1 + {{cookiecutter.repo_name}}/docs/conf.py | 16 +++++++++++++--- {{cookiecutter.repo_name}}/docs/requirements.txt | 4 ++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6e1367ce..455c6fb7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,7 @@ v1.5 (??????????) * Made support and badges for landscape, scrutinizer, coveralls and codecov switchable at project creation time. * Disabled all the pypip.in badges (server has way too much downtime). * A fix for a whitespace issue in outputed ``tox.ini``. +* Add option to use Read The Docs theme when building docs locally. v1.4 (2015-06-05) ----------------- diff --git a/README.rst b/README.rst index c81ac700..3b881825 100644 --- a/README.rst +++ b/README.rst @@ -158,6 +158,11 @@ You will be asked for these fields: "no" - Add a Scrutinizer_ badge in ``README.rst``. + * - ``rtd_theme`` + - .. code:: python + + "no" + - Whether to use the Read The Docs theme when building docs locally. The testing (``tox.ini`` and ``.travis.yml``) configuration is generated from templates. For your convenience there's an initial bootstrap ``tox.ini``, to get the initial generation going just run:: diff --git a/ci/setup.cfg b/ci/setup.cfg index 72a9bbdc..0595e812 100644 --- a/ci/setup.cfg +++ b/ci/setup.cfg @@ -27,3 +27,6 @@ command_line_interface = click &project_name[-] &full_name[-] plain &project_name[-] &full_name[-] no +rtd_theme = + yes + no diff --git a/cookiecutter.json b/cookiecutter.json index 15678c9f..4dec49d2 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -20,4 +20,5 @@ "codecov": "yes", "landscape": "no", "scrutinizer": "no" + "rtd_theme": "no" } diff --git a/{{cookiecutter.repo_name}}/docs/conf.py b/{{cookiecutter.repo_name}}/docs/conf.py index edcba0ac..61a4c7a1 100644 --- a/{{cookiecutter.repo_name}}/docs/conf.py +++ b/{{cookiecutter.repo_name}}/docs/conf.py @@ -26,9 +26,22 @@ copyright = '{0}, {1}'.format(year, author) version = release = {{ '{0!r}'.format(cookiecutter.version) }} +{%- if cookiecutter.rtd_theme|lower == 'no' %} import sphinx_py3doc_enhanced_theme html_theme = "sphinx_py3doc_enhanced_theme" html_theme_path = [sphinx_py3doc_enhanced_theme.get_html_theme_path()] +html_theme_options = { + 'githuburl': 'https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.repo_name }}/' +} +{%- else %} +# on_rtd is whether we are on readthedocs.org +on_rtd = os.environ.get('READTHEDOCS', None) == 'True' + +if not on_rtd: # only import and set the theme if we're building docs locally + import sphinx_rtd_theme + html_theme = 'sphinx_rtd_theme' + html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] +{%- endif %} pygments_style = 'trac' templates_path = ['.'] @@ -39,6 +52,3 @@ '**': ['searchbox.html', 'globaltoc.html', 'sourcelink.html'], } html_short_title = '%s-%s' % (project, version) -html_theme_options = { - 'githuburl': 'https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.repo_name }}/' -} diff --git a/{{cookiecutter.repo_name}}/docs/requirements.txt b/{{cookiecutter.repo_name}}/docs/requirements.txt index 1632a968..78cfdd5d 100644 --- a/{{cookiecutter.repo_name}}/docs/requirements.txt +++ b/{{cookiecutter.repo_name}}/docs/requirements.txt @@ -1,4 +1,8 @@ sphinx sphinxcontrib-napoleon +{%- if cookiecutter.rtd_theme|lower == 'no' %} sphinx-py3doc-enhanced-theme +{%- else %} +sphinx_rtd_theme +{%- endif %} -e . From ae1205412c9380f670cc2b549e0b32a1263d579a Mon Sep 17 00:00:00 2001 From: Christer van der Meeren Date: Tue, 9 Jun 2015 15:04:50 +0200 Subject: [PATCH 2/2] tiny bugfix --- cookiecutter.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookiecutter.json b/cookiecutter.json index 4dec49d2..45577af1 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -19,6 +19,6 @@ "coveralls": "no", "codecov": "yes", "landscape": "no", - "scrutinizer": "no" + "scrutinizer": "no", "rtd_theme": "no" }