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

Commit abb5607

Browse files
embrayMatthias Koeppe
authored andcommitted
Allow Sage to work with a system Python 3.6.
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.
1 parent 860e4dc commit abb5607

File tree

8 files changed

+30
-18
lines changed

8 files changed

+30
-18
lines changed

build/bin/sage-spkg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
#*****************************************************************************
6969

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

7375
usage()
7476
{

build/pkgs/python3/spkg-configure.m4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ SAGE_SPKG_CONFIGURE([python3], [
1010
dnl Using Python 3 for Sage. Check if we can do venv with a system python3
1111
dnl instead of building our own copy.
1212
check_modules="sqlite3, ctypes, math, hashlib, crypt, readline, socket, zlib, distutils.core"
13-
AC_CACHE_CHECK([for python3 >= 3.7.3, < 3.8 with modules $check_modules], [ac_cv_path_PYTHON3], [
13+
AC_CACHE_CHECK([for python3 >= 3.6, < 3.8 with modules $check_modules], [ac_cv_path_PYTHON3], [
1414
AC_MSG_RESULT([])
15-
AC_PATH_PROGS_FEATURE_CHECK([PYTHON3], [python3.7 python3], [
15+
AC_PATH_PROGS_FEATURE_CHECK([PYTHON3], [python3.7 python3.6 python3], [
1616
AC_MSG_CHECKING([... whether $ac_path_PYTHON3 is good])
1717
python3_version=`"$ac_path_PYTHON3" --version 2>&1 \
1818
| $SED -n -e 's/\([[0-9]]*\.[[0-9]]*\.[[0-9]]*\).*/\1/p'`
1919
AS_IF([test -n "$python3_version"], [
20-
AX_COMPARE_VERSION([$python3_version], [ge], [3.7.3], [
20+
AX_COMPARE_VERSION([$python3_version], [ge], [3.6.0], [
2121
AX_COMPARE_VERSION([$python3_version], [lt], [3.8.0], [
2222
dnl Because the system python is not used directly but rather in a venv without site-packages,
2323
dnl we test whether the module will be available in a venv.
@@ -118,7 +118,7 @@ EOF
118118
ac_path_PYTHON3_found=:
119119
AC_MSG_RESULT([yes])
120120
dnl introduction for AC_MSG_RESULT printed by AC_CACHE_CHECK
121-
AC_MSG_CHECKING([for python3 >= 3.7.3, < 3.8 with modules $check_modules])
121+
AC_MSG_CHECKING([for python3 >= 3.6, < 3.8 with modules $check_modules])
122122
], [
123123
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])
124124
])

src/sage/all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
....: 'IPython', 'prompt_toolkit', 'jedi', # sage dependencies
2323
....: 'threading', 'multiprocessing', # doctest dependencies
2424
....: '__main__', 'sage.doctest', # doctesting
25-
....: 'signal', 'enum', # may appear in Python 3
25+
....: 'signal', 'enum', 'types' # may appear in Python 3
2626
....: ]
2727
sage: def is_not_allowed(frame):
2828
....: module = inspect.getmodule(frame)

src/sage/combinat/subset.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,22 @@ def cardinality(self):
357357
"""
358358
return Integer(1) << self._s.cardinality()
359359

360-
__len__ = cardinality
360+
def __len__(self):
361+
r"""
362+
Equivalent to ``self.cardinality()``.
363+
364+
TESTS::
365+
366+
``__len__`` should return a Python int; in Python 3.7+ this happens
367+
automatically, but not on Python 3.6.
368+
369+
sage: S = Subsets(Set([1,2,3]))
370+
sage: len(S)
371+
8
372+
sage: type(len(S)) is int
373+
True
374+
"""
375+
return int(self.cardinality())
361376

362377
def first(self):
363378
"""

src/sage/graphs/views.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ cdef class EdgesView:
611611
elif i < 0:
612612
return list(self)[i]
613613
else:
614+
i = int(i) # For Python < 3.7 where islice doesn't support non-int
614615
try:
615616
return next(islice(self, i, i + 1, 1))
616617
except StopIteration:

src/sage/misc/sagedoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ def search_src(string, extra1='', extra2='', extra3='', extra4='',
10641064
sage: print(search_src(" fetch(", "def", interact=False)) # py3
10651065
Traceback (most recent call last):
10661066
...
1067-
re.error: missing ), unterminated subpattern at position 6
1067+
error: missing ), unterminated subpattern at position 6
10681068
10691069
To fix this, *escape* the parenthesis with a backslash::
10701070

src/sage/misc/sageinspect.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,10 +1724,8 @@ def sage_formatargspec(args, varargs=None, varkw=None, defaults=None,
17241724
sage: defaults = [3]
17251725
sage: sage_formatargspec(args, defaults=defaults)
17261726
'(a, b, c=3)'
1727-
sage: formatargspec(args, defaults=defaults) == sage_formatargspec(args, defaults=defaults) # py2
1728-
True
1729-
sage: formatargspec(args, defaults=defaults) == sage_formatargspec(args, defaults=defaults) # py3
1730-
doctest:...: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
1727+
sage: import warnings; warnings.simplefilter('ignore') # py3: ignore DeprecationWarning
1728+
sage: formatargspec(args, defaults=defaults) == sage_formatargspec(args, defaults=defaults)
17311729
True
17321730
"""
17331731
def formatargandannotation(arg):

src/sage/symbolic/expression.pyx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5869,14 +5869,10 @@ cdef class Expression(CommutativeRingElement):
58695869
58705870
Indexing directly with ``t[1]`` causes problems with numpy types.
58715871
5872-
sage: t[1] # py2
5872+
sage: t[1]
58735873
Traceback (most recent call last):
58745874
...
5875-
TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
5876-
sage: t[1] # py3
5877-
Traceback (most recent call last):
5878-
...
5879-
TypeError: 'sage.symbolic.expression.Expression' object is not subscriptable
5875+
TypeError: 'sage.symbolic.expression.Expression' object ...
58805876
"""
58815877
if (is_a_symbol(self._gobj) or is_a_constant(self._gobj) or
58825878
is_a_numeric(self._gobj)):

0 commit comments

Comments
 (0)