From 8b0cbaca9015e2a0a5c83fcba9626a50a2e767e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 20 Nov 2023 11:50:50 +0100 Subject: [PATCH] Fix FTBFS with Python 3.13.0a1+ Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2247014 Co-Authored-By: Karolina Surma --- don-t-use-the-removed-importlib.patch | 64 +++++++++++++++++++++++++++ numpy.spec | 18 +++++++- replace-deprecated-ctypes.ARRAY.patch | 28 ++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 don-t-use-the-removed-importlib.patch create mode 100644 replace-deprecated-ctypes.ARRAY.patch diff --git a/don-t-use-the-removed-importlib.patch b/don-t-use-the-removed-importlib.patch new file mode 100644 index 0000000..6eaa5ab --- /dev/null +++ b/don-t-use-the-removed-importlib.patch @@ -0,0 +1,64 @@ +From 7ade3828313dd437f4e2176ccbbc1ef52322de15 Mon Sep 17 00:00:00 2001 +From: Ralf Gommers +Date: Fri, 20 Oct 2023 17:29:26 +0200 +Subject: [PATCH] Stop using removed `importlib.resources` functions on Python + >=3.13 + +Closes gh-12401 +--- + vendored-meson/meson/mesonbuild/dependencies/python.py | 8 +++++++- + vendored-meson/meson/mesonbuild/modules/python.py | 7 +++++-- + 2 files changed, 12 insertions(+), 3 deletions(-) + +diff --git a/vendored-meson/meson/mesonbuild/dependencies/python.py b/vendored-meson/meson/mesonbuild/dependencies/python.py +index 1607728883df..186a6830ddbf 100644 +--- a/vendored-meson/meson/mesonbuild/dependencies/python.py ++++ b/vendored-meson/meson/mesonbuild/dependencies/python.py +@@ -15,6 +15,7 @@ + + import functools, json, os, textwrap + from pathlib import Path ++import sys + import typing as T + + from .. import mesonlib, mlog +@@ -110,8 +111,13 @@ def sanity(self) -> bool: + # Sanity check, we expect to have something that at least quacks in tune + + import importlib.resources ++ if sys.version_info >= (3, 13): ++ traversable = importlib.resources.files('mesonbuild.scripts').joinpath('python_info.py') ++ context_mgr = importlib.resources.as_file(traversable) ++ else: ++ context_mgr = importlib.resources.path('mesonbuild.scripts', 'python_info.py') + +- with importlib.resources.path('mesonbuild.scripts', 'python_info.py') as f: ++ with context_mgr as f: + cmd = self.get_command() + [str(f)] + p, stdout, stderr = mesonlib.Popen_safe(cmd) + +diff --git a/vendored-meson/meson/mesonbuild/modules/python.py b/vendored-meson/meson/mesonbuild/modules/python.py +index ac74e13dc5b7..baeb85936614 100644 +--- a/vendored-meson/meson/mesonbuild/modules/python.py ++++ b/vendored-meson/meson/mesonbuild/modules/python.py +@@ -13,7 +13,7 @@ + # limitations under the License. + from __future__ import annotations + +-import copy, json, os, shutil ++import copy, json, os, shutil, sys + import typing as T + + from . import ExtensionModule, ModuleInfo +@@ -329,7 +329,10 @@ def should_append(f, isdir: bool = False): + import importlib.resources + pycompile = os.path.join(self.interpreter.environment.get_scratch_dir(), 'pycompile.py') + with open(pycompile, 'wb') as f: +- f.write(importlib.resources.read_binary('mesonbuild.scripts', 'pycompile.py')) ++ if sys.version_info >= (3, 13): ++ f.write(importlib.resources.files('mesonbuild.scripts').joinpath('pycompile.py').read_bytes()) ++ else: ++ f.write(importlib.resources.read_binary('mesonbuild.scripts', 'pycompile.py')) + + for i in self.installations.values(): + if isinstance(i, PythonExternalProgram) and i.run_bytecompile[i.info['version']]: diff --git a/numpy.spec b/numpy.spec index 10b1e76..f7162e0 100644 --- a/numpy.spec +++ b/numpy.spec @@ -32,6 +32,13 @@ Source1: https://numpy.org/doc/%(echo %{version} | cut -d. -f1-2)/numpy-h Patch0: f2py_test.patch Patch1: 24772.patch Patch2: 24776.patch +# Python 3.13: Patch vendored meson to work around the removed functions from importlib.resources +# Upstream commit: https://github.com/numpy/meson/commit/7ade3828313dd437f4e2176ccbbc1ef52322de15 +Patch3: don-t-use-the-removed-importlib.patch +# Python 3.13: Replace deprecated ctypes.ARRAY(item_type, size) with item_type * size +# Upstream PR: https://github.com/numpy/numpy/pull/25198 +Patch4: replace-deprecated-ctypes.ARRAY.patch + %description NumPy is a general-purpose array-processing package designed to @@ -109,6 +116,10 @@ This package provides the complete documentation for NumPy. %prep %autosetup -n %{name}-%{version} -p1 +# Enable build with Python 3.13 +# See: https://github.com/numpy/numpy/commit/82d7657ce39c97fcfd86e1a5acee8b5d00682169 +sed -i 's/requires-python = ">=3.9,<3.13"/requires-python = ">=3.9"/' pyproject.toml + # openblas is provided by flexiblas by default; otherwise, # Use openblas pthreads as recommended by upstream (see comment in site.cfg.example) cat >> site.cfg <= v"3.13" +%global py313_k and not test_deprecate_help_indentation and not test_deprecate_preserve_whitespace +%endif %ifnarch %{ix86} -python3 runtests.py --no-build -- -ra -k 'not test_ppc64_ibm_double_double128 %{?ix86_k}' \ +python3 runtests.py --no-build -- -ra -k 'not test_ppc64_ibm_double_double128 %{?ix86_k} %{?py313_k}' \ -W "ignore:pkg_resources is deprecated as an API::pkg_resources" %endif diff --git a/replace-deprecated-ctypes.ARRAY.patch b/replace-deprecated-ctypes.ARRAY.patch new file mode 100644 index 0000000..53330f9 --- /dev/null +++ b/replace-deprecated-ctypes.ARRAY.patch @@ -0,0 +1,28 @@ +From d9155244ea06705ebd9194cc7a621e82316b61ba Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= +Date: Mon, 20 Nov 2023 11:36:36 +0100 +Subject: [PATCH] MAINT: Replace deprecated ctypes.ARRAY(item_type, size) with + item_type * size + +See https://github.com/python/cpython/issues/105733 +--- + numpy/core/tests/test_ufunc.py | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py +index a7401ff616f..fc1fd5af169 100644 +--- a/numpy/core/tests/test_ufunc.py ++++ b/numpy/core/tests/test_ufunc.py +@@ -2985,9 +2985,9 @@ def test_resolve_dtypes_reduction_errors(self): + reason="`ctypes.pythonapi` required for capsule unpacking.") + def test_loop_access(self): + # This is a basic test for the full strided loop access +- data_t = ct.ARRAY(ct.c_char_p, 2) +- dim_t = ct.ARRAY(ct.c_ssize_t, 1) +- strides_t = ct.ARRAY(ct.c_ssize_t, 2) ++ data_t = ct.c_char_p * 2 ++ dim_t = ct.c_ssize_t * 1 ++ strides_t = ct.c_ssize_t * 2 + strided_loop_t = ct.CFUNCTYPE( + ct.c_int, ct.c_void_p, data_t, dim_t, strides_t, ct.c_void_p) +