Thanks to the newly added '--warn-links' option to sage doc builder,
several patch are currently working to remove broken links in the doc. See
eg. #12810, #12767. However, there is still the problem of private methods
(the one starting with "_"). I understand that we don't want to include them
systematically, because they don't always interest the user, they render the
documentation much too big and make it unreadable. However, in several places
of the doc, in particular in files dealing with infrastructure we definitely
want to include some private members. This was asked to me at least by three
different people.
When you are in a module, there is a standard Sphinx way (an attribute called
"__all__") which tells which member of the module you want to appear in the
documentation. It is only used in Sphinx in a couple of places.
Unfortunately, it only works in a module but not in a class. I could easily
make it work in class by patching "sage_autodoc.py" but I don't think this is
exactly what we want. I think what we really want is a specific sage private
attribute to classes say "_included_private_doc_" which lists the private
method we want always see included in the doc. The non-private methods will be
included as usual.
Note that this could be done in a more standard ways: we could edit the
autogenerated ".rst" file and tell sphinx which members we want to include. I
don't think this would be as easy as the solution I suggested before: Sphinx
asks to write every member we want to include (not only the private ones).
I'm Ok to provide solution; I've a prototype on the sage-combinat queue which
seems to be working. I've to test it more before inclusion in Sage. We just
need to decide if the solution I'm suggestion is Ok and to agree on the name
(I'm currently using '__all__' which seems bad to me).
Any idea or better suggestion ?
Cheers,
Florent
--
To post to this group, send an email to sage-...@googlegroups.com
To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
On Sun, Apr 08, 2012 at 12:15:32PM -0700, David Roe wrote:
> I assume there's no way to automatically add only those private functions
> that are referred to within Sphinx?
There certainly is a way to do that, after all Sphinx is written in
Python. Now, knowing the pain I had to make Sphinx aware to all.py to resolve
its links, I'm not volunteering to do that. Maybe I did it the wrong way but I
had to dive way too much in Docutils/Sphinx internals. So if someone come up
with a solution, I gladly review it but I don't think this is easily doable,
without hacking deep into the beasts.
> If not, I think having "_included_private_doc_" class attribute as a list
> of strings giving the private functions to include sounds like a fine
> solution.
This is much easier than the other solution you suggested.
Waiting for more reaction.
Cheers,
Florent
Of course, as Florent and David I'd much prefer the approach of
including a private method if and only if it's referred to somewhere,
but unless we have a volunteer to implement that, the attribute is fine.
I am not very happy with the name of that attribute but don't have a
really better suggestion so ... Maybe "_documented_private_methods_"?
A potential issue/feature about that attribute: it will be inherited.
While we are speaking about documentation for ``._*`` methods it, a
related question. I consider Python's (``.__*__``) and Sage's
(``._*_``) special methods as public, and would be very much in favor
of including them by default in the Sphinx documentation.
What do you think?
Cheers,
Nicolas
--
Nicolas M. Thi�ry "Isil" <nth...@users.sf.net>
http://Nicolas.Thiery.name/
I agree that it would be nice if __*__ and _*_ showed up in the documentation.
David
While we are speaking about documentation for ``._*`` methods it, a
related question. I consider Python's (``.__*__``) and Sage's
(``._*_``) special methods as public, and would be very much in favor
of including them by default in the Sphinx documentation.
I currently look it into the Class.__dict__. So no inheritance.
> While we are speaking about documentation for ``._*`` methods it, a
> related question. I consider Python's (``.__*__``) and Sage's
> (``._*_``) special methods as public, and would be very much in favor
> of including them by default in the Sphinx documentation.
>
> What do you think?
When I was speaking of private methods, I was refering to those case of
methods as well. The question you are rising here is if SAGE_DOC_UNDERSCORE
should be True by defaults. This is a different question. I though it was
settled.
Cheers,
Florent
> I think "_included_private_doc_" attribute would be great. Does it
> have to be a list of strings, or can it be a list of class members,
> i.e. without quotes?
If we want to be consistent with __all__, it should be a list (or more
generally iterable) of string. DO you have a precise usecase for having a list
of members ?
Cheers,
Florent
Not quite: I only want the .__*__ and ._*_ methods. Not the other ._*,
for which it was indeed settled that there were too many of them.
Cheers,
Nicolas
--
On Mon, Apr 09, 2012 at 05:03:08PM -0700, John H Palmieri wrote:
> I agree that it would be nice if __*__ and _*_ showed up in the
> documentation.
> David
>
> Then run "sage --docbuild -u reference html". According to "sage
> --docbuild help":
>
> -u, --underscore include variables prefixed with '_' in reference
> manual; may be slow, may fail for PDF output
>
> (It should probably say something other than "variables" here.") This
> increases the size of the reference manual, slows down the build (as
> noted), and will likely produce many warnings, since docstrings for
> underscore methods haven't received as much attention as for non-private
> methods, so many of them are misformatted.Not quite: I only want the .__*__ and ._*_ methods. Not the other ._*,
for which it was indeed settled that there were too many of them.
In the process of trying to help fixing broken links in the documentation, I'd
like to share some info and call for a vote:
> > > I think "_included_private_doc_" attribute would be great.
I was writing a patch to allows for including private methods through an
attribute "_included_private_doc_". I just discovered that adding an
"automethod" directive does the job. For example:
.. automethod:: _foo
.. automethod:: _bar
to the end of the main doc of a class document those two special
functions. There is a drawback: The documentation of those methods is placed
here in the given order. So maintaining alphabetic order is at the doc writer
charge. Still I think that this is better than relies on a special sage
attribute. I'm Ok to add this trick to sage devel doc if chosen. So I see two
choices here. Please vote:
[ ] use the Sphinx automethod standard trick.
[ ] use a special Sage attribute "_included_private_doc_"
> > While we are speaking about documentation for ``._*`` methods it, a
> > related question. I consider Python's (``.__*__``) and Sage's
> > (``._*_``) special methods as public, and would be very much in favor
> > of including them by default in the Sphinx documentation.
> >
> > What do you think?
This is a second question: It seems that several Sage developers consider
Python's (``.__*__``) and Sage's (``._*_``) *special* methods as public so
that they should be included in the doc by default. On the opposite, *private*
methods starts by ``_`` but doesn't end with one. I'd like to call a vote for
including them by default in the doc. Some informations (thanks to John H
Palmieri): Compiling the doc with those special functions, take a little
longer, not much (13 minutes vs. 11 minutes). The html documentation was a bit
larger (215M vs. 177M). Sphinx produced 145 warnings which should be fixed.
I see the following choices:
[ ] leave things as they are and rely on the preceding "automethod" or
"_included_private_doc_" trick to document special methods.
[ ] include __*__ and _*_ method by default in the doc.
Thanks for helping having a better doc,
Cheers,
Florent
No opinion.
> [ ] leave things as they are and rely on the preceding "automethod" or
> "_included_private_doc_" trick to document special methods.
> [ ] include __*__ and _*_ method by default in the doc.
The latter.
My two cents, for what they're worth...
-Keshav
----
Join us in #sagemath on irc.freenode.net !
This means that the trivial methods __init__, __repr__, __hash__ and the like
will be included as well. They are usually not very well documented.
Cheers,
Florent
Sage itself builds with just 1GB of memory and almost all doctests pass
with 2GB of RAM. It seems crazy to me that building the documentation
is the part of Sage which needs the most memory.
(all this refers to a 64-bit x86_64 Linux system and virtual memory
limited with ulimit -v)
> I'd also say that docbuild time, documentation size, and amount of
> necessary memory are orthogonal to (not) adding special methods to the
> documentation.
I totally agree.
> I am not saying that they are irrelevant, but if we hit
> limits on these the solution is perhaps to change how documentation is
> built, not just throw away stuff from the documentation. Maybe solving
> these issues can be prerequisites to merging such a change. E.g.
> docbuilding is definitely faster if it can be done in parallel, does
> file splitting for parallel documentation also affect the minimal
> amount of memory?
I'm currently working on that too ! We should aim to have #6495 in Sage as
soon as possible. From what concerns compile time, using some more
improvement, I cut down the compile time of the ref man in a little more that
10 min on my laptop (a fast I7 2Gh, 8GB).
> Otherwise we still will increase the compile time,
> increase the size, and increase the memory requirements, just do it
> slower by adding new regular methods, it is just a matter of time.
> Hitting LaTeX limits on http://trac.sagemath.org/sage_trac/ticket/9128
> was the same issue - it surfaces when we improve documentation, but if
> we don't do it - the issue is not going away, it just remains
> submerged for a few more months.
+1
> I had people asking me how to check if an element is in a set and
> complaining that it is not written in the documentation. Well, the
> reasonable search on a doc page is for "contains" and if
> "__contains__" was included, it would show up. It may be obvious to
> people on this list that this is the case and that it is easy to look
> at the source code, but that can be quite different for new or just
> "non-developing" users.
+1 too
Florent