Skip to content

Commit

Permalink
antsibull-docs sphinx-init: allow to select other theme (ansible-comm…
Browse files Browse the repository at this point in the history
…unity#392)

* Make sphinx theme configurable internally.

* Expose command line option to choose Sphinx theme.

* Use other theme in one of the tests.

* Add changelog fragment.

* Use correct markup.
  • Loading branch information
felixfontein authored Jan 26, 2022
1 parent 5023129 commit 6fb73df
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/antsibull-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
options:
- '--use-current'
- '--use-current --sphinx-theme sphinx_rtd_theme'
- '--use-current --use-html-blobs --no-breadcrumbs community.crypto community.docker'
# The following should be run without `--use-current` and with `--collection-version 2.0.0`,
# but that isn't implemented yet:
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/392-sphinx-init-theme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "Allow to select a different Sphinx theme for ``antsibull-docs sphinx-init`` with the new ``--sphinx-theme`` option (https://github.com/ansible-community/antsibull/pull/392)."
2 changes: 2 additions & 0 deletions src/antsibull/cli/antsibull_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ def parse_args(program_name: str, args: List[str]) -> argparse.Namespace:
' one collection specified.')
sphinx_init_parser.add_argument('--lenient', action='store_true',
help='Configure Sphinx to not be too strict.')
sphinx_init_parser.add_argument('--sphinx-theme', default='sphinx-ansible-theme',
help='Configure the Sphinx theme to use.')
sphinx_init_parser.add_argument(nargs='*', dest='collections',
help='One or more collections to document. If the names are'
' directories on disk, they will be parsed as expanded'
Expand Down
8 changes: 8 additions & 0 deletions src/antsibull/cli/doc_commands/sphinx_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def site_init() -> int:
breadcrumbs = app_ctx.breadcrumbs
indexes = app_ctx.indexes

sphinx_theme = 'sphinx_ansible_theme'
sphinx_theme_package = 'sphinx-ansible-theme >= 0.9.0'
if app_ctx.extra['sphinx_theme'] != 'sphinx-ansible-theme':
sphinx_theme = app_ctx.extra['sphinx_theme']
sphinx_theme_package = app_ctx.extra['sphinx_theme']

env = doc_environment(('antsibull.data', 'sphinx_init'))

for filename in TEMPLATES:
Expand All @@ -80,6 +86,8 @@ def site_init() -> int:
use_html_blobs=use_html_blobs,
breadcrumbs=breadcrumbs,
indexes=indexes,
sphinx_theme=sphinx_theme,
sphinx_theme_package=sphinx_theme_package,
) + '\n'

destination = os.path.join(dest_dir, filename)
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull/data/sphinx_init/conf_py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pygments_style = 'ansible'

highlight_language = 'YAML+Jinja'

html_theme = 'sphinx_ansible_theme'
html_theme = '@{ sphinx_theme }@'
html_show_sphinx = False

display_version = False
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull/data/sphinx_init/requirements_txt.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
antsibull >= 0.40.0
ansible-pygments
sphinx
sphinx-ansible-theme >= 0.9.0
@{ sphinx_theme_package }@

0 comments on commit 6fb73df

Please sign in to comment.