New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docbuilding without TESTS: blocks fails #21172
Comments
Changed keywords from none to --no-tests |
comment:2
I thought that docbuilding without |
comment:3
Replying to @jdemeyer:
I would like it to be default for most users. But then for developers it might be easier if it is not. Anyways, it seems that fix for this problem is removing two empty lines. Someone with more time should check what is the real problem. |
comment:4
Replying to @jm58660:
Yes. It would be good anyway for different purposes to have something like a "Sage developer mode" which is not enabled by default (or in stable releases, say).
Is it something that should go into the Sage Developer Guide (in order to avoid it in the future)? |
comment:5
Replying to @nexttime:
Hmm... yes and no. Would be good, but OTOH dangerous as something might work in developer mode only. Actually this one is just a case of that! I compiled docs for several betas of 7.3 in a desktop, but for final version I installed it with
Some patchbot should compile with the flag and another without flag. I doubt how many developer or reviewer would compile documentation twise just to be sure. |
comment:6
Replying to @jm58660:
And how many developers actually compile their own documentation and view that? I guess not many. I do it rarely in case I'm working on a documentation ticket and want to see the output. And even if I do that, I don't care about the I don't see the point of "optionally" removing Even the online documentation still has the (I know this is all orthogonal to this ticket, but I just don't understand why somebody would add an option to remove |
comment:7
Replying to @jm58660:
If you know the fix, can you put it on this ticket? |
comment:8
I think this problem occurs because lines like the following (from Sage output in doctests around line 162 in
match the regular expression which is supposed to signify the end of a |
comment:9
Replying to @jdemeyer:
I fully agree (and by the way think this belongs to this ticket). Add IMHO The problem I see (OTOH) is that |
comment:10
Replying to @jdemeyer:
I think that it was discussed when add the switch. But I don't remember what was the reason to not make it default. |
comment:11
For the record: The online (terminal) help for
Note that everything below |
comment:12
Replying to @nexttime:
I agree. Most common problem is to not have a I guess this is partly because |
comment:13
Well, I do not know whether this was introduced at the same time, but the online help ( |
comment:14
Couldn't resist: diff --git a/src/doc/en/installation/source.rst b/src/doc/en/installation/source.rst
index 799b546..fa4a42e 100644
--- a/src/doc/en/installation/source.rst
+++ b/src/doc/en/installation/source.rst
@@ -999,7 +999,7 @@ Here are some of the more commonly used variables affecting the build process:
you run ``make``, ``make doc``, or ``make doc-pdf``.
For example, you can add ``--no-plot`` to this variable to avoid building
the graphics coming from the ``.. PLOT`` directive within the documentation,
- or you can add ``--no-tests`` to omit all "TESTS" blocks in the
+ or you can add ``--include-tests-blocks`` to include all "TESTS" blocks in the
reference manual. Run ``sage --docbuild help`` to see the full list
of options.
diff --git a/src/sage_setup/docbuild/__init__.py b/src/sage_setup/docbuild/__init__.py
index 1fc5ccb..e7363e7 100644
--- a/src/sage_setup/docbuild/__init__.py
+++ b/src/sage_setup/docbuild/__init__.py
@@ -1445,9 +1445,9 @@ def setup_parser():
standard.add_option("--no-plot", dest="no_plot",
action="store_true",
help="do not include graphics auto-generated using the '.. plot' markup")
- standard.add_option("--no-tests", dest="skip_tests", default=False,
- action="store_true",
- help="do not include TESTS blocks in the reference manual")
+ standard.add_option("--include-tests-blocks", dest="skip_tests", default=True,
+ action="store_false",
+ help="include TESTS blocks in the reference manual")
standard.add_option("--no-pdf-links", dest="no_pdf_links",
action="store_true",
help="do not include PDF links in DOCUMENT 'website'; FORMATs: html, json, pickle, web") |
comment:15
Replying to @nexttime:
[snip] Yes, and this is why I made comment above (plus looking at the documentation and source code in The original ticket #19503 was precisely about skipping |
comment:16
So here's the culprit ( # end_of_block: match a line starting with whitespace, then Sphinx
# directives of the form ".. foo:". This will match directive
# names "foo" containing letters of either case, hyphens,
# underscores.
# Also match uppercase text followed by a colon, like
# "REFERENCES:" or "ALGORITHM:".
end_of_block = re.compile('[ ]*(\.\.[ ]+[-_A-Za-z]+|[A-Z]+):')
# header: match a string of hyphens, or other characters which are
# valid markers for ReST headers: - = ` : ' " ~ _ ^ * + # < > Currently, only another ...
if not skip:
m = tests_block.match(l)
if m:
skip = True
indentation = m.group(1)
else:
s += "\n"
s += l
else:
if end_of_block.match(l) and not tests_block.match(l):
skip = False
s += "\n"
s += l
... So we'd either have to whitelist PARI's Not sure whether there is at all a complete list of such. (AFAIK, it's just informal convention to use this or that.) |
comment:17
Or check the indentation level: to terminate the block, a string like |
comment:18
Maybe something like diff --git a/src/sage/misc/sagedoc.py b/src/sage/misc/sagedoc.py
index 968a44c..77d6984 100644
--- a/src/sage/misc/sagedoc.py
+++ b/src/sage/misc/sagedoc.py
@@ -322,6 +322,8 @@ def skip_TESTS_block(docstring):
s += l
else:
if end_of_block.match(l) and not tests_block.match(l):
+ if l.find(indentation) == 0:
+ continue
skip = False
s += "\n"
s += l |
comment:19
I've tried another way: diff --git a/src/sage/misc/sagedoc.py b/src/sage/misc/sagedoc.py
index a6c5568..dc5eb13 100644
--- a/src/sage/misc/sagedoc.py
+++ b/src/sage/misc/sagedoc.py
@@ -302,6 +302,13 @@ def skip_TESTS_block(docstring):
# Also match uppercase text followed by a colon, like
# "REFERENCES:" or "ALGORITHM:".
end_of_block = re.compile('[ ]*(\.\.[ ]+[-_A-Za-z]+|[A-Z]+):')
+ # Only recognize commonly used section names, not e.g. output
+ # from doctests incidentally matching '[A-Z]+:':
+ SECTION_NAMES = set([
+ "AUTHOR", "AUTHORS",
+ "ALGORITH", "ALGORITHMS",
+ "REFERENCE", "REFERENCES"
+ ])
# header: match a string of hyphens, or other characters which are
# valid markers for ReST headers: - = ` : ' " ~ _ ^ * + # < >
header = re.compile(r'^[ ]*([-=`:\'"~_^*+#><])\1+[ ]*$')
@@ -320,7 +327,9 @@ def skip_TESTS_block(docstring):
s += "\n"
s += l
else:
- if end_of_block.match(l) and not tests_block.match(l):
+ m = end_of_block.match(l)
+ if m and not tests_block.match(l) \
+ and m.group(1) in SECTION_NAMES:
skip = False
s += "\n"
s += l Works for me modulo adding more section names. |
comment:20
... and modulo spelling of course. ;-) |
comment:21
Speling is an issue, though ;) The likelihood of someone misspelling "ALGORITM", for example, seems pretty high, and it's only going to make a difference when they do it right after a TESTS block. Troubleshooting that will be difficult. Isn't indentation safer than whitelisting? |
comment:22
With your proposal, we at least need to add "EXAMPLE" and "EXAMPLES", by the way. |
comment:23
Replying to @jhpalmieri:
I was about to write that I'm not entirely sure yet your approach works though. Deeeeeep thinking required... But anyway, I'll (ab)use my approach to find all kinds of section names (and misspellings) later... (We could eventually also correct then.) |
comment:64
Fixed. |
comment:65
Why this? @@ -278,8 +279,8 @@ def skip_TESTS_block(docstring):
sage: skip_TESTS_block(start + test + refs + test2 + directive).rstrip() == (start + refs + directive).rstrip()
True
- sage: header = 'Header:\n~~~~~~~~'
- sage: fake_header = 'Header:\n-=-=-=-=-='
+ sage: header = ' Header:\n ~~~~~~~~'
+ sage: fake_header = ' Header:\n -=-=-=-=-='
sage: skip_TESTS_block(start + test + header) == start + header
True
sage: skip_TESTS_block(start + test + fake_header).rstrip() == start.rstrip() I think this doctest should work as it was before. |
comment:66
The old test was not actually testing the "header" part of the code, since it was unindented compared to " TESTS:". Also, both |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:68
The doctests are organized better now (in my opinion). The PDF docs are not building right now, so "needs work". I'll try to figure out what's going on. |
comment:69
It's working now. Maybe I forgot to do |
comment:70
The branch seems to be red again. |
comment:71
I'll try to fix it after the next beta (although it is not clear that anyone is ever going to review it, so I may stop bothering after a while). |
comment:72
Replying to @jhpalmieri:
I guess I must do it. I know about nothing about Sphinx, and actually don't even want to know, but... |
Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:
|
comment:74
Rebased to 7.6.beta3. To help with reviewing: this does nothing explicitly with Sphinx, because that work was done in the earlier ticket dealing with TESTS blocks. This modifies the function that detects when TESTS blocks start and end, so it is plain Python dealing with regular expressions. Sphinx then uses this to process docstrings, but it was already doing that. Oh, it does change one thing with Sphinx: it changes the default from including TESTS blocks to omitting them. |
Reviewer: Jori Mäntysalo |
comment:76
Replying to @jhpalmieri:
Thanks for the explanation. This was the first time I look at Python implementation of regexps, but it seems to be clear. I mark this as a positive review. (Sidenote: We should have something better! I mean a structured way so that Sphinx (or whatever we would use) would know the blocks and one could say something like |
Changed branch from u/jhpalmieri/TESTS to |
gives
Component: documentation
Keywords: --no-tests --include-tests-blocks SAGE_SKIP_TESTS_BLOCKS
Author: John Palmieri
Branch/Commit:
f4c3edb
Reviewer: Jori Mäntysalo
Issue created by migration from https://trac.sagemath.org/ticket/21172
The text was updated successfully, but these errors were encountered: