-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
src/sage/interfaces/singular.py: use GNU Info to read Singular's info #38899
src/sage/interfaces/singular.py: use GNU Info to read Singular's info #38899
Conversation
Documentation preview for this PR (built with commit 0275387; changes) is ready! 🎉 |
4314aa8
to
69e8efd
Compare
You should just be able to run Can you please run |
No, but I think it may be the case with info 6.x. If so, I'll need to handle that. |
I updated both the feature and the |
$ sage -sh
Starting subshell with Sage environment variables set. Don't forget
to exit when you are done. Beware:
* Do not do anything with other copies of Sage on your system.
* Do not use this for installing Sage packages using "sage -i" or for
running "make" at Sage's root directory. These should be done
outside the Sage shell.
Bypassing shell configuration files...
Note: SAGE_ROOT=/home/kwankyu/GitHub/sage-dev
(sage-sh) kwankyu@HOME:sage-dev$ info --version
info (GNU texinfo) 7.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
(sage-sh) kwankyu@HOME:sage-dev$ which info
/usr/bin/info I am testing on Ubuntu on WSL There is nothing changed with your updated branch. I will force sage to build the info spkg... |
sage: !info --version
info (GNU texinfo) 7.0.3
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
sage: from sage.interfaces.singular import get_docstring
sage: get_docstring('Preface')
'\n1 Preface\n*********\n\n SINGULAR version 4.4.0\n University of Kaiserslautern-Landau\n Department of Mathematics and Centre for Computer Algebra\n Authors: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann\n\n Copyright (C) 1986-2024\n\n\n *NOTICE*\n\nThis program is free software; you can redistribute it and/or modify it\nunder the terms of the GNU General Public License as published by the\nFree Software Foundation (version 2 or version 3 of the License).\n\nSome single files have a copyright given within the file:\nSingular/links/ndbm.* (BSD)\n\nThe following software modules shipped with SINGULAR have their own\ncopyright: the omalloc library, the readline library, the GNU Multiple\nPrecision Library (GMP), NTL: A Library for doing Number Theory (NTL),\nFlint: Fast Library for Number Theory, the Singular-Factory library, the\nSingular-Factory library, the Singular-libfac library, surfex, and, for\nthe Windows distributions, the Cygwin DLL and the Cygwin tools\n(Cygwin), and the XEmacs editor (XEmacs).\n\nTheir copyrights and licenses can be found in the accompanying files\nCOPYING which are distributed along with these packages. (Since\nversion 3-0-3 of SINGULAR, al
...
sage: singular.aliggggg?
Signature: singular.aliggggg(*args, **kwds)
Type: SingularFunction
String form: aliggggg
File: ~/GitHub/sage-dev/src/sage/interfaces/singular.py
Docstring:
This function is an automatically generated pexpect wrapper around the
Singular function 'aliggggg'.
EXAMPLES:
sage: groebner = singular.groebner
sage: P.<x, y> = PolynomialRing(QQ)
sage: I = P.ideal(x^2-y, y+x)
sage: groebner(singular(I))
x+y,
y^2-y
Init docstring:
WARNING: the enclosing module is marked 'needs sage.libs.gap sage.libs.pari sage.libs.singular sage.symbolic',
so doctests may not pass.
Call docstring:
WARNING: the enclosing module is marked 'needs sage.libs.gap sage.libs.pari sage.libs.singular sage.symbolic',
so doctests may not pass. Nothing changed.... |
Argh, OK, I see the problem. When I updated the PR to trust the exit code from |
d07e649
to
4e79070
Compare
I've added back the check for the section header to ensure that I also tried to fix the In any case,
should raise an error. |
Before we can replace our hand-rolled parser for Singular's info file, we need to be able to detect the "info" program from the GNU Info package. The goal is to politely disable access to Singular's info if GNU Info is unavailable. This avoids a hard dependency on GNU Info in the sage library. We require v7 or later because a bugfix in Texinfo v7.0.0 corrects the exit code from "info" when the requested node is not found. This allows us to separate the "expected failures" from the truly unexpected ones.
Our Singular interface currently contains a hand-written parser for Singular's "info" file. This commit eliminates the custom parser in favor of launching GNU Info. GNU Info (or its superset, Texinfo) are widespread, portable, and easy to install on all of the systems we support, so in most cases this should be a "free" improvement. The hand-written parser has several drawbacks: * The extra code is a maintenance burden. We should not be wasting our time reimplementing standard tools. * The custom parser is buggy. For example, it is supposed to raise a KeyError when documentation for a non-existent function is requested. However, the parser does not keep track of what section it's in, so, for example, get_docstring("Preface") returns the contents of the preface even though "Preface" is not a Singular function. * The first time documentation is requested, the entire info file is loaded into a dictionary. This wastes a few megabytes of memory for the duration of the Sage session. * The custom parser does not handle compression (GNU Info does transparently), and the end user or people packaging Singular may not be aware of that. If the system installation of Singular has a compressed info file, Sage won't be able to read it. For contrast, the one downside to using GNU Info is that it adds a new runtime dependency to sagelib. To mitigate that, we do not technically require it, and instead raise a warning if the user (a) tries to read the Singular documentation and (b) has managed to find a system without GNU Info. Our singular_console() itself tries to launch GNU Info to display its interactive help, so the additional optional dependency is not so additional except in corner cases, such as a pypi installation of a subset of Sage linked against libsingular but without a full Singular install.
The rewritten get_docstring() in sage.interfaces.singular supports formatting the output as reStructuredText, so we no longer need to do it "by hand" in the library interface.
…atted Our _sage_getdoc_unformatted() catches all exceptions and turns them into the empty string. The side effects of this are pretty bad: this function is used to generate the help? strings in the sage REPL, and if something goes wrong, the user will get a confusing blank docstring rather than the error. The change was introduced in issue 19671 as a workaround for a runtime error raised inside flask. But we are no longer using flask, and hopefully no other parts of the Sage library raise an exception during the documentation build. We are about to find out!
4e79070
to
d52b5e5
Compare
These modules use singular_function() from sage.libs.singular.function to create top-level aliases for a few singular functions. The docbuild however tries to build documentation for these functions, and it can raise an error if GNU info is not installed. There's no good reason to define them globally in the first place (they are only used locally), so an easy fix is to move the imports and variables local.
d52b5e5
to
5f8f525
Compare
It's looking like it might be OK now:
|
Thanks. It now works nicely, both with spkg info (7.0.3) and system info (7.1). One anomaly I noticed: for this input
I get
Completing "ali" to "align" is nice, but I think the documentation should show "align" instead of "ali". But to be fair, this anomaly is not new. Let me know if you would fix it or leave it. |
Some strange thing is happening in documentation: |
I don't think this will be easy to fix. The problem is that The thing that I could fix here is that |
This is probably something a singular expert should look in to, but I think the names of the built-in singular functions can be obtained from the list returned by |
It looks like the OUTPUT block for singular_version() was copy/pasted from somewhere else -- it doesn't make sense. We delete it; the remaining short description of this function is sufficient.
That was literally the docstring for |
OK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now. Thanks.
Would you add "Fixes #32242" in the PR description? |
Done, thank you for the careful review |
…ad Singular's info Our Singular interface currently contains a hand-written parser for Singular's "info" file. This commit eliminates the custom parser in favor of launching GNU Info. GNU Info (or its superset, Texinfo) are widespread, portable, and easy to install on all of the systems we support, so in most cases this should be a "free" improvement. The hand-written parser has several drawbacks: * The extra code is a maintenance burden. We should not be wasting our time reimplementing standard tools. * The custom parser is buggy. For example, it is supposed to raise a KeyError when documentation for a non-existent function is requested. However, the parser does not keep track of what section it's in, so, for example, get_docstring("Preface") returns the contents of the preface even though "Preface" is not a Singular function. * The first time documentation is requested, the entire info file is loaded into a dictionary. This wastes a few megabytes of memory for the duration of the Sage session. * The custom parser does not handle compression (GNU Info does transparently), and the end user or people packaging Singular may not be aware of that. If the system installation of Singular has a compressed info file, Sage won't be able to read it. For contrast, the one downside to using GNU Info is that it adds a new runtime dependency to sagelib. To mitigate that, we do not technically require it, and instead raise a warning if the user (a) tries to read the Singular documentation and (b) has managed to find a system without GNU Info. Our singular_console() itself tries to launch GNU Info to display its interactive help, so the additional optional dependency is not so additional except in corner cases, such as a pypi installation of a subset of Sage linked against libsingular but without a full Singular install. This was originally sagemath#32242 Since then, * GNU Info has become a standard package in the sage distribution * I'm now using `sage.features.info` to detect the "info" program, so nothing bad happens if it's not installed Fixes sagemath#32242 URL: sagemath#38899 Reported by: Michael Orlitzky Reviewer(s): Kwankyu Lee, Michael Orlitzky
Our Singular interface currently contains a hand-written parser for Singular's "info" file. This commit eliminates the custom parser in favor of launching GNU Info. GNU Info (or its superset, Texinfo) are widespread, portable, and easy to install on all of the systems we support, so in most cases this should be a "free" improvement.
The hand-written parser has several drawbacks:
For contrast, the one downside to using GNU Info is that it adds a new runtime dependency to sagelib. To mitigate that, we do not technically require it, and instead raise a warning if the user (a) tries to read the Singular documentation and (b) has managed to find a system without GNU Info. Our singular_console() itself tries to launch GNU Info to display its interactive help, so the additional optional dependency is not so additional except in corner cases, such as a pypi installation of a subset of Sage linked against libsingular but without a full Singular install.
This was originally #32242
Since then,
sage.features.info
to detect the "info" program, so nothing bad happens if it's not installedFixes #32242