Skip to content

Commit

Permalink
Update scipy patch
Browse files Browse the repository at this point in the history
Remove Sulongisms
  • Loading branch information
msimacek committed Aug 28, 2024
1 parent bb7ac57 commit 4e5ec10
Showing 1 changed file with 3 additions and 282 deletions.
285 changes: 3 additions & 282 deletions graalpython/lib-graalpython/patches/scipy/scipy-1.10.1.patch
Original file line number Diff line number Diff line change
@@ -1,139 +1,13 @@
diff --git a/meson.build b/meson.build
index ad18b245..24108760 100644
--- a/meson.build
+++ b/meson.build
@@ -11,7 +11,7 @@ project(
'buildtype=debugoptimized',
'c_std=c99',
'cpp_std=c++14',
- 'fortran_std=legacy',
+ 'fortran_std=none',
'blas=openblas',
'lapack=openblas'
],
@@ -66,6 +66,10 @@ if ff.has_argument('-Wno-conversion')
add_project_arguments('-Wno-conversion', language: 'fortran')
endif

+if ff.has_argument('-fallow-argument-mismatch')
+ add_project_arguments('-fallow-argument-mismatch', language: 'fortran')
+endif
+
is_windows = host_machine.system() == 'windows'

# Intel compilers default to fast-math, so disable it if we detect Intel
diff --git a/mesonpy_wrapper.py b/mesonpy_wrapper.py
new file mode 100644
index 00000000..afa33ecc
--- /dev/null
+++ b/mesonpy_wrapper.py
@@ -0,0 +1,86 @@
+import mesonpy
+import os
+import sys
+from contextlib import contextmanager
+import subprocess
+
+
+def get_flang_new_lib_dir():
+ if sys.implementation.name == "graalpy" and __graalpython__.use_system_toolchain:
+ return None, None
+ try:
+ output = subprocess.check_output(['flang-new', '--version'])
+ flang_dir = output.splitlines()[-1].split()[-1].strip().decode("utf-8")
+ return os.path.join(flang_dir, "flang-new"), os.path.normpath(os.path.join(flang_dir, '..', 'lib'))
+ except Exception as e:
+ print(f"INFO: flang-new not detected, could not find library path. Reason: {e}")
+ return None, None
+
+
+def append_env_var(env, var, value):
+ env[var] = '{} {}'.format(env.get(var, ''), value)
+
+
+def get_build_env():
+ env = {}
+ flang_new, flang_lib_dir = get_flang_new_lib_dir()
+ if flang_new:
+ # until flang-new can compile propack we disable it (during runtime)
+ env["USE_PROPACK"] = "0"
+ env['CC'] = 'clang'
+ env['CXX'] = 'clang++'
+ # env['FC'] = flang_new
+ env['FC'] = "flang-new"
+ if sys.implementation.name == "graalpy":
+ cflags = "-flto=full"
+ else:
+ ld = 'lld'
+ cflags = "-flto=full -fuse-ld=lld -Wl,--mllvm=-lto-embed-bitcode=optimized,--lto-O0"
+ env['CC_LD'] = ld
+ env['CXX_LD'] = ld
+ env['FC_LD'] = ld
+ env['CFLAGS'] = cflags
+ env['CXXFLAGS'] = cflags
+ env['FFLAGS'] = cflags
+ append_env_var(env, 'LDFLAGS', f'-L{flang_lib_dir}')
+ return env
+
+
+@contextmanager
+def env_vars(env):
+ # save and set
+ prev = {}
+ for k, v in env.items():
+ prev[k] = os.environ.get(k, None)
+ os.environ[k] = v
+
+ yield
+
+ # restore
+ for k, v in prev.items():
+ if v is None:
+ del os.environ[k]
+ else:
+ os.environ[k] = v
+
+
+def get_config_settings(config_settings=None):
+ if config_settings is None:
+ config_settings = {}
+ config_settings['compile-args'] = '-j4'
+ config_settings['builddir'] = f'mesonbuild-{sys.implementation.name}'
+ return config_settings
+
+
+def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
+ config_settings = get_config_settings(config_settings)
+ scipy_build_env = get_build_env()
+ with env_vars(scipy_build_env):
+ return mesonpy.build_wheel(wheel_directory, config_settings=config_settings, metadata_directory=metadata_directory)
+
+
+def build_sdist(sdist_directory, config_settings=None):
+ config_settings = get_config_settings(config_settings)
+ scipy_build_env = get_build_env()
+ with env_vars(scipy_build_env):
+ return mesonpy.build_sdist(sdist_directory, config_settings=config_settings)
diff --git a/pyproject.toml b/pyproject.toml
index 454a3c2e..94a754aa 100644
index 454a3c2e..7c96eb11 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -8,55 +8,21 @@
# "pybind11>=2.4.3,<2.5.0",

