simon-git: spigot (master): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sat Oct 7 18:07:31 BST 2017
TL;DR:
6eebe12 Reorganise scope management in Python module.
7b180b1 Export all the expr.cpp function names in Python.
f635efa Fix embarrassing bug in Python float->spigot conversion.
0071e57 Standardise on argparse in the Python demo programs.
472116e Sensible Python interface to the base formatter.
6c303e2 Expose the rounding-mode enumeration in Python.
151dd2d Namespace-sanitise the Python spigot internals.
Repository: https://git.tartarus.org/simon/spigot.git
On the web: https://git.tartarus.org/?p=simon/spigot.git
Branch updated: master
Committer: Simon Tatham <anakin at pobox.com>
Date: 2017-10-07 18:07:31
commit 6eebe122dfb45c1072b37441f025b4b41abaed44
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=6eebe122dfb45c1072b37441f025b4b41abaed44;hp=366ff2fa1b8456d4b28a1c4fc4c408d97219bd26
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 15:28:24 2017 +0100
Reorganise scope management in Python module.
Previously, the C side of the spigot/Python integration was falling
back through several possible kinds of scope argument that might have
been given to the parse method. Now all of that is done on the Python
side, and the C part is simplified right down so that it simply
expects an object it can treat as a mapping, and moreover, that object
is expected to return the internal C spigot type and not the Python
wrapper. (Also, I've filled in the missing TypeErrors if one of those
things failed to happen.)
User-level code can still pass all the previous kinds of scope to the
constructor of the outer Spigot class - a mapping, a function, or a
list of mapping-or-function objects to be checked in priority order -
hopefully without noticing any difference. It's just that now, sorting
out all those possibilities is done on the Python side, and by the
time control goes over to the C side, a wrapper class with a custom
__getitem__ method will have been wrapped around the user's scope
argument to hide all that complexity.
The useful effect of all this is that in the course of cleaning it up
I've also arranged that user-provided scopes don't _have_ to return
Spigot objects as the result of a variable lookup. Instead, they're
allowed to return floating or integer types, which will be
automatically converted into spigots. This lets me remove a lot of
tedious boilerplate not only from the test collection, but also from a
lot of the operator implementations within the (outer) Spigot class
itself!
python/mediant.py | 10 +++----
python/powbegin.py | 17 +++++-------
python/pyspig.cpp | 50 ++++++++--------------------------
python/pythangle.py | 3 +--
python/setup.py | 3 ++-
python/spig/__init__.py | 72 +++++++++++++++++++++++--------------------------
python/test.py | 2 +-
7 files changed, 59 insertions(+), 98 deletions(-)
commit 7b180b1d687a6cff72d8fd70de6df28bf517085e
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=7b180b1d687a6cff72d8fd70de6df28bf517085e;hp=6eebe122dfb45c1072b37441f025b4b41abaed44
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 17:57:17 2017 +0100
Export all the expr.cpp function names in Python.
Now you don't _have_ to access spigot's collection of mathematical
functions via the string-parsing API; you can directly write things
like 'for term in spigot.pi.continued_fraction()', or 'print
float(spigot.tan(10**100))'.
(But beware, of course, that spigot.tan(1e100) will not give the same
answer, because there's nothing the spigot Python bindings can do
about the fact that Python will _already_ have rounded 1e100 to the
nearest IEEE double before passing it to them.)
Internally, this is still all done using the string parsing system,
but that's an implementation detail that shouldn't be important (or,
with any luck, even visible) to user code.
expr.cpp | 16 ++++++++++++++++
expr.h | 10 ++++++++++
python/mediant.py | 6 +++---
python/powbegin.py | 3 ++-
python/pyspig.cpp | 11 +++++++++++
python/spig/__init__.py | 42 ++++++++++++++++++++++++++++++++++++++++++
python/test.py | 9 +++++----
7 files changed, 89 insertions(+), 8 deletions(-)
commit f635efa28a50a70b25b32ecf0b1135cdbc049b03
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=f635efa28a50a70b25b32ecf0b1135cdbc049b03;hp=7b180b1d687a6cff72d8fd70de6df28bf517085e
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 17:57:24 2017 +0100
Fix embarrassing bug in Python float->spigot conversion.
When given an object of float type to turn into a spigot, I was
ignoring its actual value and always converting 1.0 instead. Ahem.
python/spig/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
commit 0071e57673125bfb6f62d2010b9563ea82facdc4
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=0071e57673125bfb6f62d2010b9563ea82facdc4;hp=f635efa28a50a70b25b32ecf0b1135cdbc049b03
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 17:16:43 2017 +0100
Standardise on argparse in the Python demo programs.
On balance I'm preferring it to the getopt approach these days, in
spite of occasional annoyances like the difficulty of making arguments
optional if a particular option is provided (like I had to do manually
in powbegin). But it enforces that I don't forget the help for any
option, and more conveniently separates the command-line parsing from
the underlying doing-of-stuff.
python/powbegin.py | 102 ++++++++++++++++++++++++++--------------------------
python/pythangle.py | 98 ++++++++++++++++++++++++--------------------------
2 files changed, 98 insertions(+), 102 deletions(-)
commit 472116edc3d3f9500aaffdd63369d3c903b0d13e
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=472116edc3d3f9500aaffdd63369d3c903b0d13e;hp=0071e57673125bfb6f62d2010b9563ea82facdc4
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 17:35:14 2017 +0100
Sensible Python interface to the base formatter.
Now pythangle.py doesn't have to use the internal 'sp' field of its
spigot objects.
python/pyspig.cpp | 2 +-
python/pythangle.py | 9 +--------
python/spig/__init__.py | 28 ++++++++++++++++++++++++++++
python/test.py | 11 ++---------
4 files changed, 32 insertions(+), 18 deletions(-)
commit 6c303e27b2ac40c91d24d0944b8c64497caa893e
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=6c303e27b2ac40c91d24d0944b8c64497caa893e;hp=472116edc3d3f9500aaffdd63369d3c903b0d13e
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 17:48:07 2017 +0100
Expose the rounding-mode enumeration in Python.
This fixes a long-standing FIXME in the implementation where I had had
to hardcode the numeric value of an element of that enum, and it also
means user code can sensibly ask for the rounding mode it actually
wants.
baseout.h | 55 +++++++++++++++++++++++++------------------------
python/pyspig.cpp | 14 +++++++++++++
python/pythangle.py | 3 ++-
python/spig/__init__.py | 7 +++++--
4 files changed, 49 insertions(+), 30 deletions(-)
commit 151dd2dab217ed0e23af8a486e9b0eaefa5e81ed
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=151dd2dab217ed0e23af8a486e9b0eaefa5e81ed;hp=6c303e27b2ac40c91d24d0944b8c64497caa893e
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 17:49:40 2017 +0100
Namespace-sanitise the Python spigot internals.
Now the spigot.internal module is called spigot._internal throughout,
with that leading underscore to hint that user code shouldn't be
messing about with it. Also I've imported it with a sensible name in
the outer Python wrapper so that you don't have the slightly odd
'spigot.spigot.internal' that used to exist.
While I'm here, I've also renamed the 'sp' field of the outer wrapper
class to _sp, just to catch anything that was still using it outside
the implementation.
python/pyspig.cpp | 6 +++---
python/setup.py | 2 +-
python/spig/__init__.py | 42 +++++++++++++++++++++---------------------
3 files changed, 25 insertions(+), 25 deletions(-)
More information about the tartarus-commits
mailing list