Skip to content

Commit

Permalink
sagemathgh-36983: Prepare python3 spkg-configure.m4 for Python 3.12…
Browse files Browse the repository at this point in the history
… (setuptools instead of distutils)

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

- Cherry-picked from sagemath#36181

This PR does not change what versions are accepted!
To test with Python 3.12, still need to adjust the version bound set in
`build/pkgs/python3/spkg-configure.m4`.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->
- Depends on sagemath#36957 (merged here to resolve merge conflict)

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36983
Reported by: Matthias Köppe
Reviewer(s): Gonzalo Tornaría, Matthias Köppe
  • Loading branch information
Release Manager committed Feb 11, 2024
2 parents 20a6fde + 0e54d2c commit 647ec81
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 17 deletions.
1 change: 0 additions & 1 deletion build/pkgs/_python3.12/distros/debian.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
python3.12
python3.12-dev
python3.12-distutils
python3.12-venv
9 changes: 4 additions & 5 deletions build/pkgs/python3/SPKG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ By default, Sage will try to use system's ``python3`` to set up a virtual
environment, a.k.a. `venv <https://docs.python.org/3.10/library/venv.html>`_
rather than building a Python 3 installation from scratch.

Sage will accept versions 3.9.x to 3.10.x.
Sage will accept versions 3.9.x to 3.11.x.

You can also use ``--with-python=/path/to/python3_binary`` to tell Sage to use
``/path/to/python3_binary`` to set up the venv. Note that setting up the venv requires
a number of Python modules to be available within the Python in question. Currently,
as of Sage 9.7, these modules are as follows: ``sqlite3``, ``ctypes``, ``math``,
``hashlib``, ``socket``, ``zlib``, ``distutils.core``, ``ssl`` -
they will be checked for by the ``configure`` script.
as of Sage 10.3, these modules are as follows: ``sqlite3``, ``ctypes``, ``math``,
``hashlib``, ``socket``, ``zlib``, ``ssl``, ``ensurepip``.

Use the ``configure`` option ``--without-system-python3`` in case you want Python 3
Use the ``configure`` option ``--without-system-python3`` if you want Python 3
built from scratch.


