Skip to content

Commit 26dca91

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 2c7b52e + 4abc647 commit 26dca91

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

src/doc/en/developer/packaging_sage_library.rst

+11
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

+26
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

+5-3
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

+16
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from sage.env import SAGE_DOC_SRC, SAGE_DOC, PPLPY_DOCS, MATHJAX_DIR
3535
from sage.misc.latex_macros import sage_mathjax_macros
3636
from sage.features import PythonModule
37+
from sage.features.all import all_features
3738

3839
# General configuration
3940
# ---------------------
@@ -1051,3 +1052,18 @@ def setup(app):
10511052
app.connect('missing-reference', find_sage_dangling_links)
10521053
app.connect('builder-inited', nitpick_patch_config)
10531054
app.connect('html-page-context', add_page_context)
1055+
1056+
1057+
# Conditional content
1058+
# https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#tags
1059+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#conf-tags
1060+
# https://github.com/readthedocs/readthedocs.org/issues/4603#issuecomment-1411594800
1061+
# Workaround to allow importing this file from other confs
1062+
if 'tags' not in locals():
1063+
class Tags(set):
1064+
has = set.__contains__
1065+
tags = Tags()
1066+
1067+
1068+
for feature in all_features():
1069+
tags.add('feature_' + feature.name.replace('.', '_'))

0 commit comments

Comments
 (0)