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 committed Jan 17, 2020
1 parent b6b9c3a commit b4a777e
Show file tree
Hide file tree
Showing 9 changed files with 38 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 @@ -64,7 +64,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
@@ -1,14 +1,14 @@
SAGE_SPKG_CONFIGURE([python3], [
SAGE_SPKG_DEPCHECK([sqlite libpng bzip2 xz libffi], [
check_modules="sqlite3, ctypes, math, hashlib, crypt, readline, socket, zlib, distutils.core"
AC_CACHE_CHECK([for python3 >= 3.7, < 3.8 with sqlite3 module], [ac_cv_path_PYTHON3], [
AC_CACHE_CHECK([for python3 >= 3.6, < 3.8 with sqlite3 module], [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.0], [
AX_COMPARE_VERSION([$python3_version], [ge], [3.6.0], [
AX_COMPARE_VERSION([$python3_version], [lt], [3.8.0], [
AS_IF(["$ac_path_PYTHON3" -S -c "import $check_modules"], [
AC_LANG_PUSH([C])
Expand Down Expand Up @@ -51,7 +51,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.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 an extension])
])
Expand Down
8 changes: 8 additions & 0 deletions src/bin/sage-env-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ fi

export SAGE_SYSTEM_PYTHON="@SAGE_SYSTEM_PYTHON@"

if [ -n "$SAGE_SYSTEM_PYTHON" ]; then
# Force LC_CTYPE to a UTF-8 locale to ensure that Python uses UTF-8 by
# default (on Python 3.7+ this is not necessary as UTF-8 is always the
# default encoding, so we only need this if using a system Python that
# is less than 3.7, since Sage's Python is 3.7+)
export LC_CTYPE="C.UTF-8"
fi

# This is usually blank if the system GMP is used, or $SAGE_LOCAL otherwise
export SAGE_GMP_PREFIX="@SAGE_GMP_PREFIX@"
export SAGE_GMP_INCLUDE="@SAGE_GMP_INCLUDE@"
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 @@ -359,7 +359,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 @@ -601,6 +601,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 @@ -1035,7 +1035,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 @@ -1752,10 +1752,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 @@ -5879,14 +5879,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 b4a777e

Please sign in to comment.