Skip to content

Restore support for SAGE_DOCBUILD_OPTS#41776

Merged
vbraun merged 2 commits intosagemath:developfrom
orlitzky:sage-docbuild-opts
Mar 22, 2026
Merged

Restore support for SAGE_DOCBUILD_OPTS#41776
vbraun merged 2 commits intosagemath:developfrom
orlitzky:sage-docbuild-opts

Conversation

@orlitzky
Copy link
Copy Markdown
Contributor

@orlitzky orlitzky commented Mar 7, 2026

In the past, SAGE_DOCBUILD_OPTS was included on the command-line in most scenarios where the documentation build was invoked. At some point, this got lost. In an ideal future it will no longer be necessary, but right now, supporting it makes it easy for the CI to include TESTS blocks in the documentation.

In the docbuild's main(), we now prepend SAGE_DOCBUILD_OPTS to sys.argv[1:] before calling parse_args(). To convert the variable (a string) to a list, we split on whitespace. This isn't great, but it gets the job done in typical use cases. The "easy" way to accomplish this goal would be to insert SAGE_DOCBUILD_OPTS into the docbuild command in src/doc/meson.build, but the meson people feel rather strongly that you shouldn't be able to access environment variables within the build.

Closes: #41609

The main issue (for me) that this solves is the absence of the TESTS blocks in the documentation previews. A random documentation page where TESTS are visible:

And its counterpart in another open PR, with no TESTS:

In the past, SAGE_DOCBUILD_OPTS was included on the command-line in
most scenarios where the documentation build was invoked. At some
point, this got lost. In an ideal future it will no longer be
necessary, but right now, supporting it makes it easy for the CI to
include TESTS blocks in the documentation.

In the docbuild's main(), we now prepend SAGE_DOCBUILD_OPTS to
sys.argv[1:] before calling parse_args(). To convert the variable (a
string) to a list, we split on whitespace. This isn't great, but it
gets the job done in typical use cases.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 7, 2026

