Skip to content
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

sage --docbuild: Add options to list all documents #31353

Closed
mkoeppe opened this issue Feb 7, 2021 · 20 comments
Closed

sage --docbuild: Add options to list all documents #31353

mkoeppe opened this issue Feb 7, 2021 · 20 comments

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 7, 2021

In contrast to the existing -D option, it would be a simple machine-readable output; and given a document such as en/reference, it would list its subdocuments.

Using this output we can reimplement the parallel build of all documents (AllBuilder._wrapper) using a simple Makefile.

CC: @jhpalmieri

Component: documentation

Author: John Palmieri

Branch/Commit: b67798e

Reviewer: Matthias Koeppe

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

@mkoeppe mkoeppe added this to the sage-9.3 milestone Feb 7, 2021
@jhpalmieri
Copy link
Member

comment:1

While we're at it, we should perhaps upgrade from optparse to argparse.

@jhpalmieri
Copy link
Member

comment:2

Something like this will allow the use of sage --docbuild -all-documents ARG, where ARG is either reference for one list or any other string for the other list:

diff --git a/src/sage_setup/docbuild/__init__.py b/src/sage_setup/docbuild/__init__.py
index f4e8522e28..77547ec6d0 100644
--- a/src/sage_setup/docbuild/__init__.py
+++ b/src/sage_setup/docbuild/__init__.py
@@ -1466,9 +1466,16 @@ def help_wrapper(option, opt_str, value, parser):
         print(help_documents(), end="")
     if option.dest == 'formats':
         print(help_formats(), end="")
+    if option.dest == 'all_documents':
+        if value == 'en/reference' or value == 'reference':
+            b = ReferenceBuilder('reference')
+            refdir = os.path.join(os.environ['SAGE_DOC_SRC'], 'en', b.name)
+            s = sorted(b.get_all_documents(refdir))
+        else:
+            s = get_documents()
+        print(s)
     setattr(parser.values, 'printed_list', 1)
 

@@ -1581,6 +1588,10 @@ def setup_parser():
     advanced.add_option("-k", "--keep-going", dest="keep_going",
                         default=False, action="store_true",
                         help="Do not abort on errors but continue as much as possible after an error")
+    advanced.add_option("--all-documents", dest="all_documents",
+                        type="str", action="callback", callback=help_wrapper,
+                        help="list ALL available DOCUMENTs, including subdocuments "
+                        "of en/reference. Mainly for internal use.")
     parser.add_option_group(advanced)
 
     return parser

@jhpalmieri
Copy link
Member

comment:3

Sample output:

% ./sage --docbuild --all-documents reference
['reference/algebras', 'reference/arithgroup', 'reference/arithmetic_curves', 'reference/asymptotic', 'reference/calculus', 'reference/categories', 'reference/coding', 'reference/coercion', 'reference/combinat', 'reference/constants', 'reference/cpython', 'reference/cryptography', 'reference/curves', 'reference/data_structures', 'reference/databases', 'reference/diophantine_approximation', 'reference/discrete_geometry', 'reference/doctest', 'reference/dynamics', 'reference/euclidean_spaces', 'reference/finance', 'reference/finite_rings', 'reference/function_fields', 'reference/functions', 'reference/game_theory', 'reference/games', 'reference/graphs', 'reference/groups', 'reference/hecke', 'reference/history_and_license', 'reference/homology', 'reference/hyperbolic_geometry', 'reference/interfaces', 'reference/knots', 'reference/lfunctions', 'reference/libs', 'reference/logic', 'reference/manifolds', 'reference/matrices', 'reference/matroids', 'reference/misc', 'reference/modabvar', 'reference/modfrm', 'reference/modfrm_hecketriangle', 'reference/modmisc', 'reference/modsym', 'reference/modules', 'reference/monoids', 'reference/noncommutative_polynomial_rings', 'reference/number_fields', 'reference/numerical', 'reference/padics', 'reference/parallel', 'reference/plot3d', 'reference/plotting', 'reference/polynomial_rings', 'reference/power_series', 'reference/probability', 'reference/quadratic_forms', 'reference/quat_algebras', 'reference/quivers', 'reference/references', 'reference/repl', 'reference/riemannian_geometry', 'reference/rings', 'reference/rings_numerical', 'reference/rings_standard', 'reference/sat', 'reference/schemes', 'reference/semirings', 'reference/sets', 'reference/spkg', 'reference/stats', 'reference/structure', 'reference/tensor_free_modules', 'reference/valuations']
% ./sage --docbuild --all-documents whatever 
['reference', 'ja/a_tour_of_sage', 'ja/tutorial', 'it/a_tour_of_sage', 'it/faq', 'ca/intro', 'ru/tutorial', 'pt/a_tour_of_sage', 'pt/tutorial', 'hu/a_tour_of_sage', 'de/a_tour_of_sage', 'de/tutorial', 'de/thematische_anleitungen', 'fr/a_tour_of_sage', 'fr/tutorial', 'es/a_tour_of_sage', 'es/tutorial', 'a_tour_of_sage', 'developer', 'prep', 'tutorial', 'faq', 'constructions', 'website', 'installation', 'thematic_tutorials', 'tr/a_tour_of_sage']

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Feb 8, 2021

comment:4

Great. For using this from Makefiles it's probably better to print it one item a line without decoration such as commas

@jhpalmieri
Copy link
Member

Branch: u/jhpalmieri/print-all-docs

@jhpalmieri
Copy link
Member

Commit: f17f2f6

@jhpalmieri
Copy link
Member

comment:6

Here's a branch. I did a little sorting on the document names to reflect the order in which things should get built (reference manual first, reference/references first within that).


New commits:

f17f2f6trac 31353: add option to print names of all pieces of documentation,

@jhpalmieri
Copy link
Member

Author: John Palmieri

@jhpalmieri
Copy link
Member

comment:7

It's ready for review in terms of my code, but I don't know if it's printing in the format you want.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Feb 9, 2021

comment:8

The output is perfect, thanks a lot!

But in terms of the interface, I think it would be better if passing anything that is not all or references would give an error.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 9, 2021

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

8063fd8trac 31353: add option to print names of all pieces of documentation,
799ddf2trac 31353: only accept 'all' or 'reference' as arguments

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 9, 2021

Changed commit from f17f2f6 to 799ddf2

@jhpalmieri
Copy link
Member

comment:10

Okay, how about this?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Feb 9, 2021

comment:11

Perfect except for a possible typo here

+            raise ValueError("argument for --all-documents must be either 'all'"
+                             " or 'references'")

should be 'reference' I think

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 9, 2021

Changed commit from 799ddf2 to b67798e

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 9, 2021

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

b67798etrac 31353: only accept 'all' or 'reference' as arguments

@jhpalmieri
Copy link
Member

comment:13

Thanks for catching that; fixed.

@jhpalmieri
Copy link
Member

comment:14

I've opened #31366 for converting from optparse to argparse.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Feb 9, 2021

Reviewer: Matthias Koeppe

@vbraun
Copy link
Member

vbraun commented Mar 9, 2021

Changed branch from u/jhpalmieri/print-all-docs to b67798e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants