Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Allow Sage to work with a system Python 3.6.
Browse files Browse the repository at this point in the history
Currently sage-the-distribution is tested against a minimum of Python
3.7, but we can support more system Pythons by supporting down to 3.6
with some minimal fixes to tests.
  • Loading branch information
embray authored and mkoeppe committed Jun 5, 2020
1 parent 860e4dc commit abb5607
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
4 changes: 3 additions & 1 deletion build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
#*****************************************************************************

# Avoid surprises with character ranges [a-z] in regular expressions
export LC_ALL=C
# See Trac #15791; some locales can produce different results for
# character ranges (use C.UTF-8 to ensure UTF-8 default encoding in Python)
export LC_ALL=C.UTF-8

usage()
{
Expand Down
8 changes: 4 additions & 4 deletions build/pkgs/python3/spkg-configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ SAGE_SPKG_CONFIGURE([python3], [
dnl Using Python 3 for Sage. Check if we can do venv with a system python3
dnl instead of building our own copy.
check_modules="sqlite3, ctypes, math, hashlib, crypt, readline, socket, zlib, distutils.core"
AC_CACHE_CHECK([for python3 >= 3.7.3, < 3.8 with modules $check_modules], [ac_cv_path_PYTHON3], [
AC_CACHE_CHECK([for python3 >= 3.6, < 3.8 with modules $check_modules], [ac_cv_path_PYTHON3], [
AC_MSG_RESULT([])
AC_PATH_PROGS_FEATURE_CHECK([PYTHON3], [python3.7 python3], [
AC_PATH_PROGS_FEATURE_CHECK([PYTHON3], [python3.7 python3.6 python3], [
AC_MSG_CHECKING([... whether $ac_path_PYTHON3 is good])
python3_version=`"$ac_path_PYTHON3" --version 2>&1 \
| $SED -n -e 's/\([[0-9]]*\.[[0-9]]*\.[[0-9]]*\).*/\1/p'`
AS_IF([test -n "$python3_version"], [
AX_COMPARE_VERSION([$python3_version], [ge], [3.7.3], [
AX_COMPARE_VERSION([$python3_version], [ge], [3.6.0], [
AX_COMPARE_VERSION([$python3_version], [lt], [3.8.0], [
dnl Because the system python is not used directly but rather in a venv without site-packages,
dnl we test whether the module will be available in a venv.
Expand Down Expand Up @@ -118,7 +118,7 @@ EOF
ac_path_PYTHON3_found=:
AC_MSG_RESULT([yes])
dnl introduction for AC_MSG_RESULT printed by AC_CACHE_CHECK
AC_MSG_CHECKING([for python3 >= 3.7.3, < 3.8 with modules $check_modules])
AC_MSG_CHECKING([for python3 >= 3.6, < 3.8 with modules $check_modules])
], [
AC_MSG_RESULT([no, the version is in the supported range, and the modules can be imported, but distutils cannot build a C++ 11 extension])
])
Expand Down
2 changes: 1 addition & 1 deletion src/sage/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
....: 'IPython', 'prompt_toolkit', 'jedi', # sage dependencies
....: 'threading', 'multiprocessing', # doctest dependencies
....: '__main__', 'sage.doctest', # doctesting
....: 'signal', 'enum', # may appear in Python 3
....: 'signal', 'enum', 'types' # may appear in Python 3
....: ]
sage: def is_not_allowed(frame):
....: module = inspect.getmodule(frame)
Expand Down
17 changes: 16 additions & 1 deletion src/sage/combinat/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,22 @@ def cardinality(self):
"""
return Integer(1) << self._s.cardinality()

__len__ = cardinality
def __len__(self):
r"""
Equivalent to ``self.cardinality()``.
TESTS::
``__len__`` should return a Python int; in Python 3.7+ this happens
automatically, but not on Python 3.6.
sage: S = Subsets(Set([1,2,3]))
sage: len(S)
8
sage: type(len(S)) is int
True
"""
return int(self.cardinality())

def first(self):
"""
Expand Down
1 change: 1 addition & 0 deletions src/sage/graphs/views.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ cdef class EdgesView:
elif i < 0:
return list(self)[i]
else:
i = int(i) # For Python < 3.7 where islice doesn't support non-int
try:
return next(islice(self, i, i + 1, 1))
except StopIteration:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/sagedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def search_src(string, extra1='', extra2='', extra3='', extra4='',
sage: print(search_src(" fetch(", "def", interact=False)) # py3
Traceback (most recent call last):
...
re.error: missing ), unterminated subpattern at position 6
error: missing ), unterminated subpattern at position 6
To fix this, *escape* the parenthesis with a backslash::
Expand Down
6 changes: 2 additions & 4 deletions src/sage/misc/sageinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,10 +1724,8 @@ def sage_formatargspec(args, varargs=None, varkw=None, defaults=None,
sage: defaults = [3]
sage: sage_formatargspec(args, defaults=defaults)
'(a, b, c=3)'
sage: formatargspec(args, defaults=defaults) == sage_formatargspec(args, defaults=defaults) # py2
True
sage: formatargspec(args, defaults=defaults) == sage_formatargspec(args, defaults=defaults) # py3
doctest:...: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
sage: import warnings; warnings.simplefilter('ignore') # py3: ignore DeprecationWarning
sage: formatargspec(args, defaults=defaults) == sage_formatargspec(args, defaults=defaults)
True
"""
def formatargandannotation(arg):
Expand Down
8 changes: 2 additions & 6 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5869,14 +5869,10 @@ cdef class Expression(CommutativeRingElement):
Indexing directly with ``t[1]`` causes problems with numpy types.
sage: t[1] # py2
sage: t[1]
Traceback (most recent call last):
...
TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
sage: t[1] # py3
Traceback (most recent call last):
...
TypeError: 'sage.symbolic.expression.Expression' object is not subscriptable
TypeError: 'sage.symbolic.expression.Expression' object ...
"""
if (is_a_symbol(self._gobj) or is_a_constant(self._gobj) or
is_a_numeric(self._gobj)):
Expand Down

0 comments on commit abb5607

Please sign in to comment.