Documentation preview for this PR (built with commit e6e3e1f; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@orlitzky orlitzky force-pushed the sage-docbuild-opts branch from e209a83 to 09d00a6 Compare March 7, 2026 22:41
@orlitzky orlitzky changed the title Re-support SAGE_DOCBUILD_OPTS in the docbuild Restore support for SAGE_DOCBUILD_OPTS Mar 13, 2026
@orlitzky orlitzky requested a review from kwankyu March 13, 2026 22:33
@orlitzky
Copy link
Copy Markdown
Contributor Author

@kwankyu this fixes some aspects of the documentation preview that I remember you working on.

@kwankyu
Copy link
Copy Markdown
Collaborator

kwankyu commented Mar 14, 2026

FYI, the variable is documented here:

https://doc-10-7--sagemath.netlify.app/html/en/installation/source.html#envvar-SAGE_DOCBUILD_OPTS

and as of Sage 10.6, it is found at:

sage-10.6$ rg "SAGE_DOCBUILD_OPTS"
.github/workflows/doc-build.yml
196:          export SAGE_DOCBUILD_OPTS="--include-tests-blocks"

build/make/Makefile.in
381:	+$(MAKE_REC) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-plot" doc-html

src/doc/Makefile
28:	sage --docbuild --no-pdf-links $(subst -,/,$(subst doc-inventory--,,$@)) inventory $(SAGE_DOCBUILD_OPTS)
32:	sage --docbuild --no-pdf-links $(subst -,/,$(subst doc-html--,,$@)) html $(SAGE_DOCBUILD_OPTS)
46:	$(MAKE) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-prune-empty-dirs" doc-inventory--reference_top
55:	$(MAKE) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-prune-empty-dirs" doc-html--$(subst /,-,$(BIBLIO))
56:	$(MAKE) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-prune-empty-dirs" $(foreach doc, $(OTHER_DOCS), doc-html--$(subst /,-,$(doc)))
60:	$(MAKE) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-prune-empty-dirs" doc-html--reference_top
72:	LATEXOPTS="--file-line-error --interaction=batchmode" sage --docbuild $(subst -,/,$(subst doc-pdf--,,$@)) pdf $(SAGE_DOCBUILD_OPTS)
80:	$(MAKE) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-prune-empty-dirs" doc-pdf--$(subst /,-,$(BIBLIO))
81:	$(MAKE) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-prune-empty-dirs" $(foreach doc, $(OTHER_DOCS), doc-pdf--$(subst /,-,$(doc)))
82:	$(MAKE) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-prune-empty-dirs" doc-pdf--reference_top
88:	$(MAKE) SAGE_DOCBUILD_OPTS="$(SAGE_DOCBUILD_OPTS) --no-prune-empty-dirs" $(foreach doc, $(wordlist 2, 100, $(DOCS)), doc-pdf--$(subst /,-,$(doc)))

src/doc/en/installation/source.rst
637:  ``export SAGE_DOCBUILD_OPTS+=' --no-plot'``
966:.. envvar:: SAGE_DOCBUILD_OPTS

In general, I prefer reviving make doc-html in CI. Note that it was replaced with meson build, that, in particular, does not work for "live doc" (interactive Examples) currently.

@orlitzky
Copy link
Copy Markdown
Contributor Author

In general, I prefer reviving make doc-html in CI. Note that it was replaced with meson build, that, in particular, does not work for "live doc" (interactive Examples) currently.

We could fix the CI with this approach, but the sagelib build system (which builds the docs once itself) doesn't use the Makefile or the "sage" script, so the documentation for SAGE_DOCBUILD_OPTS would still be misleading to end users.

@kwankyu
Copy link
Copy Markdown
Collaborator

kwankyu commented Mar 14, 2026

@orlitzky
Copy link
Copy Markdown
Contributor Author

Don't you need to edit the lines here? https://doc-10-8--sagemath.netlify.app/html/en/installation/source-distro.html#envvar-SAGE_DOCBUILD_OPTS

The title of this page is "Sage-the-distribution (classical build)", and in that context this section is still accurate. Running make doc will eventually provoke meson to run src/build-docs.py, which then runs src/sage_docbuild/__main__.py. This is also what sage --docbuild does, so modulo some implementation details we are not lying about how SAGE_DOCBUILD_OPTS is used in sage-the-distribution.

@kwankyu
Copy link
Copy Markdown
Collaborator

kwankyu commented Mar 15, 2026

This line

The value of this variable is passed as an argument to sage --docbuild all html or sage --docbuild all pdf when you run make, make doc, or make doc-pdf.

is not correct any more. How about this?

The value of this variable is passed to the Sage doc builder when you run make doc, make doc-html or make doc-pdf.

On the other hand sage --docbuild has been broken...

The documentation builder now processes SAGE_DOCBUILD_OPTS itself, so
we should no longer state that it will be passed as an argument to
"sage --docbuild". Moreover, running "sage --docbuild" does not work
without "src" in PYTHONPATH, so instead of suggesting

  $ sage --docbuild --help

to obtain the list of options, we now suggest reading the header
of the appropriate source file.
@orlitzky
Copy link
Copy Markdown
Contributor Author

No problem, I have tried to clarify that line without getting into specifics. Instead of sage --docbuild --help (which does not work without messing with PYTHONPATH), I have pointed everyone to the header of the relevant source file.

Copy link
Copy Markdown
Collaborator

@kwankyu kwankyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 18, 2026
sagemathgh-41776: Restore support for SAGE_DOCBUILD_OPTS
    
In the past, `SAGE_DOCBUILD_OPTS` was included on the command-line in
most scenarios where the documentation build was invoked. At some point,
this got lost. In an ideal future it will no longer be necessary, but
right now, supporting it makes it easy for the CI to include TESTS
blocks in the documentation.

In the docbuild's `main()`, we now prepend `SAGE_DOCBUILD_OPTS` to
`sys.argv[1:]` before calling `parse_args()`. To convert the variable (a
string) to a list, we split on whitespace. This isn't great, but it gets
the job done in typical use cases. The "easy" way to accomplish this
goal would be to insert `SAGE_DOCBUILD_OPTS` into the docbuild command
in `src/doc/meson.build`, but the meson people feel rather strongly that
you shouldn't be able to access environment variables within the build.

Closes: sagemath#41609

The main issue (for me) that this solves is the absence of the `TESTS`
blocks in the documentation previews. A random documentation page where
`TESTS` are visible:

* https://doc-pr-41776--sagemath.netlify.app/html/en/reference/quat_alge
bras/sage/algebras/quatalg/quaternion_algebra

And its counterpart in another open PR, with no `TESTS`:

* https://doc-pr-41768--sagemath.netlify.app/html/en/reference/quat_alge
bras/sage/algebras/quatalg/quaternion_algebra
    
URL: sagemath#41776
Reported by: Michael Orlitzky
Reviewer(s): Kwankyu Lee
vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 21, 2026
sagemathgh-41776: Restore support for SAGE_DOCBUILD_OPTS
    
In the past, `SAGE_DOCBUILD_OPTS` was included on the command-line in
most scenarios where the documentation build was invoked. At some point,
this got lost. In an ideal future it will no longer be necessary, but
right now, supporting it makes it easy for the CI to include TESTS
blocks in the documentation.

In the docbuild's `main()`, we now prepend `SAGE_DOCBUILD_OPTS` to
`sys.argv[1:]` before calling `parse_args()`. To convert the variable (a
string) to a list, we split on whitespace. This isn't great, but it gets
the job done in typical use cases. The "easy" way to accomplish this
goal would be to insert `SAGE_DOCBUILD_OPTS` into the docbuild command
in `src/doc/meson.build`, but the meson people feel rather strongly that
you shouldn't be able to access environment variables within the build.

Closes: sagemath#41609

The main issue (for me) that this solves is the absence of the `TESTS`
blocks in the documentation previews. A random documentation page where
`TESTS` are visible:

* https://doc-pr-41776--sagemath.netlify.app/html/en/reference/quat_alge
bras/sage/algebras/quatalg/quaternion_algebra

And its counterpart in another open PR, with no `TESTS`:

* https://doc-pr-41768--sagemath.netlify.app/html/en/reference/quat_alge
bras/sage/algebras/quatalg/quaternion_algebra
    
URL: sagemath#41776
Reported by: Michael Orlitzky
Reviewer(s): Kwankyu Lee
@vbraun vbraun merged commit 80bd4e9 into sagemath:develop Mar 22, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SAGE_DOCBUILD_OPTS obsolete?

3 participants