sagemath/sage

./configure --disable-doc

Closed this issue · 174 comments

This switch will disable the docbuild and avoid installing its many dependencies (sphinx...).

In contrast to other packages, pplpy's docbuild is enabled unless explicitly disabled by setting SAGE_SPKG_INSTALL_DOCS=no. We move it to a separate package pplpy_doc and make it a dependency of sagemath_doc_html.

Split out from #31396.

We also add argon2_cffi and nbclient to the packages disabled upon --disable-notebook.

Depends on #29039

CC: @tobiasdiez @dimpase @jhpalmieri @sagetrac-tmonteil

Component: build: configure

Author: Matthias Koeppe, John Palmieri

Branch/Commit: 43221d0

Reviewer: John Palmieri, Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/32759

Branch pushed to git repo; I updated commit sha1. New commits:

97b9fcfconfigure.ac (--disable-doc): Disable also 'requests' and its dependencies, and direct sphinx dependencies
18b4055build/pkgs/pplpy/dependencies: Depend on sphinx only if SAGE_SPKG_INSTALL_DOCS!=no

Description changed:

--- 
+++ 
@@ -1,4 +1,7 @@
 This switch will disable the docbuild and installation of its many dependencies (sphinx...)
+
+In contrast to other packages, `ppl`'s docbuild is enabled unless explicitly disabled by setting `SAGE_SPKG_INSTALL_DOCS=no`.
+We conditionalize the dependency of `ppl` on this and also on `sphinx` being in the list of installed packages.
 
 Split out from #31396.
 

Changed commit from 18b4055 to dfd23fb

Branch pushed to git repo; I updated commit sha1. New commits:

dfd23fbbuild/pkgs/pplpy/dependencies: Fix up SAGE_SPKG_INSTALL_DOCS logic

Author: Matthias Koeppe

Changed commit from dfd23fb to 7307c75

Branch pushed to git repo; I updated commit sha1. New commits:

7307c75configure.ac (--disabled-notebook): Also disable nbclient

Description changed:

--- 
+++ 
@@ -5,3 +5,5 @@
 
 Split out from #31396.
 
+We also add another package to those that are disabled upon `--disable-notebook`.
+
comment:9

If --disable-doc is given, then should doc be removed from the all-start target, so that make doesn't try to build the docs?

comment:10

Also, after I used ./configure --disable-doc, packages like alabaster and sphinxcontrib-... were built anyway.

comment:11

Replying to @jhpalmieri:

If --disable-doc is given, then should doc be removed from the all-start target, so that make doesn't try to build the docs?

Yes, that's a good idea.

comment:12

config.log says (for example)

configure:45112: result: sphinx-4.2.0:                                standard, but disabled using configure option

but maybe the problem is that I ran make instead of make build?

comment:13

Yes, probably the all-start target pulled in the doc dependencies.

Changed commit from 7307c75 to 128de23

Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:

d13b8aeconfigure.ac (--disable-doc): Disable also 'requests' and its dependencies, and direct sphinx dependencies
4121cb0build/pkgs/pplpy/dependencies: Depend on sphinx only if SAGE_SPKG_INSTALL_DOCS!=no
8ca1189build/pkgs/pplpy/dependencies: Fix up SAGE_SPKG_INSTALL_DOCS logic
ccf6fb5configure.ac (--disabled-notebook): Also disable nbclient
8e26780build/pkgs/sagemath_doc_{html,pdf}: New; delegate to them from targets doc-html etc.
eeb8777m4/sage_spkg_collect.m4: Determine install tree for python3 via new trees.txt mechanism
c8e19a0fixup
5a4424bbuild/make/Makefile.in (all-sage): Do not include packages installed in SAGE_DOCS
67714b8Merge #31356
128de23configure.ac (--disable-doc): Disable the actual docbuild on 'make'

Dependencies: #31356

comment:16

Replying to @mkoeppe:

Replying to @jhpalmieri:

If --disable-doc is given, then should doc be removed from the all-start target, so that make doesn't try to build the docs?

Yes, that's a good idea.

This is implemented now, via #31356

Changed commit from 128de23 to 8a7027a

Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:

eb65e03build/pkgs/sagemath_doc_*/dependencies: Add sage_docbuild
7989d87src/doc/Makefile: Handle errors from './sage --docbuild --all-documents'
d64fb76build/make/Makefile.in: Undo reintroduction of SAGE_SKIP_PLOT_DIRECTIVE, SAGE_DOC_MATHJAX settings
6afc0d5build/pkgs/sagemath_doc_html/spkg-install: Move handling of SAGE_DOC_JSMATH environment variable here from src/bin/sage-env
b2cf40cbuild/make/Makefile.in: Undo reintroduction of SAGE_SKIP_PLOT_DIRECTIVE, SAGE_DOC_MATHJAX settings (fixup)
37a03bdsrc/doc/en/developer/packaging.rst: Fix up section label
fc89a66build/pkgs/sagemath_doc_pdf/spkg-install: Set SAGE_DOC_MATHJAX as a workaround
fd298c4build/pkgs/sagemath_doc_pdf/dependencies: Depend on sagemath_doc_html
b0593eaMerge #31356
8a7027aconfigure.ac (--disable-doc): Disable the actual docbuild on 'make'
comment:18

Rebased on top of updated #31356

comment:19

Should we expect doctests to pass with ./configure --disable-doc? I get

src/sage/misc/sagedoc.py  # 8 doctests failed
src/sage_docbuild/utils.py  # 5 doctests failed
src/sage_docbuild/__init__.py  # 38 doctests failed
src/sage_docbuild/sphinxbuild.py  # 13 doctests failed
src/sage/docs/conf.py  # 1 doctest failed

which is not surprising, but should they be tagged so that they are only tested when sagemath_doc_html is built?

comment:20

git grep 'dochtml' shows that we already seem to have an optional tag for this kind of thing.

We should probably replace it by # optional - sagemath_doc_html and add the missing ones for the failing doctests.

comment:21

Right, and then in the top-level Makefile, this line needs to be changed:

TESTALL_FLAGS = --optional=sage,dochtml,optional,external,build

and maybe the last line in this block from src/sage/doctest/control.py:

            if have_git:
                self.files.append(opj(SAGE_SRC, 'sage_setup'))
                self.files.append(opj(SAGE_SRC, 'sage_docbuild'))

Perhaps define have_docs appropriately and have a separate if have_docs block. Either that or tag everything in sage_docbuild.

comment:22

Something like this?

diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py
index 858d8cb567..8dbb693e22 100644
--- a/src/sage/doctest/control.py
+++ b/src/sage/doctest/control.py
@@ -727,13 +727,14 @@ class DocTestController(SageObject):
             Doctesting ...
         """
         opj = os.path.join
-        from sage.env import SAGE_SRC, SAGE_DOC_SRC, SAGE_ROOT, SAGE_ROOT_GIT
+        from sage.env import SAGE_SRC, SAGE_DOC_SRC, SAGE_DOC, SAGE_ROOT, SAGE_ROOT_GIT
         # SAGE_ROOT_GIT can be None on distributions which typically
         # only have the SAGE_LOCAL install tree but not SAGE_ROOT
         if SAGE_ROOT_GIT is not None:
             have_git = os.path.isdir(SAGE_ROOT_GIT)
         else:
             have_git = False
+        have_docs = os.path.isdir(opj(SAGE_DOC, 'html', 'en', 'tutorial'))
 
         def all_files():
             self.files.append(opj(SAGE_SRC, 'sage'))
@@ -742,7 +743,8 @@ class DocTestController(SageObject):
             # don't make sense to run outside a build environment
             if have_git:
                 self.files.append(opj(SAGE_SRC, 'sage_setup'))
-                self.files.append(opj(SAGE_SRC, 'sage_docbuild'))
+                if have_docs:
+                    self.files.append(opj(SAGE_SRC, 'sage_docbuild'))
             self.files.append(SAGE_DOC_SRC)
 
         if self.options.all or (self.options.new and not have_git):
comment:23

I think it would make more sense to just test whether opj(SAGE_SRC, 'sage_docbuild') exists.

Same for sage_setup.

I think we can get rid of the have_git logic

comment:24

By the way, with make distclean && ./configure --disable-doc && make build, the various sphinx packages are still being built.

Changed commit from 8a7027a to b6167ca

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

5d962faconfigure.ac (--disable-notebook): Also disable argon2_cffi
da2f1ccconfigure.ac (--disable-doc): New
4f0fee0configure.ac (--disable-doc): Disable also 'requests' and its dependencies, and direct sphinx dependencies
92d06dcbuild/pkgs/pplpy/dependencies: Depend on sphinx only if SAGE_SPKG_INSTALL_DOCS!=no
3b1f105build/pkgs/pplpy/dependencies: Fix up SAGE_SPKG_INSTALL_DOCS logic
64273d1configure.ac (--disabled-notebook): Also disable nbclient
b6167caconfigure.ac (--disable-doc): Disable the actual docbuild on 'make'
comment:26

Replying to @mkoeppe:

Rebased on top of updated #31356

... I had lost most of the commits in this rebase.

Fixed.

comment:27

Replying to @mkoeppe:

I think it would make more sense to just test whether opj(SAGE_SRC, 'sage_docbuild') exists.

Same for sage_setup.

I think we can get rid of the have_git logic

Either that or test whether we can import sage_docbuild. I think the directory will exist (in a source distribution) regardless, but we don't want to test if we haven't at least built sage_docbuild. That seems cleaner than tagging everything in those files optional - sage_docbuild.

comment:28

I think the doctesting logic is that the source tree (in SAGE_ROOT/src) is preferred over installed sources, which are only used for falling back (for example for use in downstream packaging). But I agree, when falling back to installed sources, then importing sage_docbuild and using its __path__ is the right solution

comment:29

My point is that the typical doctest in sage_docbuild/* starts with from sage_docbuild import ..., so we shouldn't bother to test (as part of make testall etc.) if we can't import sage_docbuild. So I suggest something like:

diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py
index 858d8cb567..2bf0a4beb4 100644
--- a/src/sage/doctest/control.py
+++ b/src/sage/doctest/control.py
@@ -740,9 +740,13 @@ class DocTestController(SageObject):
             # Don't run these tests when not in the git repository; they are
             # of interest for building sage, but not for runtime behavior and
             # don't make sense to run outside a build environment
-            if have_git:
+            if os.path.isdir(opj(SAGE_SRC, 'sage_setup')):
                 self.files.append(opj(SAGE_SRC, 'sage_setup'))
+            try:
+                import sage_docbuild
                 self.files.append(opj(SAGE_SRC, 'sage_docbuild'))
+            except ImportError:
+                pass
             self.files.append(SAGE_DOC_SRC)
 
         if self.options.all or (self.options.new and not have_git):
comment:30

Ah ok, I agree. Same for sage_setup then, I think

Branch pushed to git repo; I updated commit sha1. New commits:

3556181git grep -l '#.*optional.*dochtml' | xargs sed -i.bak 's/# optional - dochtml/# optional - sagemath_doc_html/'

Changed commit from b6167ca to 3556181

Branch pushed to git repo; I updated commit sha1. New commits:

4c11aabsed -i.bak 's/dochtml/sagemath_doc_html/' Makefile src/bin/sage-runtests src/doc/en/developer/doctesting.rst

Changed commit from 3556181 to 4c11aab

comment:33

Is it possible that SAGE_DOC_SRC might be missing? We could do this:

diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py
index 858d8cb567..86dbd24d1a 100644
--- a/src/sage/doctest/control.py
+++ b/src/sage/doctest/control.py
@@ -737,13 +737,22 @@ class DocTestController(SageObject):
 
         def all_files():
             self.files.append(opj(SAGE_SRC, 'sage'))
-            # Don't run these tests when not in the git repository; they are
-            # of interest for building sage, but not for runtime behavior and
-            # don't make sense to run outside a build environment
-            if have_git:
+            # Only test sage_setup and sage_docbuild if the relevant
+            # imports work. They may not work if not in a build
+            # environment or if the documentation build has been
+            # disabled.
+            try:
+                import sage_setup
                 self.files.append(opj(SAGE_SRC, 'sage_setup'))
+            except ImportError:
+                pass
+            try:
+                import sage_docbuild
                 self.files.append(opj(SAGE_SRC, 'sage_docbuild'))
-            self.files.append(SAGE_DOC_SRC)
+            except ImportError:
+                pass
+            if os.path.isdir(SAGE_DOC_SRC):
+                self.files.append(SAGE_DOC_SRC)
 
         if self.options.all or (self.options.new and not have_git):
             self.log("Doctesting entire Sage library.")

New commits:

4c11aabsed -i.bak 's/dochtml/sagemath_doc_html/' Makefile src/bin/sage-runtests src/doc/en/developer/doctesting.rst
comment:34

Can we autodetect sagemath_doc_html as an optional tag to add for testing?

comment:35

Yes, I think it should be autodetected already because sagemath_doc_html is just an installed package

comment:36

Replying to @jhpalmieri:

Is it possible that SAGE_DOC_SRC might be missing?

Yes, I think so, for example in downstream packaging of sage

comment:37

Replying to @mkoeppe:

Yes, I think it should be autodetected already because sagemath_doc_html is just an installed package

Does that mean we shouldn't manually add it to TESTALL_FLAGS and let it happen automatically?

comment:38

Yes, that's a good point

comment:39

Not sure how to implement TESTALL_NODOC_FLAGS then

TESTALL_FLAGS = --optional=sage,sagemath_doc_html,optional,external,build
TESTALL_NODOC_FLAGS = --optional=sage,optional,external,build
comment:40

(introduced in #31084)

comment:41

Deprecate the nodoc targets and tell people to use ./configure --disable-doc instead?

Or leave it with the two FLAGS being identical? Running make ptest-nodoc runs make build and so shouldn't build sagemath_doc_html, so it shouldn't run tests with that flag, while make ptest runs make and so will build sagemath_doc_html.

comment:42

Thanks for the analysis, I like the 2nd option

Branch pushed to git repo; I updated commit sha1. New commits:

afa2f80Makefile: Get rid of TESTALL_NODOC_FLAGS

Changed commit from 4c11aab to afa2f80

Branch pushed to git repo; I updated commit sha1. New commits:

28cf775src/bin/sage-runtests (_get_optional_defaults): No need to include sagemath_doc_html here

Changed commit from afa2f80 to 28cf775

comment:45

Could you push the change from comment:33 to the ticket please?

comment:47

Replying to @jhpalmieri:

Should we expect doctests to pass with ./configure --disable-doc? I get

src/sage/misc/sagedoc.py  # 8 doctests failed [...]

Not sure what to do with these ones. What's happening here is that sage.misc.sagedoc.detex has a run-time dependency on Sphinx.


New commits:

10de6fdtrac 32759: doctest sage_setup and sage_docbuild conditionally

Changed commit from 28cf775 to 10de6fd

Changed commit from 10de6fd to 4213f8a

comment:49

Replying to @mkoeppe:

Yes, I think it should be autodetected already because sagemath_doc_html is just an installed package

Actually, at the moment this is not true because sage.doctest.control only looks at the optional packages.


New commits:

4213f8asage.misc.sagedoc: Do not fail if sphinx cannot be imported
comment:50

What mechanism adds sage.geometry.polyhedron and sage_spkg to the list of tags?

Changed commit from 4213f8a to 80513e3

Branch pushed to git repo; I updated commit sha1. New commits:

b142e34sage.features.sphinx: New
80513e3src/sage/doctest/control.py: Add test for Sphinx feature
comment:52

It's happening in the lines of code in the middle of which I have just inserted a test for sphinx

comment:53

In #32174 I am hoping to unify all that

Branch pushed to git repo; I updated commit sha1. New commits:

7d26e21sage.features.sagemath.sagemath_doc_html: New

Changed commit from 80513e3 to 7d26e21

Branch pushed to git repo; I updated commit sha1. New commits:

bb1626asage.features.sagemath.sagemath_doc_html: Fixup

Changed commit from 7d26e21 to bb1626a

Branch pushed to git repo; I updated commit sha1. New commits:

a24c3bdsrc/sage/misc/sagedoc.py: Mark some doctests # optional - sphinx

Changed commit from bb1626a to a24c3bd

Branch pushed to git repo; I updated commit sha1. New commits:

3e9770bsage.features.StaticFile: Accept directories too

Changed commit from a24c3bd to 3e9770b

Changed author from Matthias Koeppe to Matthias Koeppe, John Palmieri

comment:59

By the way, this fails:

make distclean
./configure --disable-doc
make
make doc-html

I think the error boils down to

[reference] intersphinx inventory '/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.5.beta5/local/share/doc/pplpy/objects.inv' not fetchable due to <class 'FileNotFoundError'>: [Errno 2] No such file or directory: '/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.5.beta5/local/share/doc/pplpy/objects.inv'

The problem is that pplpy doesn't build its documentation the first time, and then it doesn't get rebuilt when make doc-html is run. I don't know how to fix this.

comment:60

With make distclean && ./configure && make ptestlong, I get two doctest failures:

File "src/sage/all.py", line 31, in sage.all
Failed example:
    [inspect.getmodule(f).__name__ for f in frames if is_not_allowed(f)]
Expected:
    []
Got:
    ['pytz', 'importlib.resources']

and

File "src/sage/misc/sagedoc.py", line 31, in sage.misc.sagedoc
Failed example:
    "sphinx" in sys.modules
Expected:
    False
Got:
    True
comment:61

Replying to @jhpalmieri:

The problem is that pplpy doesn't build its documentation the first time, and then it doesn't get rebuilt when make doc-html is run. I don't know how to fix this.

We can introduce a separate package pplpy_doc, something that would actually also make sense for the upstream Python package.

Branch pushed to git repo; I updated commit sha1. New commits:

e4a7290build/pkgs/pplpy_doc: Split pplpy docbuild out as a separate package
ee4e50abuild/pkgs/sagemath_doc_html/dependencies: Add pplpy_doc

Changed commit from 3e9770b to ee4e50a

Changed dependencies from #31356 to #31356, #32745

Changed commit from ee4e50a to 810f26f

Branch pushed to git repo; I updated commit sha1. New commits:

f681abbbuild/bin/sage-spkg: Also source sage-src-env-config so that SAGE_VENV is available
7438449src/bin/sage-env: Do not skip the script if SAGE_ENV_SOURCED was set but SAGE_VENV has changed
b07c8e3build/bin/sage-spkg: Remove workaround of setting of PATH in the generated package scripts
4af9a24Merge #32745
810f26fsrc/sage/misc/sagedoc.py: Test that sphinx is not imported in a fresh Sage copy

Changed commit from 810f26f to d280c9c

Branch pushed to git repo; I updated commit sha1. New commits:

f75d33fTrac #32836: don't let libSingular clobber the user's PATH.
d280c9cMerge #32836

Changed dependencies from #31356, #32745 to #31356, #32745, #32836

Changed commit from d280c9c to 7960b90

Branch pushed to git repo; I updated commit sha1. New commits:

7960b90src/sage/all.py: Update doctest
comment:68

Replying to @jhpalmieri:

With make distclean && ./configure && make ptestlong, I get two doctest failures:

File "src/sage/all.py", line 31, in sage.all
Failed example:
    [inspect.getmodule(f).__name__ for f in frames if is_not_allowed(f)]
Expected:
    []
Got:
    ['pytz', 'importlib.resources']

I've updated this doctest for the stuff that is pulled in by the doctest framework via Sphinx.

and

File "src/sage/misc/sagedoc.py", line 31, in sage.misc.sagedoc
Failed example:
    "sphinx" in sys.modules
Expected:
    False
Got:
    True

Fixed by starting a fresh interpreter for this test. Had to pull in 2 tickets that fixed issues with recursive invocation of sage

Branch pushed to git repo; I updated commit sha1. New commits:

687e5basrc/sage/features/sagemath.py: Add doctests

Changed commit from 7960b90 to 687e5ba

comment:70

With --disable-doc, make doc-html goes through but ends with

touch: /var/lib/sage/installed/sagemath_doc_html-none: No such file or directory
make[2]: *** [sagemath_doc_html-SAGE_DOCS-no-deps] Error 1
comment:72

For reasons I don't understand, my computer is now refusing to build the plots in the documentation — it keeps hanging in references/plotting. After fighting with this for a while, I've given in and am resuming testing using export SAGE_DOCBUILD_OPTS=' --no-plot'.

(Not related to this ticket: this happens with the develop branch, too.)

Branch pushed to git repo; I updated commit sha1. New commits:

40a9760build/make/Makefile.in: Raise an error if installation into disabled installation tree is attempted

Changed commit from 687e5ba to 40a9760

comment:74

Replying to @mkoeppe:

With --disable-doc, make doc-html goes through but ends with

touch: /var/lib/sage/installed/sagemath_doc_html-none: No such file or directory
make[2]: *** [sagemath_doc_html-SAGE_DOCS-no-deps] Error 1

Fixed now by explicitly raising a clear error.

Do we want make doc, make doc-html to work when --disable-doc has been configured?

comment:75

Replying to @mkoeppe:

Do we want make doc, make doc-html to work when --disable-doc has been configured?

Good question, I don't know. Should the following work? Does it work?

make distclean
./configure --disable-doc
make
./configure --enable-doc # without make distclean or similar
make doc-html
comment:76

Replying to @jhpalmieri:

Replying to @mkoeppe:

Do we want make doc, make doc-html to work when --disable-doc has been configured?

Good question, I don't know.

I think I would be happy if it didn't work but if there were a clear error message.

% make doc
...
Error: Sage build configured with --disable-doc, so building the documentation will not work. To fix this, ...
comment:77

Replying to @jhpalmieri:

Should the following work? Does it work?

make distclean
./configure --disable-doc
make
./configure --enable-doc # without make distclean or similar
make doc-html

Yes, I think this works

Branch pushed to git repo; I updated commit sha1. New commits:

51f3002build/make/Makefile.in: Better error message when docbuild is attempted but configure --disable-doc has been used

Changed commit from 40a9760 to 51f3002