Expand Down
1 change: 1 addition & 0 deletions build/pkgs/python3/distros/alpine.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python3-dev
py3-setuptools
2 changes: 1 addition & 1 deletion build/pkgs/python3/distros/debian.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
python3
libpython3-dev
python3-distutils
python3-setuptools
python3-venv
1 change: 1 addition & 0 deletions build/pkgs/python3/distros/fedora.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python3-devel
python-setuptools
1 change: 1 addition & 0 deletions build/pkgs/python3/distros/freebsd.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lang/python
devel/py-setuptools
1 change: 1 addition & 0 deletions build/pkgs/python3/distros/homebrew.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# This installs /usr/local/bin/python3 -> python3.9
python3
python-setuptools
1 change: 1 addition & 0 deletions build/pkgs/python3/distros/macports.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python310
py-setuptools
1 change: 1 addition & 0 deletions build/pkgs/python3/distros/opensuse.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python3${PYTHON_MINOR}-devel
python3${PYTHON_MINOR}-setuptools
1 change: 1 addition & 0 deletions build/pkgs/python3/distros/void.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python3-devel
python3-setuptools
6 changes: 3 additions & 3 deletions build/pkgs/python3/spkg-configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ SAGE_SPKG_CONFIGURE([python3], [
dnl Check if we can do venv with a system python3
dnl instead of building our own copy.
dnl Trac #31160: We no longer check for readline here.
check_modules="sqlite3, ctypes, math, hashlib, socket, zlib, distutils.core, ssl, ensurepip"
AC_CACHE_CHECK([for python3 >= ]MIN_VERSION[, < ]LT_VERSION[ with modules $check_modules], [ac_cv_path_PYTHON3], [
check_modules="sqlite3, ctypes, math, hashlib, socket, zlib, ssl, ensurepip"
AC_CACHE_CHECK([for python3 >= ]MIN_VERSION[, < ]LT_VERSION[ with modules $check_modules and setuptools/distutils], [ac_cv_path_PYTHON3], [
AS_IF([test x"$ac_path_PYTHON3" != x], [dnl checking explicitly specified $with_python
AC_MSG_RESULT([])
AC_PATH_PROG([ac_path_PYTHON3], [$ac_path_PYTHON3])
Expand All @@ -40,7 +40,7 @@ SAGE_SPKG_CONFIGURE([python3], [
ac_path_PYTHON3_found=:
AC_MSG_RESULT([yes])
dnl introduction for AC_MSG_RESULT printed by AC_CACHE_CHECK
AC_MSG_CHECKING([for python3 >= ]MIN_VERSION[, < ]LT_VERSION[ with modules $check_modules])
AC_MSG_CHECKING([for python3 >= ]MIN_VERSION[, < ]LT_VERSION[ with modules $check_modules and setuptools/distutils])
])
AS_IF([test -z "$ac_cv_path_PYTHON3"], [
AC_MSG_ERROR([the python3 selected using --with-python=$with_python is not suitable])
Expand Down
28 changes: 21 additions & 7 deletions m4/sage_check_python_for_venv.m4
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@ AC_DEFUN([SAGE_CHECK_PYTHON_FOR_VENV], [
AX_COMPARE_VERSION([$python3_version], [ge], MIN_VERSION, [
AX_COMPARE_VERSION([$python3_version], [lt], LT_VERSION, [
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.
dnl we should test whether the module will be available in a venv.
dnl Otherwise, some system site-package may be providing this module to the system python.
dnl However, on Python >= 3.12, we need setuptools to run our extension compilation tests
dnl because distutils has been removed from the standard library.
AX_COMPARE_VERSION([$python3_version], [ge], [3.12.0], [
conftest_venv_options="--system-site-packages"
distutils_core="setuptools"
distutils_extension="setuptools.extension"
], [
conftest_venv_options=
distutils_core="distutils.core"
distutils_extension="distutils.extension"
])
all_required_modules="]REQUIRED_MODULES[, $distutils_core, $distutils_extension"
dnl m4_define([conftest_venv], [config-venv]) .... for debugging only
rm -rf conftest_venv
AS_IF(["]PYTHON_EXE[" build/bin/sage-venv conftest_venv && conftest_venv/bin/python3 -c "import ]REQUIRED_MODULES[" 2>& ]AS_MESSAGE_LOG_FD, [
AS_IF(["]PYTHON_EXE[" build/bin/sage-venv $conftest_venv_options conftest_venv && conftest_venv/bin/python3 -c "import $all_required_modules" 2>& ]AS_MESSAGE_LOG_FD, [
AS_VAR_SET([python3_result], [yes])
SAGE_PYTHON_CHECK_DISTUTILS([CC="$CC" CXX="$CXX" conftest_venv/bin/python3], [
SAGE_ARCHFLAGS="unset"
Expand All @@ -46,7 +58,7 @@ AC_DEFUN([SAGE_CHECK_PYTHON_FOR_VENV], [
AC_MSG_RESULT([$python3_result])
])
], [
AC_MSG_RESULT([no, the version is in the supported range but cannot import one of the required modules: ]REQUIRED_MODULES)
AC_MSG_RESULT([no, the version is in the supported range but cannot import one of the required modules: $all_required_modules])
])
], [
AC_MSG_RESULT([no, $python3_version is too recent])
Expand Down Expand Up @@ -123,8 +135,9 @@ PyInit_spam(void)
])
AC_LANG_POP([C])
cat > conftest.py <<EOF
from distutils.core import setup
from distutils.extension import Extension
from $distutils_core import setup
from $distutils_extension import Extension
from sys import exit
modules = list((Extension("config_check_distutils", list(("conftest.c",))),))
setup(name="config_check_distutils", ext_modules=modules)
Expand Down Expand Up @@ -176,8 +189,9 @@ PyInit_spam(void)
])
AC_LANG_POP([C++])
cat > conftest.py <<EOF
from distutils.core import setup
from distutils.extension import Extension
from $distutils_core import setup
from $distutils_extension import Extension
from sys import exit
modules = list((Extension("config_check_distutils_cxx", list(("conftest.cpp",)),
extra_compile_args=list(("-std=c++11",)), language="c++"),))
Expand Down

0 comments on commit 647ec81

Please sign in to comment.