[build-system]
-build-backend = 'mesonpy'
+# build-backend = 'mesonpy'
+build-backend = 'mesonpy_wrapper'
+backend-path = ["."]
requires = [
"meson-python>=0.11.0,<0.13.0",
"Cython>=0.29.32,<3.0",
@@ -15,48 +15,11 @@ requires = [
# conservatively avoid issues from
# https://github.com/pybind/pybind11/issues/4420
"pybind11==2.10.1",
- "pythran>=0.12.0,<0.13.0",
+ "pythran>=0.13.0",
+ "pythran==0.13.1",
# `wheel` is needed for non-isolated builds, given that `meson-python`
# doesn't list it as a runtime requirement (at least in 0.5.0)
"wheel<0.39.0",
Expand Down Expand Up @@ -176,159 +50,6 @@ index 454a3c2e..94a754aa 100644
- "numpy; python_version>='3.12'",
- "numpy; python_version>='3.8' and platform_python_implementation=='PyPy'",
+ "numpy==1.23.5",
+ "ninja",
]

[project]
diff --git a/scipy/_lib/_ccallback_c.pyx b/scipy/_lib/_ccallback_c.pyx
index 0704acc6..beb2bc72 100644
--- a/scipy/_lib/_ccallback_c.pyx
+++ b/scipy/_lib/_ccallback_c.pyx
@@ -210,15 +210,15 @@ cdef double sine(double x, void *user_data) nogil except *:
import ctypes

plus1_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p)
-plus1_ctypes = ctypes.cast(<size_t>&plus1_cython, plus1_t)
+# plus1_ctypes = ctypes.cast(<size_t>&plus1_cython, plus1_t)

plus1b_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_double,
ctypes.POINTER(ctypes.c_int), ctypes.c_void_p)
-plus1b_ctypes = ctypes.cast(<size_t>&plus1b_cython, plus1b_t)
+# plus1b_ctypes = ctypes.cast(<size_t>&plus1b_cython, plus1b_t)

plus1bc_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double,
ctypes.POINTER(ctypes.c_int), ctypes.c_void_p)
-plus1bc_ctypes = ctypes.cast(<size_t>&plus1bc_cython, plus1bc_t)
+# plus1bc_ctypes = ctypes.cast(<size_t>&plus1bc_cython, plus1bc_t)

