Skip to content

Commit

Permalink
Docs: make external packages optional
Browse files Browse the repository at this point in the history
It was noted in #2155 that when packaging Freeciv21, sphinx_rtd_theme and
sphinx_last_updated_by_git were needed at build time to create the man pages.
The rtd theme is obviously only needed for HTML output and last_updated_by_git
doesn't seem to be used with the man pages. Make them both optional by checking
if they can be imported when evaluating the config.

This will allow package maintainers to ship man pages even when one of the two
packages are missing from their distribution.
  • Loading branch information
lmoureaux committed Jan 20, 2024
1 parent 9e1606e commit f53d414
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import sphinx_rtd_theme
try:
import sphinx_rtd_theme
has_theme = True
except ImportError:
has_theme = False

try:
import sphinx_last_updated_by_git
has_updated_by_git = True
except ImportError:
has_updated_by_git = False


# -- Project information -----------------------------------------------------
Expand Down Expand Up @@ -48,9 +58,11 @@
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.ifconfig',
'sphinx_rtd_theme',
'sphinx_last_updated_by_git',
]
if has_theme:
extensions.append('sphinx_rtd_theme')
if has_updated_by_git:
extensions.append('sphinx_last_updated_by_git')

# See https://github.com/readthedocs/recommonmark#linking-to-headings-in-other-files
autosectionlabel_prefix_document = True
Expand Down Expand Up @@ -95,16 +107,15 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
if has_theme:
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'style_external_links': True

}

# Add any paths that contain custom static files (such as style sheets) here,
Expand Down

0 comments on commit f53d414

Please sign in to comment.