Skip to content

Commit 3424ffe

Browse files
author
Release Manager
committed
sagemathgh-36495: Conditional documentation <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> Documentation is conditionalized by using Sphinx tags. Split out from (and preparation for): - sagemath#36380 Part of: - sagemath#29705 <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36495 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
2 parents ecbc7b6 + 4abc647 commit 3424ffe

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

src/doc/en/developer/packaging_sage_library.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,17 @@ requiring all of Sage to be present.
472472
mechanism mentioned above can also be used for this.
473473

474474

475+
Dependencies of the Sage documentation
476+
--------------------------------------
477+
478+
The documentation will not be modularized.
479+
480+
However, some parts of the Sage reference manual may depend on functionality
481+
provided by optional packages. These portions of the reference manual
482+
should be conditionalized using the Sphinx directive ``.. ONLY::``,
483+
as explained in :ref:`section-documentation-conditional`.
484+
485+
475486
Version constraints of dependencies
476487
-----------------------------------
477488

src/doc/en/developer/sage_manuals.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,32 @@ procedure is different:
166166
* Add your file to the index contained in
167167
``SAGE_ROOT/src/doc/en/reference/combinat/module_list.rst``.
168168

169+
.. _section-documentation-conditional:
170+
171+
Making portions of the reference manual conditional on optional features
172+
========================================================================
173+
174+
For every dynamically detectable feature such as :class:`graphviz
175+
<~sage.features.graphviz.Graphviz>` or :class:`sage.symbolic
176+
<sage.features.sagemath.sage__symbolic>` (see :mod:`sage.features`),
177+
Sage defines a Sphinx tag that can be used with the `Sphinx
178+
directive ".. ONLY::"
179+
<https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#tags>`_.
180+
Because Sphinx tags have to use Python identifier syntax, Sage uses
181+
the format ``feature_``, followed by the feature name where dots are
182+
replaced by underscores. Hence, conditionalizing on the features of
183+
the previous examples would look as follows:
184+
185+
.. CODE-BLOCK:: rest
186+
187+
.. ONLY:: feature_graphviz
188+
189+
and:
190+
191+
.. CODE-BLOCK:: rest
192+
193+
.. ONLY:: feature_sage_symbolic
194+
169195
.. _section-building-manuals:
170196

171197
Building the manuals

src/doc/en/reference/polynomial_rings/index.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ Infinite Polynomial Rings
6565
Boolean Polynomials
6666
-------------------
6767

68-
.. toctree::
69-
:maxdepth: 1
68+
.. ONLY:: feature_sage_rings_polynomial_pbori
69+
70+
.. toctree::
71+
:maxdepth: 1
7072

71-
sage/rings/polynomial/pbori/pbori
73+
sage/rings/polynomial/pbori/pbori
7274

7375
.. include:: ../footer.txt

src/sage_docbuild/conf.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from sage.env import SAGE_DOC_SRC, SAGE_DOC, THEBE_DIR, PPLPY_DOCS, MATHJAX_DIR
3434
from sage.misc.latex_macros import sage_mathjax_macros
3535
from sage.features import PythonModule
36+
from sage.features.all import all_features
3637

3738
# General configuration
3839
# ---------------------
@@ -940,3 +941,18 @@ def setup(app):
940941
app.connect('missing-reference', find_sage_dangling_links)
941942
app.connect('builder-inited', nitpick_patch_config)
942943
app.connect('html-page-context', add_page_context)
944+
945+
946+
# Conditional content
947+
# https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#tags
948+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#conf-tags
949+
# https://github.com/readthedocs/readthedocs.org/issues/4603#issuecomment-1411594800
950+
# Workaround to allow importing this file from other confs
951+
if 'tags' not in locals():
952+
class Tags(set):
953+
has = set.__contains__
954+
tags = Tags()
955+
956+
957+
for feature in all_features():
958+
tags.add('feature_' + feature.name.replace('.', '_'))

0 commit comments

Comments
 (0)