sine_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_void_p)
-sine_ctypes = ctypes.cast(<size_t>&sine, sine_t)
+# sine_ctypes = ctypes.cast(<size_t>&sine, sine_t)
diff --git a/scipy/_lib/setup.py b/scipy/_lib/setup.py
index 6fca8a66..95000399 100644
--- a/scipy/_lib/setup.py
+++ b/scipy/_lib/setup.py
@@ -55,8 +55,6 @@ def configuration(parent_package='',top_path=None):
# Generate a header file containing defines
config_cmd = config.get_config_cmd()
defines = []
- if config_cmd.check_func('open_memstream', decl=True, call=True):
- defines.append(('HAVE_OPEN_MEMSTREAM', '1'))
target = os.path.join(os.path.dirname(__file__), 'src',
'messagestream_config.h')
with open(target, 'w') as f:
diff --git a/scipy/_lib/src/messagestream_config.h.in b/scipy/_lib/src/messagestream_config.h.in
index fe2a3876..1cdf6c79 100644
--- a/scipy/_lib/src/messagestream_config.h.in
+++ b/scipy/_lib/src/messagestream_config.h.in
@@ -1 +1 @@
-#define HAVE_OPEN_MEMSTREAM @has_openmemstream@
+#define HAVE_OPEN_MEMSTREAM 0 // @has_openmemstream@
\ No newline at end of file
diff --git a/scipy/sparse/linalg/meson.build b/scipy/sparse/linalg/meson.build
index 946cac0c..96852886 100644
--- a/scipy/sparse/linalg/meson.build
+++ b/scipy/sparse/linalg/meson.build
@@ -15,7 +15,7 @@ py3.install_sources([
subdir: 'scipy/sparse/linalg'
)

-subdir('_propack')
+# subdir('_propack')
subdir('_isolve')
subdir('_dsolve')
subdir('_eigen')
diff --git a/scipy/special/meson.build b/scipy/special/meson.build
index f92183f5..b1443aad 100644
--- a/scipy/special/meson.build
+++ b/scipy/special/meson.build
@@ -427,24 +427,24 @@ py3.extension_module('_test_internal',
# Must use `custom_target`, because `py3.install_sources` does not work with
# generated sources - see https://github.com/mesonbuild/meson/issues/7372
npz_files = [
- [
- '_data_boost',
- 'tests/data/boost/assoc_legendre_p_ipp/assoc_legendre_p.txt',
- 'boost',
- 'boost.npz'
- ],
- [
- '_data_gsl',
- 'tests/data/gsl/mathieu_ab.txt',
- 'gsl',
- 'gsl.npz'
- ],
- [
- '_data_local',
- 'tests/data/local/ellipkm1.txt',
- 'local',
- 'local.npz'
- ],
+ # [
+ # '_data_boost',
+ # 'tests/data/boost/assoc_legendre_p_ipp/assoc_legendre_p.txt',
+ # 'boost',
+ # 'boost.npz'
+ # ],
+ # [
+ # '_data_gsl',
+ # 'tests/data/gsl/mathieu_ab.txt',
+ # 'gsl',
+ # 'gsl.npz'
+ # ],
+ # [
+ # '_data_local',
+ # 'tests/data/local/ellipkm1.txt',
+ # 'local',
+ # 'local.npz'
+ # ],
]

foreach npz_file: npz_files
diff --git a/tools/cythonize.py b/tools/cythonize.py
index 402824cb..b6aba959 100755
--- a/tools/cythonize.py
+++ b/tools/cythonize.py
@@ -95,21 +95,19 @@ def process_pyx(fromfile, tofile, cwd):
if tofile.endswith('.cxx'):
flags += ['--cplus']

- try:
+ try:
+ from Cython.Compiler.Main import setuptools_main
+ prev_argv = sys.argv[1:]
try:
- r = subprocess.call(['cython'] + flags + ["-o", tofile, fromfile], cwd=cwd)
- if r != 0:
- raise Exception('Cython failed')
- except OSError as e:
- # There are ways of installing Cython that don't result in a cython
- # executable on the path, see gh-2397.
- r = subprocess.call([sys.executable, '-c',
- 'import sys; from Cython.Compiler.Main import '
- 'setuptools_main as main; sys.exit(main())'] + flags +
- ["-o", tofile, fromfile],
- cwd=cwd)
- if r != 0:
- raise Exception("Cython either isn't installed or it failed.") from e
+ oldcwd = os.getcwd()
+ os.chdir(cwd)
+ sys.argv[1:] = flags + ["-o", tofile, fromfile]
+ retcode = setuptools_main()
+ if retcode:
+ sys.exit(retcode)
+ finally:
+ sys.argv[1:] = prev_argv
+ os.chdir(oldcwd)
except OSError as e:
raise OSError('Cython needs to be installed') from e

@@ -253,7 +251,7 @@ def find_process_files(root_dir):
lock = Lock()

try:
- num_proc = int(os.environ.get('SCIPY_NUM_CYTHONIZE_JOBS', cpu_count()))
+ num_proc = int(os.environ.get('SCIPY_NUM_CYTHONIZE_JOBS', 1))
pool = Pool(processes=num_proc)
except ImportError as e:
# Allow building (single-threaded) on GNU/Hurd, which does not

0 comments on commit 4e5ec10

Please sign in to comment.