From 633b36852dae7b736df779997df7ec9f228f7655 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Sun, 25 Feb 2024 21:52:12 +0100 Subject: [PATCH 01/13] Fix build with flint 3.1 --- src/sage/doctest/control.py | 8 -------- src/sage/libs/arb/arb_version.pyx | 23 ----------------------- src/sage/libs/flint/flint_wrap.h | 2 -- src/sage/libs/flint/fmpq.pxd | 2 -- src/sage/symbolic/ginac/useries-flint.h | 3 --- src/sage/symbolic/ginac/useries.cpp | 6 ++++-- 6 files changed, 4 insertions(+), 40 deletions(-) delete mode 100644 src/sage/libs/arb/arb_version.pyx diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py index 2973e9f6c64..58d4d53dbb9 100644 --- a/src/sage/doctest/control.py +++ b/src/sage/doctest/control.py @@ -58,14 +58,6 @@ auto_optional_tags = set() -try: - from sage.libs.arb.arb_version import version as arb_vers - arb_tag = 'arb2' + arb_vers().split('.')[1] - auto_optional_tags.add(arb_tag) -except ImportError: - pass - - class DocTestDefaults(SageObject): """ This class is used for doctesting the Sage doctest module. diff --git a/src/sage/libs/arb/arb_version.pyx b/src/sage/libs/arb/arb_version.pyx deleted file mode 100644 index b8ab4d725e5..00000000000 --- a/src/sage/libs/arb/arb_version.pyx +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -from sage.cpython.string cimport char_to_str - - -cdef extern from "arb_wrap.h": - char * arb_version - - -def version(): - """ - Get arb version - - TESTS:: - - sage: from sage.libs.arb.arb_version import version - sage: version().split('.')[0] - '2' - """ - try: - py_string = char_to_str(arb_version) - finally: - pass - return py_string diff --git a/src/sage/libs/flint/flint_wrap.h b/src/sage/libs/flint/flint_wrap.h index fcfe660a1f6..1302973779e 100644 --- a/src/sage/libs/flint/flint_wrap.h +++ b/src/sage/libs/flint/flint_wrap.h @@ -136,8 +136,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/sage/libs/flint/fmpq.pxd b/src/sage/libs/flint/fmpq.pxd index 41f075326fe..61ebabac2b0 100644 --- a/src/sage/libs/flint/fmpq.pxd +++ b/src/sage/libs/flint/fmpq.pxd @@ -41,14 +41,12 @@ cdef extern from "flint_wrap.h": void fmpq_height(fmpz_t height, const fmpq_t x) noexcept flint_bitcnt_t fmpq_height_bits(const fmpq_t x) noexcept void fmpq_set_fmpz_frac(fmpq_t res, const fmpz_t p, const fmpz_t q) noexcept - void fmpq_get_mpz_frac(mpz_t a, mpz_t b, fmpq_t c) noexcept void fmpq_set_si(fmpq_t res, slong p, ulong q) noexcept void _fmpq_set_si(fmpz_t rnum, fmpz_t rden, slong p, ulong q) noexcept void fmpq_set_ui(fmpq_t res, ulong p, ulong q) noexcept void _fmpq_set_ui(fmpz_t rnum, fmpz_t rden, ulong p, ulong q) noexcept void fmpq_set_mpq(fmpq_t dest, const mpq_t src) noexcept int fmpq_set_str(fmpq_t dest, const char * s, int base) noexcept - void fmpq_init_set_mpz_frac_readonly(fmpq_t z, const mpz_t p, const mpz_t q) noexcept double fmpq_get_d(const fmpq_t f) noexcept void fmpq_get_mpq(mpq_t dest, const fmpq_t src) noexcept int fmpq_get_mpfr(mpfr_t dest, const fmpq_t src, mpfr_rnd_t rnd) noexcept diff --git a/src/sage/symbolic/ginac/useries-flint.h b/src/sage/symbolic/ginac/useries-flint.h index 7ecd4d50107..08847273e2e 100644 --- a/src/sage/symbolic/ginac/useries-flint.h +++ b/src/sage/symbolic/ginac/useries-flint.h @@ -27,9 +27,6 @@ #include "flint/fmpq_poly.h" #include "flint/fmpq.h" -extern "C" void fmpq_get_mpz_frac(mpz_t a, mpz_t b, fmpq_t c); -extern "C" void fmpq_init_set_mpz_frac_readonly(fmpq_t z, const mpz_t p, const mpz_t q); - #include diff --git a/src/sage/symbolic/ginac/useries.cpp b/src/sage/symbolic/ginac/useries.cpp index b9a8b867648..7649e36b49a 100644 --- a/src/sage/symbolic/ginac/useries.cpp +++ b/src/sage/symbolic/ginac/useries.cpp @@ -550,14 +550,16 @@ void power::useries(flint_series_t& fp, int order) const mpz_t cnum, cden; mpz_init(cnum); mpz_init(cden); - fmpq_get_mpz_frac(cnum, cden, c); + fmpz_get_mpz(cnum, fmpq_numref(c)); + fmpz_get_mpz(cden, fmpq_denref(c)); if (not mpz_perfect_square_p(cnum) or not mpz_perfect_square_p(cden)) throw flint_error(); mpz_sqrt(cnum, cnum); mpz_sqrt(cden, cden); fmpq_t cc; - fmpq_init_set_mpz_frac_readonly(cc, cnum, cden); + fmpz_init_set_readonly(fmpq_numref(cc), cnum); + fmpz_init_set_readonly(fmpq_denref(cc), cden); mpz_clear(cnum); mpz_clear(cden); From 6e904cf73b7aae33440aea0d24b3c549d35e4418 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Mon, 26 Feb 2024 20:36:22 +0100 Subject: [PATCH 02/13] Drop obsolete arb doctest tags --- src/.relint.yml | 2 +- src/sage/doctest/parsing.py | 4 +--- src/sage/rings/complex_arb.pyx | 8 ++------ src/sage/rings/real_arb.pyx | 12 ++---------- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/.relint.yml b/src/.relint.yml index 97bf2ac1dbc..61dcf109c88 100644 --- a/src/.relint.yml +++ b/src/.relint.yml @@ -71,4 +71,4 @@ magic doctest comments should appear on the "sage:" line, not "....:" lines # see optional_regex in src/sage/doctest/parsing.py # "indirect doctest" is from src/bin/sage-coverage - pattern: '^[ ]*[.][.][.][.]:.*#.*(arb216|arb218|py2|py3|long time|not implemented|not tested|known bug|optional|indirect doctest)' + pattern: '^[ ]*[.][.][.][.]:.*#.*(py2|py3|long time|not implemented|not tested|known bug|optional|indirect doctest)' diff --git a/src/sage/doctest/parsing.py b/src/sage/doctest/parsing.py index 3e5b0a98975..31c27ddd4f2 100644 --- a/src/sage/doctest/parsing.py +++ b/src/sage/doctest/parsing.py @@ -95,7 +95,7 @@ def fake_RIFtol(*args): ansi_escape_sequence = re.compile(r"(\x1b[@-Z\\-~]|\x1b\[.*?[@-~]|\x9b.*?[@-~])") special_optional_regex = ( - "arb216|arb218|py2|long time|not implemented|not tested|optional|needs|known bug" + "py2|long time|not implemented|not tested|optional|needs|known bug" ) tag_with_explanation_regex = r"((?:\w|[.])*)\s*(?:\((?P.*?)\))?" optional_regex = re.compile( @@ -136,8 +136,6 @@ def parse_optional_tags( - ``'not tested'`` - ``'known bug'`` (possible values are ``None``, ``linux`` and ``macos``) - ``'py2'`` - - ``'arb216'`` - - ``'arb218'`` - ``'optional - FEATURE...'`` or ``'needs FEATURE...'`` -- the dictionary will just have the key ``'FEATURE'`` diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index b7384f628dc..31d1baf0f38 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -4792,18 +4792,14 @@ cdef class ComplexBall(RingElement): sage: n = CBF(1,1) sage: m = CBF(-2/3, 3/5) - sage: n.elliptic_pi_inc(CBF.pi()/2, m) # arb216 - [0.8934793755173 +/- ...e-14] + [0.95707868710750 +/- ...e-15]*I - sage: n.elliptic_pi_inc(CBF.pi()/2, m) # arb218 - this is a regression, see :trac:28623 + sage: n.elliptic_pi_inc(CBF.pi()/2, m) # this is a regression, see :trac:28623 nan + nan*I sage: n.elliptic_pi(m) [0.8934793755173...] + [0.957078687107...]*I sage: n = CBF(2, 3/7) sage: m = CBF(-1/3, 2/9) - sage: n.elliptic_pi_inc(CBF.pi()/2, m) # arb216 - [0.2969588746419 +/- ...e-14] + [1.3188795332738 +/- ...e-14]*I - sage: n.elliptic_pi_inc(CBF.pi()/2, m) # arb218 - this is a regression, see :trac:28623 + sage: n.elliptic_pi_inc(CBF.pi()/2, m) # this is a regression, see :trac:28623 nan + nan*I sage: n.elliptic_pi(m) [0.296958874641...] + [1.318879533273...]*I diff --git a/src/sage/rings/real_arb.pyx b/src/sage/rings/real_arb.pyx index 8509b19cc66..5769123c6d2 100644 --- a/src/sage/rings/real_arb.pyx +++ b/src/sage/rings/real_arb.pyx @@ -294,11 +294,7 @@ cdef int arb_to_mpfi(mpfi_t target, arb_t source, const long precision) except - EXAMPLES:: - sage: RIF(RBF(2)**(2**100)) # arb216 # indirect doctest - Traceback (most recent call last): - ... - ArithmeticError: Error converting arb to mpfi. Overflow? - sage: RIF(RBF(2)**(2**100)) # arb218 # indirect doctest + sage: RIF(RBF(2)**(2**100)) [5.8756537891115869e1388255822130839282 .. +infinity] # 64-bit [2.098... .. +infinity] # 32-bit @@ -1729,11 +1725,7 @@ cdef class RealBall(RingElement): :: sage: b = RBF(2)^(2^1000) - sage: b.mid() # arb216 - Traceback (most recent call last): - ... - RuntimeError: unable to convert to MPFR (exponent out of range?) - sage: b.mid() # arb218 + sage: b.mid() +infinity .. SEEALSO:: :meth:`rad`, :meth:`squash` From e509b118a5048189d3868ffd1cf7204efedc56ba Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 27 Feb 2024 14:38:34 +0000 Subject: [PATCH 03/13] Add script for updating Python sources and extension data in meson build files --- generate-meson.py | 198 ------------------------------------------ tools/update-meson.py | 127 +++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 198 deletions(-) delete mode 100644 generate-meson.py create mode 100644 tools/update-meson.py diff --git a/generate-meson.py b/generate-meson.py deleted file mode 100644 index 1bcb7fc3871..00000000000 --- a/generate-meson.py +++ /dev/null @@ -1,198 +0,0 @@ -# Small script that generates a meson.build file in the given folder. -# The generated build file contains all python files as `install_sources` and all cython files as `extension_module` - -import argparse -import sys -from pathlib import Path -from types import SimpleNamespace - -parser = argparse.ArgumentParser(description='Generate meson.build file for a given folder.') -parser.add_argument('folder', type=str, nargs='?', default='.', - help='folder for which the meson.build file will be generated') -parser.add_argument('--dry-run', '-n', action='store_true', - help='do not write any files, just print the output') -parser.add_argument('--force', '-f', action='store_true', - help='overwrite existing meson.build file') - -args = parser.parse_args() - -def run(folder: Path): - dry_run = args.dry_run - force = args.force - - if not folder.is_dir(): - print(f'Error: {folder} is not a directory') - return - folder_rel_to_src = folder.relative_to('src') - - python_files = sorted(list(folder.glob('*.py')) + list(folder.glob('*.pxd')) + list(folder.glob('*.h'))) - cython_files = sorted(list(folder.glob('*.pyx'))) - - - if not python_files and not cython_files: - print(f'Error: {folder} does not contain any python or cython files') - return - - def get_metadata(path: Path): - with open(path, 'r') as file: - metadata = SimpleNamespace() - metadata.path = path - metadata.libraries = [] - for line in file: - if line.startswith('# distutils: libraries ='): - libraries = line.split('libraries =')[1].strip().split() - libraries = [ - library - .replace('ARB_LIBRARY', 'arb') - .replace('NTL_LIBRARIES', 'ntl') - .replace('SINGULAR_LIBRARIES', 'singular') - .replace('LINBOX_LIBRARIES', 'linbox') - .replace('FFLASFFPACK_LIBRARIES', 'fflas') - .replace('GSL_LIBRARIES', 'gsl') - .replace('M4RI_LIBRARIES', 'm4ri') - .replace('GDLIB_LIBRARIES', 'gd') - .replace('LIBPNG_LIBRARIES', 'png') - .replace('CBLAS_LIBRARIES', 'cblas') - .replace('ZLIB_LIBRARIES', 'zlib') - .replace('Lfunction', 'lfunction') - for library in libraries] - try: - libraries.remove('CYGWIN_SQLITE3_LIBS') - except ValueError: - pass - metadata.libraries += libraries - - metadata.inc_dirs = [] - c_file = path.with_suffix('.c') - cpp_file = path.with_suffix('.cpp') - if cpp_file.exists(): - metadata.is_cpp = True - c_file = cpp_file - else: - metadata.is_cpp = False - if c_file.exists(): - metadata.not_yet_on_conda = False - with open(c_file, 'r') as c_file: - contents = c_file.read() - known_inc_dirs = { - 'sage/cpython/': 'inc_cpython', - 'sage/rings': 'inc_rings', - 'sage/rings/finite_rings': 'inc_rings_finite', - 'sage/libs/flint': 'inc_flint', - 'sage/libs/gsl': 'inc_gsl', - 'sage/libs/ntl': 'inc_ntl', - 'sage/libs/arb': 'inc_arb', - 'sage/data_structures': 'inc_data_structures', - 'sage/ext/': 'inc_ext', - 'numpy/core/include/': 'inc_numpy', - 'sage/symbolic/ginac/': 'inc_ginac', - 'sage/symbolic/pynac_wrap.h': 'inc_pynac', - 'sage/groups/perm_gps/partn_ref2/': 'inc_partn_ref2', - 'sage/ext/interpreters/': 'inc_interpreters', - } - for known_inc_dir in known_inc_dirs: - if known_inc_dir in contents: - metadata.inc_dirs.append(known_inc_dirs[known_inc_dir]) - known_libs = { - 'cypari2/': 'cypari2', - 'cysignals/': 'cysignals', - '/gmp.h': 'gmp', - '/iml.h': 'iml', - '/m4ri/': 'm4ri', - '/pari/': 'pari', - '/flint/': 'flint', - '/fflas-ffpack/': 'fflas', - '/givaro/': 'givaro', - '/gmp++/': 'gmpxx', - '/linbox/': 'linbox', - '/gsl/': 'gsl', - 'mpfr.h': 'mpfr', - 'sage/symbolic/ginac/': 'ginac', - 'arb.h': 'arb', - 'mpfi.h': 'mpfi', - 'mpc.h': 'mpc', - 'gmpy2/': 'gmpy2', - } - for known_lib in known_libs: - if known_lib in contents: - metadata.libraries.append(known_libs[known_lib]) - else: - metadata.not_yet_on_conda = metadata.is_cpp is False - - return metadata - - cython_files = [get_metadata(file) for file in cython_files] - cython_c_files = [file for file in cython_files if not file.is_cpp] - cython_cpp_files = [file for file in cython_files if file.is_cpp] - all_libraries = sorted(set(library for file in cython_files for library in file.libraries) | {'gmp'}) - all_inc_dirs = sorted(set(inc_dir for file in cython_files for inc_dir in file.inc_dirs)) - subdirs = sorted(list(folder.glob('*/'))) - - meson_build_path = folder / 'meson.build' - if not dry_run and not force and meson_build_path.exists(): - print(f'Error: {meson_build_path} already exists, use --force to overwrite') - return - - with open(meson_build_path, 'w') if not dry_run else sys.stdout as meson_build: - meson_build.write('py.install_sources(\n') - for file in python_files: - meson_build.write(f" '{file.name}',\n") - meson_build.write(f" subdir: '{folder_rel_to_src}',\n") - meson_build.write(')\n') - - if cython_c_files: - meson_build.write('\n') - meson_build.write('extension_data = {\n') - for file in cython_c_files: - if file.not_yet_on_conda: - meson_build.write(f" # '{file.path.stem}': files('{file.path.name}'), # not yet on conda\n") - else: - meson_build.write(f" '{file.path.stem}': files('{file.path.name}'),\n") - meson_build.write('}\n\n') - - meson_build.write('foreach name, pyx : extension_data\n') - meson_build.write(" py.extension_module(name,\n") - meson_build.write(" sources: pyx,\n") - meson_build.write(f" subdir: '{folder_rel_to_src}',\n") - meson_build.write(' install: true,\n') - meson_build.write(f" include_directories: [{', '.join(all_inc_dirs)}],\n") - meson_build.write(f" dependencies: [py_dep{', ' if all_libraries else ''}{', '.join(all_libraries)}],\n") - meson_build.write(' )\n') - meson_build.write('endforeach\n') - - if cython_cpp_files: - meson_build.write('\n') - meson_build.write('extension_data_cpp = {\n') - for file in cython_cpp_files: - if file.not_yet_on_conda: - meson_build.write(f" # '{file.path.stem}': files('{file.path.name}'), # not yet on conda\n") - else: - meson_build.write(f" '{file.path.stem}': files('{file.path.name}'),\n") - meson_build.write('}\n\n') - - meson_build.write('foreach name, pyx : extension_data_cpp\n') - meson_build.write(" py.extension_module(name,\n") - meson_build.write(" sources: pyx,\n") - meson_build.write(f" subdir: '{folder_rel_to_src}',\n") - meson_build.write(' install: true,\n') - meson_build.write(' override_options : [\'cython_language=cpp\'],\n') - meson_build.write(f" include_directories: [{', '.join(all_inc_dirs)}],\n") - meson_build.write(f" dependencies: [py_dep{', ' if all_libraries else ''}{', '.join(all_libraries)}],\n") - meson_build.write(' )\n') - meson_build.write('endforeach\n') - - meson_build.write('\n') - for subdir in subdirs: - if subdir.name.startswith('_') or subdir.name.startswith('.'): - continue - if not list(subdir.glob('*.py*')): - continue - - if not list(subdir.glob('*.pyx')): - meson_build.write(f"install_subdir('{subdir.name}', install_dir: sage_install_dir / '{folder_rel_to_src.relative_to('sage')}')\n") - else: - meson_build.write(f"subdir('{subdir.name}')\n") - run(subdir) - -folder = Path(args.folder) -run(folder) diff --git a/tools/update-meson.py b/tools/update-meson.py new file mode 100644 index 00000000000..49578007804 --- /dev/null +++ b/tools/update-meson.py @@ -0,0 +1,127 @@ +import argparse +from pathlib import Path + +from mesonbuild.ast import AstVisitor +from mesonbuild.ast.interpreter import MethodNode +from mesonbuild.mparser import AssignmentNode, BaseNode, DictNode, SymbolNode +from mesonbuild.rewriter import ( + ArgumentNode, + ArrayNode, + BaseStringNode, + FunctionNode, + Rewriter, + StringNode, + Token, +) + +# Get target directory from command line arguments +parser = argparse.ArgumentParser() +parser.add_argument("sourcedir", help="Source directory") +options = parser.parse_args() + + +class AstPython(AstVisitor): + install_sources_calls: list[MethodNode] = [] + extension_data: list[AssignmentNode] = [] + + def visit_MethodNode(self, node: MethodNode) -> None: + if node.name.value == "install_sources": + self.install_sources_calls += [node] + return super().visit_MethodNode(node) + + def visit_AssignmentNode(self, node: AssignmentNode) -> None: + if node.var_name.value in ["extension_data", "extension_data_cpp"]: + self.extension_data += [node] + return super().visit_AssignmentNode(node) + + +# Utility function to get a list of the sources from a node +def arg_list_from_node(n): + args = [] + if isinstance(n, FunctionNode) or isinstance(n, MethodNode): + args = list(n.args.arguments) + # if 'func_name' in n and n.func_name.value in BUILD_TARGET_FUNCTIONS: + # args.pop(0) + elif isinstance(n, ArrayNode): + args = n.args.arguments + elif isinstance(n, ArgumentNode): + args = n.arguments + return args + +def _symbol(val: str) -> SymbolNode: + return SymbolNode(Token('', '', 0, 0, 0, (0, 0), val)) + + +def add_python_sources(self: Rewriter, visitor: AstPython): + for target in visitor.install_sources_calls: + # Generate the current source list + src_list: list[str] = [] + for arg in arg_list_from_node(target): + if isinstance(arg, BaseStringNode): + src_list += [arg.value] + + folder = Path(target.filename).parent + python_files = sorted( + list(folder.glob("*.py")) + ) # + list(folder.glob('*.pxd')) + list(folder.glob('*.h'))) + + to_append: list[StringNode] = [] + for file in python_files: + file_name = file.name + if file_name == "__init__.py": + # We don't want to add __init__.py files + continue + if file_name in src_list: + continue + token = Token("string", target.filename, 0, 0, 0, None, file_name) + to_append += [StringNode(token)] + + # Append to the AST at the right place + target.args.arguments = sorted( + target.args.arguments + to_append, key=lambda x: x.value + ) + + # Mark the node as modified + if target not in self.modified_nodes: + self.modified_nodes += [target] + + ext_data: dict[Path, list[str]] = {} + for target in visitor.extension_data: + folder = Path(target.filename).parent + # Generate the current source dict + src_list: dict[str, BaseNode] = {} + if isinstance(target.value, DictNode): + src_list.update({k.value: v for k, v in target.value.args.kwargs.items()}) + ext_data.setdefault(folder, []) + ext_data[folder] += src_list.keys() + + for target in visitor.extension_data: + if target.var_name.value != "extension_data": + continue + folder = Path(target.filename).parent + src_list = ext_data[folder] + + cython_files = sorted(list(folder.glob("*.pyx"))) + for file in cython_files: + file_name = file.stem + if file_name in src_list: + continue + token = Token("string", target.filename, 0, 0, 0, None, file_name) + arg = ArgumentNode(Token("", target.filename, 0, 0, 0, None, "[]")) + arg.append( + StringNode(Token("string", target.filename, 0, 0, 0, None, file.name)) + ) + func = FunctionNode(_symbol("files"), _symbol("("), arg, _symbol(")")) + target.value.args.kwargs.update({StringNode(token): func}) + if target not in self.modified_nodes: + self.modified_nodes += [target] + + +Rewriter.process_add_python_sources = add_python_sources +rewriter = Rewriter(options.sourcedir) +visitor = AstPython() +rewriter.interpreter.visitors += [visitor] +rewriter.analyze_meson() +rewriter.process_add_python_sources(visitor) +rewriter.apply_changes() +rewriter.print_info() From 62bf19f4c174b66552c82209b220ff43eb8e3969 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 27 Feb 2024 15:20:18 +0000 Subject: [PATCH 04/13] Remove unnecessary code for finding include path for Cython modules --- src/meson.build | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/meson.build b/src/meson.build index 9dbab81ca37..0c80bcc0ece 100644 --- a/src/meson.build +++ b/src/meson.build @@ -124,20 +124,6 @@ maxima = find_program('maxima', required: true) # Cannot be found via pkg-config ntl = cc.find_library('ntl', required: true) -# It's strange but cython cannot find its own include files -# so we find them ourselves, and add them to the include path -inc_cython = run_command(py, - [ - '-c', - ''' -import Cython -print(Cython.__file__.replace('__init__.py', '')) - '''.strip() - ], - check: true - ).stdout().strip() -add_project_arguments('-I', inc_cython + 'Includes', language : 'cython') - # Meson currently ignores include_directories for Cython modules, so we # have to add them manually. # https://github.com/mesonbuild/meson/issues/9562 From 5e7a899097269c15d6d5022d105eba06262dcfae Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 27 Feb 2024 15:33:09 +0000 Subject: [PATCH 05/13] Improve code for generating interpreters --- .github/workflows/ci-meson.yml | 6 --- src/doc/en/installation/meson.rst | 6 --- src/sage/ext/interpreters/__init__.py | 1 - src/sage/ext/interpreters/meson.build | 30 ------------ src/sage/ext/meson.build | 68 +++++++++++++++++++++------ 5 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 src/sage/ext/interpreters/__init__.py delete mode 100644 src/sage/ext/interpreters/meson.build diff --git a/.github/workflows/ci-meson.yml b/.github/workflows/ci-meson.yml index 279fc9d1365..d3235fa9d64 100644 --- a/.github/workflows/ci-meson.yml +++ b/.github/workflows/ci-meson.yml @@ -66,12 +66,6 @@ jobs: conda info conda list - - name: Bootstrap - shell: bash -l {0} - run: python -m sage_setup.autogen.interpreters src/sage/ext/interpreters - env: - PYTHONPATH: src - - name: Build shell: bash -l {0} run: | diff --git a/src/doc/en/installation/meson.rst b/src/doc/en/installation/meson.rst index d2179bf8fe2..d48e9403231 100644 --- a/src/doc/en/installation/meson.rst +++ b/src/doc/en/installation/meson.rst @@ -27,12 +27,6 @@ Alternatively, install all build requirements as described in section ``rm src/**/*.so`` or ``for f in src/**/*.so ; do mv "$f" "$f.old"; done``. Also uninstall the 'old' sage packages with ``pip uninstall sage-conf sage-setup sagemath-standard``. -Generate a few files that are needed for the build process:: - - ```bash - python -m sage_setup.autogen.interpreters src/sage/ext/interpreters - ``` - To compile and install the project in editable install, just use:: ```bash diff --git a/src/sage/ext/interpreters/__init__.py b/src/sage/ext/interpreters/__init__.py deleted file mode 100644 index 1b10e244496..00000000000 --- a/src/sage/ext/interpreters/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Here so that cython creates the correct module name diff --git a/src/sage/ext/interpreters/meson.build b/src/sage/ext/interpreters/meson.build deleted file mode 100644 index 3dc6a9e3064..00000000000 --- a/src/sage/ext/interpreters/meson.build +++ /dev/null @@ -1,30 +0,0 @@ -py.install_sources( - 'all.py', - 'wrapper_cc.pxd', - 'wrapper_cdf.pxd', - 'wrapper_el.pxd', - 'wrapper_py.pxd', - 'wrapper_rdf.pxd', - 'wrapper_rr.pxd', - subdir : 'sage/ext/interpreters' -) - -extension_data = { - 'wrapper_cc' : files('wrapper_cc.pyx'), - 'wrapper_cdf' : files('wrapper_cdf.pyx'), - 'wrapper_el' : files('wrapper_el.pyx'), - 'wrapper_py' : files('wrapper_py.pyx'), - 'wrapper_rdf' : files('wrapper_rdf.pyx'), - 'wrapper_rr' : files('wrapper_rr.pyx') -} - -foreach name, pyx : extension_data - py.extension_module(name, - sources: pyx, - subdir: 'sage/ext/interpreters', - install: true, - include_directories: [inc_cpython, inc_ext, inc_interpreters, inc_rings, inc_src], - dependencies: [py_dep, cypari2, cysignals, gmp, gsl, mpc, mpfr, pari, interpreters_dep], - ) -endforeach - diff --git a/src/sage/ext/meson.build b/src/sage/ext/meson.build index fdeecdc9318..53aa479c12d 100644 --- a/src/sage/ext/meson.build +++ b/src/sage/ext/meson.build @@ -30,45 +30,85 @@ endforeach interpreters = custom_target( 'sage.ext.interpreters', - output: 'all.py', + output: [ + 'all.py', + 'wrapper_cc.pxd', + 'wrapper_cdf.pxd', + 'wrapper_el.pxd', + 'wrapper_py.pxd', + 'wrapper_rdf.pxd', + 'wrapper_rr.pxd', + 'wrapper_cc.pyx', + 'wrapper_cdf.pyx', + 'wrapper_el.pyx', + 'wrapper_py.pyx', + 'wrapper_rdf.pyx', + 'wrapper_rr.pyx', + ], input: '../../sage_setup/autogen/interpreters/__init__.py', - command: [py, '-m', 'sage_setup.autogen.interpreters', meson.current_source_dir() / 'interpreters'], - # This is actually against the Meson philosophy, which does not like in-source builds. - # So normally you would do something like the following - # however, this we currently cannot pass the generated files as sources to install_sources - # properly fixing this is left for a follow-up - # command: [py, '-m', 'sage_setup.autogen.interpreters','@OUTDIR@'], + command: [py, '-m', 'sage_setup.autogen.interpreters','@OUTDIR@'], env: ['PYTHONPATH=' + meson.current_source_dir() / '..' / '..'], + # Manually install the generated files instead of using install_sources + # this is a workaround for https://github.com/mesonbuild/meson/issues/7372 + install: true, + install_dir: py.get_install_dir() / 'sage/ext/interpreters', + install_tag: 'python-runtime', ) -# Manually create header files, which otherwise is not found +# Use this once https://github.com/mesonbuild/meson/issues/7372 is fixed +#foreach file : interpreters.to_list() +# py.install_sources( +# file.full_path(), +# subdir : 'sage/ext/interpreters' +# ) +#endforeach + +extension_data = { + 'wrapper_cc' : interpreters[7], + 'wrapper_cdf' : interpreters[8], + 'wrapper_el' : interpreters[9], + 'wrapper_py' : interpreters[10], + 'wrapper_rdf' : interpreters[11], + 'wrapper_rr' : interpreters[12], +} + +# Manually create header files, which otherwise are not found wrapper_el_header = custom_target( 'wrapper_el.h', output : 'wrapper_el.h', - input : ['interpreters/wrapper_el.pyx', interpreters], + input : [interpreters[9], interpreters], command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../')], ) wrapper_cc_header = custom_target( 'wrapper_cc.h', output : 'wrapper_cc.h', - input : ['interpreters/wrapper_cc.pyx', interpreters], + input : [interpreters[7], interpreters], command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../')], ) wrapper_cdf_header = custom_target( 'wrapper_cdf.h', output : 'wrapper_cdf.h', - input : ['interpreters/wrapper_cdf.pyx', interpreters], + input : [interpreters[8], interpreters], command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../')], ) wrapper_rr_header = custom_target( 'wrapper_rr.h', output : 'wrapper_rr.h', - input : ['interpreters/wrapper_rr.pyx', interpreters], + input : [interpreters[12], interpreters], command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../')], ) interpreters_dep = declare_dependency( - sources: [interpreters, wrapper_el_header, wrapper_cc_header, wrapper_cdf_header, wrapper_rr_header], + sources: [wrapper_el_header, wrapper_cc_header, wrapper_cdf_header, wrapper_rr_header], ) -subdir('interpreters') + +foreach name, pyx : extension_data + py.extension_module(name, + sources: pyx, + subdir: 'sage/ext/interpreters', + install: true, + include_directories: [inc_cpython, inc_ext, inc_interpreters, inc_rings, inc_src], + dependencies: [py_dep, cypari2, cysignals, gmp, gsl, mpc, mpfr, pari, interpreters_dep], + ) +endforeach From d129c03d605d1301d30db2ec5ad8a124d1db819f Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 27 Feb 2024 15:36:40 +0000 Subject: [PATCH 06/13] Update CI workflow to use lock environment file --- .github/workflows/ci-meson.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci-meson.yml b/.github/workflows/ci-meson.yml index d3235fa9d64..ff810052bf5 100644 --- a/.github/workflows/ci-meson.yml +++ b/.github/workflows/ci-meson.yml @@ -34,9 +34,6 @@ jobs: env: GH_TOKEN: ${{ github.token }} - - name: Create conda environment files - run: ./bootstrap-conda - - name: Cache conda packages uses: actions/cache@v3 with: @@ -58,7 +55,7 @@ jobs: channels: conda-forge channel-priority: true activate-environment: sage - environment-file: src/environment-${{ matrix.python }}.yml + environment-file: src/environment-${{ matrix.python }}-${{ startsWith(matrix.os, 'macos') && 'macos' || 'linux' }}.yml - name: Print Conda environment shell: bash -l {0} From 434225cd8c9e8e183598008fb61cb9cb191cc0c3 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 27 Feb 2024 15:37:05 +0000 Subject: [PATCH 07/13] Remove unnecessary arb include directory in meson.build files --- grayskull | 1 + meson | 1 + src/sage/libs/arb/meson.build | 2 +- src/sage/matrix/meson.build | 4 ++-- src/sage/rings/meson.build | 4 ++-- src/sage/rings/number_field/meson.build | 4 ++-- src/sage/rings/polynomial/meson.build | 4 ++-- 7 files changed, 11 insertions(+), 9 deletions(-) create mode 160000 grayskull create mode 160000 meson diff --git a/grayskull b/grayskull new file mode 160000 index 00000000000..5e74f1daa33 --- /dev/null +++ b/grayskull @@ -0,0 +1 @@ +Subproject commit 5e74f1daa33168642351563f5d73110e09dbd689 diff --git a/meson b/meson new file mode 160000 index 00000000000..5fdf7d7d8ca --- /dev/null +++ b/meson @@ -0,0 +1 @@ +Subproject commit 5fdf7d7d8caebb66f96f515c954182015caad492 diff --git a/src/sage/libs/arb/meson.build b/src/sage/libs/arb/meson.build index 36da5a1cc6c..8c6f0375b33 100644 --- a/src/sage/libs/arb/meson.build +++ b/src/sage/libs/arb/meson.build @@ -28,7 +28,7 @@ foreach name, pyx : extension_data sources: pyx, subdir: 'sage/libs/arb', install: true, - include_directories: [inc_arb, inc_cpython, inc_flint, inc_rings], + include_directories: [inc_cpython, inc_flint, inc_rings], dependencies: [py_dep, flint, gmp, mpfr], ) endforeach diff --git a/src/sage/matrix/meson.build b/src/sage/matrix/meson.build index 18a51f2f28b..311ba17592b 100644 --- a/src/sage/matrix/meson.build +++ b/src/sage/matrix/meson.build @@ -69,7 +69,7 @@ foreach name, pyx : extension_data sources: pyx, subdir: 'sage/matrix', install: true, - include_directories: [inc_arb, inc_cpython, inc_ext, inc_flint, inc_ntl, inc_numpy, inc_rings, inc_rings_finite], + include_directories: [inc_cpython, inc_ext, inc_flint, inc_ntl, inc_numpy, inc_rings, inc_rings_finite], dependencies: dependencies, ) endforeach @@ -93,7 +93,7 @@ foreach name, pyx : extension_data_cpp subdir: 'sage/matrix', install: true, override_options : ['cython_language=cpp'], - include_directories: [inc_arb, inc_cpython, inc_ext, inc_flint, inc_ntl, inc_numpy, inc_rings, inc_rings_finite], + include_directories: [inc_cpython, inc_ext, inc_flint, inc_ntl, inc_numpy, inc_rings, inc_rings_finite], dependencies: [py_dep, blas, cypari2, cysignals, fflas, flint, gd, givaro, gmp, gmpxx, iml, linbox, m, m4ri, m4rie, mpfi, mpfr, mtx, ntl, pari, png, singular, zlib], ) endforeach diff --git a/src/sage/rings/meson.build b/src/sage/rings/meson.build index 3146d4ddaf4..114007def84 100644 --- a/src/sage/rings/meson.build +++ b/src/sage/rings/meson.build @@ -129,7 +129,7 @@ foreach name, pyx : extension_data sources: pyx, subdir: 'sage/rings', install: true, - include_directories: [inc_arb, inc_cpython, inc_ext, inc_flint, inc_gsl, inc_ntl, inc_rings, inc_rings_finite], + include_directories: [inc_cpython, inc_ext, inc_flint, inc_gsl, inc_ntl, inc_rings, inc_rings_finite], dependencies: [py_dep, cypari2, cysignals, flint, gmp, gmpy2, gsl, m, mpc, mpfi, mpfr, ntl, pari, pthread], ) endforeach @@ -148,7 +148,7 @@ foreach name, pyx : extension_data_cpp install: true, cpp_args: ['-DUSE_THREADS=1','-DTHREAD_STACK_SIZE=4096'], override_options : ['cython_language=cpp'], - include_directories: [inc_arb, inc_cpython, inc_ext, inc_flint, inc_gsl, inc_ntl, inc_rings, inc_rings_finite], + include_directories: [inc_cpython, inc_ext, inc_flint, inc_gsl, inc_ntl, inc_rings, inc_rings_finite], dependencies: [py_dep, cypari2, cysignals, flint, gmp, gmpy2, gsl, m, mpc, mpfi, mpfr, ntl, pari, pthread], ) endforeach diff --git a/src/sage/rings/number_field/meson.build b/src/sage/rings/number_field/meson.build index a417e2f2b0d..f233e51632c 100644 --- a/src/sage/rings/number_field/meson.build +++ b/src/sage/rings/number_field/meson.build @@ -41,7 +41,7 @@ foreach name, pyx : extension_data sources: pyx, subdir: 'sage/rings/number_field', install: true, - include_directories: [inc_arb, inc_cpython, inc_ext, inc_flint, inc_ntl, inc_rings], + include_directories: [inc_cpython, inc_ext, inc_flint, inc_ntl, inc_rings], dependencies: [py_dep, cypari2, cysignals, flint, gmp, mpfi, mpfr, ntl], ) endforeach @@ -57,7 +57,7 @@ foreach name, pyx : extension_data_cpp subdir: 'sage/rings/number_field', install: true, override_options : ['cython_language=cpp'], - include_directories: [inc_arb, inc_cpython, inc_ext, inc_flint, inc_ntl, inc_rings], + include_directories: [inc_cpython, inc_ext, inc_flint, inc_ntl, inc_rings], dependencies: [py_dep, cypari2, cysignals, flint, gmp, mpfi, mpfr, ntl], ) endforeach diff --git a/src/sage/rings/polynomial/meson.build b/src/sage/rings/polynomial/meson.build index ff859284f88..381a76642d9 100644 --- a/src/sage/rings/polynomial/meson.build +++ b/src/sage/rings/polynomial/meson.build @@ -96,7 +96,7 @@ foreach name, pyx : extension_data sources: pyx, subdir: 'sage/rings/polynomial', install: true, - include_directories: [inc_arb, inc_cpython, inc_ext, inc_flint, inc_ntl, inc_numpy, inc_rings, inc_rings_finite], + include_directories: [inc_cpython, inc_ext, inc_flint, inc_ntl, inc_numpy, inc_rings, inc_rings_finite], dependencies: [py_dep, cypari2, cysignals, flint, givaro, gmp, mpfi, mpfr, ntl, pari], ) endforeach @@ -121,7 +121,7 @@ foreach name, pyx : extension_data_cpp subdir: 'sage/rings/polynomial', install: true, override_options : ['cython_language=cpp'], - include_directories: [inc_arb, inc_cpython, inc_ext, inc_flint, inc_ntl, inc_numpy, inc_rings, inc_rings_finite], + include_directories: [inc_cpython, inc_ext, inc_flint, inc_ntl, inc_numpy, inc_rings, inc_rings_finite], dependencies: [py_dep, cypari2, cysignals, flint, givaro, gmp, mpfi, mpfr, ntl, pari, singular], ) endforeach From 3fbe6a332acc8367d1e04fbde4555949128ebb1d Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 28 Feb 2024 08:15:19 +0000 Subject: [PATCH 08/13] add meson to conda lock file --- src/environment-3.10-linux.yml | 12 +++++++----- src/environment-3.10-macos.yml | 10 ++++++---- src/environment-3.11-linux.yml | 12 +++++++----- src/environment-3.11-macos.yml | 10 ++++++---- src/environment-3.9-linux.yml | 12 +++++++----- src/environment-3.9-macos.yml | 10 ++++++---- 6 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/environment-3.10-linux.yml b/src/environment-3.10-linux.yml index 201bf1c8492..5251be1d9a5 100644 --- a/src/environment-3.10-linux.yml +++ b/src/environment-3.10-linux.yml @@ -361,10 +361,11 @@ dependencies: - libxkbcommon=1.6.0=h5d7e998_0 - matplotlib-inline=0.1.6=pyhd8ed1ab_0 - memory-allocator=0.1.3=py310h2372a71_0 - - overrides=7.4.0=pyhd8ed1ab_0 - - pexpect=4.8.0=pyh1a96a4e_2 - - pillow=10.1.0=py310h01dd4db_0 - - pip=23.3.2=pyhd8ed1ab_0 + - meson=1.3.2=pyhd8ed1ab_0 + - overrides=7.7.0=pyhd8ed1ab_0 + - pexpect=4.9.0=pyhd8ed1ab_0 + - pillow=10.2.0=py310h01dd4db_0 + - pip=24.0=pyhd8ed1ab_0 - pplpy=0.8.9=py310h28f6eb6_0 - primecountpy=0.1.0=py310hd41b1e2_4 - prompt-toolkit=3.0.42=pyha770c72_0 @@ -400,7 +401,8 @@ dependencies: - jsonschema-specifications=2023.11.2=pyhd8ed1ab_0 - jupyter_server_terminals=0.5.0=pyhd8ed1ab_0 - liblapacke=3.9.0=20_linux64_openblas - - numpy=1.26.2=py310hb13e2d6_0 + - meson-python=0.15.0=pyh0c530f3_0 + - numpy=1.26.4=py310hb13e2d6_0 - prompt_toolkit=3.0.42=hd8ed1ab_0 - pyqt5-sip=12.12.2=py310hc6cd4ac_5 - requests=2.31.0=pyhd8ed1ab_0 diff --git a/src/environment-3.10-macos.yml b/src/environment-3.10-macos.yml index ba31dab449e..41e79e3abb6 100644 --- a/src/environment-3.10-macos.yml +++ b/src/environment-3.10-macos.yml @@ -299,9 +299,10 @@ dependencies: - liblapack=3.9.0=20_osx64_openblas - matplotlib-inline=0.1.6=pyhd8ed1ab_0 - memory-allocator=0.1.3=py310h6729b98_0 - - overrides=7.4.0=pyhd8ed1ab_0 - - pexpect=4.8.0=pyh1a96a4e_2 - - pip=23.3.2=pyhd8ed1ab_0 + - meson=1.3.2=pyhd8ed1ab_0 + - overrides=7.7.0=pyhd8ed1ab_0 + - pexpect=4.9.0=pyhd8ed1ab_0 + - pip=24.0=pyhd8ed1ab_0 - pplpy=0.8.9=py310hd89f7aa_0 - primecountpy=0.1.0=py310h88cfcbd_4 - prompt-toolkit=3.0.42=pyha770c72_0 @@ -333,7 +334,8 @@ dependencies: - jsonschema-specifications=2023.11.2=pyhd8ed1ab_0 - jupyter_server_terminals=0.5.0=pyhd8ed1ab_0 - liblapacke=3.9.0=20_osx64_openblas - - numpy=1.26.2=py310h2a7ecf2_0 + - meson-python=0.15.0=pyh0c530f3_0 + - numpy=1.26.4=py310h4bfa8fc_0 - pango=1.50.14=h19c1c8a_2 - prompt_toolkit=3.0.42=hd8ed1ab_0 - pyobjc-framework-cocoa=10.1=py310h3674b6a_0 diff --git a/src/environment-3.11-linux.yml b/src/environment-3.11-linux.yml index 8439b8e51db..a5ce24f1437 100644 --- a/src/environment-3.11-linux.yml +++ b/src/environment-3.11-linux.yml @@ -360,10 +360,11 @@ dependencies: - libxkbcommon=1.6.0=h5d7e998_0 - matplotlib-inline=0.1.6=pyhd8ed1ab_0 - memory-allocator=0.1.3=py311h459d7ec_0 - - overrides=7.4.0=pyhd8ed1ab_0 - - pexpect=4.8.0=pyh1a96a4e_2 - - pillow=10.1.0=py311ha6c5da5_0 - - pip=23.3.2=pyhd8ed1ab_0 + - meson=1.3.2=pyhd8ed1ab_0 + - overrides=7.7.0=pyhd8ed1ab_0 + - pexpect=4.9.0=pyhd8ed1ab_0 + - pillow=10.2.0=py311ha6c5da5_0 + - pip=24.0=pyhd8ed1ab_0 - pplpy=0.8.9=py311h85abca9_0 - primecountpy=0.1.0=py311h9547e67_4 - prompt-toolkit=3.0.42=pyha770c72_0 @@ -399,7 +400,8 @@ dependencies: - jsonschema-specifications=2023.11.2=pyhd8ed1ab_0 - jupyter_server_terminals=0.5.0=pyhd8ed1ab_0 - liblapacke=3.9.0=20_linux64_openblas - - numpy=1.26.2=py311h64a7726_0 + - meson-python=0.15.0=pyh0c530f3_0 + - numpy=1.26.4=py311h64a7726_0 - prompt_toolkit=3.0.42=hd8ed1ab_0 - pyqt5-sip=12.12.2=py311hb755f60_5 - requests=2.31.0=pyhd8ed1ab_0 diff --git a/src/environment-3.11-macos.yml b/src/environment-3.11-macos.yml index 86acb5faf05..379761c6a34 100644 --- a/src/environment-3.11-macos.yml +++ b/src/environment-3.11-macos.yml @@ -298,9 +298,10 @@ dependencies: - liblapack=3.9.0=20_osx64_openblas - matplotlib-inline=0.1.6=pyhd8ed1ab_0 - memory-allocator=0.1.3=py311h2725bcf_0 - - overrides=7.4.0=pyhd8ed1ab_0 - - pexpect=4.8.0=pyh1a96a4e_2 - - pip=23.3.2=pyhd8ed1ab_0 + - meson=1.3.2=pyhd8ed1ab_0 + - overrides=7.7.0=pyhd8ed1ab_0 + - pexpect=4.9.0=pyhd8ed1ab_0 + - pip=24.0=pyhd8ed1ab_0 - pplpy=0.8.9=py311h7355a2a_0 - primecountpy=0.1.0=py311h5fe6e05_4 - prompt-toolkit=3.0.42=pyha770c72_0 @@ -332,7 +333,8 @@ dependencies: - jsonschema-specifications=2023.11.2=pyhd8ed1ab_0 - jupyter_server_terminals=0.5.0=pyhd8ed1ab_0 - liblapacke=3.9.0=20_osx64_openblas - - numpy=1.26.2=py311h93c810c_0 + - meson-python=0.15.0=pyh0c530f3_0 + - numpy=1.26.4=py311hc43a94b_0 - pango=1.50.14=h19c1c8a_2 - prompt_toolkit=3.0.42=hd8ed1ab_0 - pyobjc-framework-cocoa=10.1=py311h9b70068_0 diff --git a/src/environment-3.9-linux.yml b/src/environment-3.9-linux.yml index 70d7997cd8a..bb1994af9d3 100644 --- a/src/environment-3.9-linux.yml +++ b/src/environment-3.9-linux.yml @@ -361,10 +361,11 @@ dependencies: - libxkbcommon=1.6.0=h5d7e998_0 - matplotlib-inline=0.1.6=pyhd8ed1ab_0 - memory-allocator=0.1.3=py39hd1e30aa_0 - - overrides=7.4.0=pyhd8ed1ab_0 - - pexpect=4.8.0=pyh1a96a4e_2 - - pillow=10.1.0=py39had0adad_0 - - pip=23.3.2=pyhd8ed1ab_0 + - meson=1.3.2=pyhd8ed1ab_0 + - overrides=7.7.0=pyhd8ed1ab_0 + - pexpect=4.9.0=pyhd8ed1ab_0 + - pillow=10.2.0=py39had0adad_0 + - pip=24.0=pyhd8ed1ab_0 - pplpy=0.8.9=py39hba3e9e5_0 - primecountpy=0.1.0=py39h7633fee_4 - prompt-toolkit=3.0.42=pyha770c72_0 @@ -400,7 +401,8 @@ dependencies: - jsonschema-specifications=2023.11.2=pyhd8ed1ab_0 - jupyter_server_terminals=0.5.0=pyhd8ed1ab_0 - liblapacke=3.9.0=20_linux64_openblas - - numpy=1.26.2=py39h474f0d3_0 + - meson-python=0.15.0=pyh0c530f3_0 + - numpy=1.26.4=py39h474f0d3_0 - prompt_toolkit=3.0.42=hd8ed1ab_0 - pyqt5-sip=12.12.2=py39h3d6467e_5 - requests=2.31.0=pyhd8ed1ab_0 diff --git a/src/environment-3.9-macos.yml b/src/environment-3.9-macos.yml index c924d013cbc..04874958b09 100644 --- a/src/environment-3.9-macos.yml +++ b/src/environment-3.9-macos.yml @@ -299,9 +299,10 @@ dependencies: - liblapack=3.9.0=20_osx64_openblas - matplotlib-inline=0.1.6=pyhd8ed1ab_0 - memory-allocator=0.1.3=py39hdc70f33_0 - - overrides=7.4.0=pyhd8ed1ab_0 - - pexpect=4.8.0=pyh1a96a4e_2 - - pip=23.3.2=pyhd8ed1ab_0 + - meson=1.3.2=pyhd8ed1ab_0 + - overrides=7.7.0=pyhd8ed1ab_0 + - pexpect=4.9.0=pyhd8ed1ab_0 + - pip=24.0=pyhd8ed1ab_0 - pplpy=0.8.9=py39h248ee18_0 - primecountpy=0.1.0=py39h8ee36c8_4 - prompt-toolkit=3.0.42=pyha770c72_0 @@ -333,7 +334,8 @@ dependencies: - jsonschema-specifications=2023.11.2=pyhd8ed1ab_0 - jupyter_server_terminals=0.5.0=pyhd8ed1ab_0 - liblapacke=3.9.0=20_osx64_openblas - - numpy=1.26.2=py39h14c6d2e_0 + - meson-python=0.15.0=pyh0c530f3_0 + - numpy=1.26.4=py39h28c39a1_0 - pango=1.50.14=h19c1c8a_2 - prompt_toolkit=3.0.42=hd8ed1ab_0 - pyobjc-framework-cocoa=10.1=py39h8602b6b_0 From 8d1acf87a8caee6c70d9709694cf2945b55ddeb6 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 28 Feb 2024 08:46:04 +0000 Subject: [PATCH 09/13] Remove unnecessary interpreters include_directories in meson.build files --- src/meson.build | 1 - src/sage/ext/meson.build | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/meson.build b/src/meson.build index 0c80bcc0ece..2e7fded9954 100644 --- a/src/meson.build +++ b/src/meson.build @@ -152,7 +152,6 @@ inc_ntl = include_directories('sage/libs/ntl') inc_arb = include_directories('sage/libs/arb') inc_data_structures = include_directories('sage/data_structures') inc_ext = include_directories('sage/ext') -inc_interpreters = include_directories('sage/ext/interpreters') inc_partn_ref2 = include_directories('sage/groups/perm_gps/partn_ref2') inc_src = include_directories('.') diff --git a/src/sage/ext/meson.build b/src/sage/ext/meson.build index 53aa479c12d..5824afb5ab7 100644 --- a/src/sage/ext/meson.build +++ b/src/sage/ext/meson.build @@ -108,7 +108,7 @@ foreach name, pyx : extension_data sources: pyx, subdir: 'sage/ext/interpreters', install: true, - include_directories: [inc_cpython, inc_ext, inc_interpreters, inc_rings, inc_src], + include_directories: [inc_cpython, inc_ext, inc_rings, inc_src], dependencies: [py_dep, cypari2, cysignals, gmp, gsl, mpc, mpfr, pari, interpreters_dep], ) endforeach From e4353083434c70c103e0f8c9fcbb3b2556148a2c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 28 Feb 2024 09:10:23 +0000 Subject: [PATCH 10/13] Fix compilation (arb) --- src/sage/libs/arb/meson.build | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/libs/arb/meson.build b/src/sage/libs/arb/meson.build index 8c6f0375b33..375b45f673c 100644 --- a/src/sage/libs/arb/meson.build +++ b/src/sage/libs/arb/meson.build @@ -19,7 +19,6 @@ py.install_sources( ) extension_data = { - 'arb_version' : files('arb_version.pyx'), 'arith' : files('arith.pyx') } From c83cc2feaf98764c0b5d9f3360a3343047f05e13 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 28 Feb 2024 09:57:09 +0000 Subject: [PATCH 11/13] try to fix interpreter build --- src/sage/calculus/meson.build | 2 +- src/sage/ext/interpreters/meson.build | 85 +++++++++++++++++++ src/sage/ext/meson.build | 85 +------------------ src/sage/meson.build | 2 +- .../autogen/interpreters/__init__.py | 10 +-- 5 files changed, 92 insertions(+), 92 deletions(-) create mode 100644 src/sage/ext/interpreters/meson.build diff --git a/src/sage/calculus/meson.build b/src/sage/calculus/meson.build index 54b02a8b899..60ade235702 100644 --- a/src/sage/calculus/meson.build +++ b/src/sage/calculus/meson.build @@ -28,7 +28,7 @@ foreach name, pyx : extension_data subdir: 'sage/calculus', install: true, include_directories: [inc_ext, inc_numpy], - dependencies: [py_dep, cysignals, gmp, gsl], + dependencies: [py_dep, cysignals, gmp, gsl, interpreters_dep], ) endforeach diff --git a/src/sage/ext/interpreters/meson.build b/src/sage/ext/interpreters/meson.build new file mode 100644 index 00000000000..68d87afef6f --- /dev/null +++ b/src/sage/ext/interpreters/meson.build @@ -0,0 +1,85 @@ + +interpreters = custom_target( + 'sage.ext.interpreters', + output: [ + 'all.py', + 'wrapper_cc.pxd', + 'wrapper_cdf.pxd', + 'wrapper_el.pxd', + 'wrapper_py.pxd', + 'wrapper_rdf.pxd', + 'wrapper_rr.pxd', + 'wrapper_cc.pyx', + 'wrapper_cdf.pyx', + 'wrapper_el.pyx', + 'wrapper_py.pyx', + 'wrapper_rdf.pyx', + 'wrapper_rr.pyx', + ], + input: '../../../sage_setup/autogen/interpreters/__init__.py', + command: [py, '-m', 'sage_setup.autogen.interpreters','@OUTDIR@'], + env: ['PYTHONPATH=' + meson.current_source_dir() / '..' / '..' / '..'], + # Manually install the generated files instead of using install_sources + # this is a workaround for https://github.com/mesonbuild/meson/issues/7372 + install: true, + install_dir: py.get_install_dir() / 'sage/ext/interpreters', + install_tag: 'python-runtime', +) + +# Use this once https://github.com/mesonbuild/meson/issues/7372 is fixed +#foreach file : interpreters.to_list() +# py.install_sources( +# file.full_path(), +# subdir : 'sage/ext/interpreters' +# ) +#endforeach + +extension_data = { + 'wrapper_cc' : interpreters[7], + 'wrapper_cdf' : interpreters[8], + 'wrapper_el' : interpreters[9], + 'wrapper_py' : interpreters[10], + 'wrapper_rdf' : interpreters[11], + 'wrapper_rr' : interpreters[12], +} + +# Manually create header files, which otherwise are not found +wrapper_el_header = custom_target( + 'wrapper_el.h', + output : 'wrapper_el.h', + input : [interpreters[9], interpreters], + command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../../')], +) +wrapper_cc_header = custom_target( + 'wrapper_cc.h', + output : 'wrapper_cc.h', + input : [interpreters[7], interpreters], + command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../../')], +) +wrapper_cdf_header = custom_target( + 'wrapper_cdf.h', + output : 'wrapper_cdf.h', + input : [interpreters[8], interpreters], + command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../../')], +) +wrapper_rr_header = custom_target( + 'wrapper_rr.h', + output : 'wrapper_rr.h', + input : [interpreters[12], interpreters], + command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../../')], +) + +interpreters_dep = declare_dependency( + sources: [wrapper_el_header, wrapper_cc_header, wrapper_cdf_header, wrapper_rr_header], +) + + +foreach name, pyx : extension_data + py.extension_module(name, + sources: pyx, + subdir: 'sage/ext/interpreters', + install: true, + include_directories: [inc_cpython, inc_ext, inc_rings, inc_src], + dependencies: [py_dep, cypari2, cysignals, gmp, gsl, mpc, mpfr, pari, interpreters_dep], + ) +endforeach diff --git a/src/sage/ext/meson.build b/src/sage/ext/meson.build index 5824afb5ab7..7cacc1367d8 100644 --- a/src/sage/ext/meson.build +++ b/src/sage/ext/meson.build @@ -28,87 +28,4 @@ foreach name, pyx : extension_data ) endforeach -interpreters = custom_target( - 'sage.ext.interpreters', - output: [ - 'all.py', - 'wrapper_cc.pxd', - 'wrapper_cdf.pxd', - 'wrapper_el.pxd', - 'wrapper_py.pxd', - 'wrapper_rdf.pxd', - 'wrapper_rr.pxd', - 'wrapper_cc.pyx', - 'wrapper_cdf.pyx', - 'wrapper_el.pyx', - 'wrapper_py.pyx', - 'wrapper_rdf.pyx', - 'wrapper_rr.pyx', - ], - input: '../../sage_setup/autogen/interpreters/__init__.py', - command: [py, '-m', 'sage_setup.autogen.interpreters','@OUTDIR@'], - env: ['PYTHONPATH=' + meson.current_source_dir() / '..' / '..'], - # Manually install the generated files instead of using install_sources - # this is a workaround for https://github.com/mesonbuild/meson/issues/7372 - install: true, - install_dir: py.get_install_dir() / 'sage/ext/interpreters', - install_tag: 'python-runtime', -) - -# Use this once https://github.com/mesonbuild/meson/issues/7372 is fixed -#foreach file : interpreters.to_list() -# py.install_sources( -# file.full_path(), -# subdir : 'sage/ext/interpreters' -# ) -#endforeach - -extension_data = { - 'wrapper_cc' : interpreters[7], - 'wrapper_cdf' : interpreters[8], - 'wrapper_el' : interpreters[9], - 'wrapper_py' : interpreters[10], - 'wrapper_rdf' : interpreters[11], - 'wrapper_rr' : interpreters[12], -} - -# Manually create header files, which otherwise are not found -wrapper_el_header = custom_target( - 'wrapper_el.h', - output : 'wrapper_el.h', - input : [interpreters[9], interpreters], - command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../')], -) -wrapper_cc_header = custom_target( - 'wrapper_cc.h', - output : 'wrapper_cc.h', - input : [interpreters[7], interpreters], - command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../')], -) -wrapper_cdf_header = custom_target( - 'wrapper_cdf.h', - output : 'wrapper_cdf.h', - input : [interpreters[8], interpreters], - command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../')], -) -wrapper_rr_header = custom_target( - 'wrapper_rr.h', - output : 'wrapper_rr.h', - input : [interpreters[12], interpreters], - command : [cython.cmd_array(), '@INPUT0@', '-o', '@OUTPUT@', '-I', join_paths(meson.current_source_dir(), '../../')], -) - -interpreters_dep = declare_dependency( - sources: [wrapper_el_header, wrapper_cc_header, wrapper_cdf_header, wrapper_rr_header], -) - - -foreach name, pyx : extension_data - py.extension_module(name, - sources: pyx, - subdir: 'sage/ext/interpreters', - install: true, - include_directories: [inc_cpython, inc_ext, inc_rings, inc_src], - dependencies: [py_dep, cypari2, cysignals, gmp, gsl, mpc, mpfr, pari, interpreters_dep], - ) -endforeach +subdir('interpreters') diff --git a/src/sage/meson.build b/src/sage/meson.build index d505ccfecdf..267223db51e 100644 --- a/src/sage/meson.build +++ b/src/sage/meson.build @@ -97,13 +97,13 @@ subdir('misc') subdir('structure') subdir('algebras') subdir('arith') +subdir('ext') subdir('calculus') subdir('categories') subdir('coding') subdir('combinat') subdir('crypto') subdir('data_structures') -subdir('ext') subdir('functions') subdir('games') subdir('geometry') diff --git a/src/sage_setup/autogen/interpreters/__init__.py b/src/sage_setup/autogen/interpreters/__init__.py index 87dae60bce7..ed4b0c52238 100644 --- a/src/sage_setup/autogen/interpreters/__init__.py +++ b/src/sage_setup/autogen/interpreters/__init__.py @@ -109,20 +109,18 @@ # that will have to be changed. ##################################################################### -from __future__ import print_function, absolute_import +from __future__ import absolute_import, print_function import os - from os.path import getmtime -from .generator import InterpreterGenerator, AUTOGEN_WARN +from .generator import AUTOGEN_WARN, InterpreterGenerator from .instructions import * from .memory import * from .specs.base import * from .storage import * from .utils import * - # Tuple of (filename_root, extension, method) where filename_root is the # root of the filename to be joined with "_".ext and # method is the name of a get_ method on InterpreterGenerator that returns @@ -197,7 +195,7 @@ def rebuild(dirname, force=False, interpreters=None, distribution=None): sage: testdir = tmp_dir() sage: rebuild(testdir, interpreters=['Element', 'Python'], ....: distribution='sagemath-categories') - Building interpreters for fast_callable + Generating interpreters for fast_callable in ... -> First build of interpreters sage: with open(testdir + '/all__sagemath_categories.py') as f: ....: f.readline() @@ -205,7 +203,7 @@ def rebuild(dirname, force=False, interpreters=None, distribution=None): """ # This line will show up in "sage -b" (once per upgrade, not every time # you run it). - print("Building interpreters for fast_callable") + print(f"Generating interpreters for fast_callable in {dirname}") if interpreters is None: interpreters = ['CDF', 'Element', 'Python', 'RDF', 'RR', 'CC'] From a1e41c1dd526a1c826b7839cad831b3a0965051c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 28 Feb 2024 10:48:33 +0000 Subject: [PATCH 12/13] More fun with interpreters --- src/sage/calculus/meson.build | 2 +- src/sage/ext/interpreters/meson.build | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/calculus/meson.build b/src/sage/calculus/meson.build index 60ade235702..e11ac5a0a32 100644 --- a/src/sage/calculus/meson.build +++ b/src/sage/calculus/meson.build @@ -27,7 +27,7 @@ foreach name, pyx : extension_data sources: pyx, subdir: 'sage/calculus', install: true, - include_directories: [inc_ext, inc_numpy], + include_directories: [inc_numpy], dependencies: [py_dep, cysignals, gmp, gsl, interpreters_dep], ) endforeach diff --git a/src/sage/ext/interpreters/meson.build b/src/sage/ext/interpreters/meson.build index 68d87afef6f..fb54f2abe7f 100644 --- a/src/sage/ext/interpreters/meson.build +++ b/src/sage/ext/interpreters/meson.build @@ -71,6 +71,7 @@ wrapper_rr_header = custom_target( interpreters_dep = declare_dependency( sources: [wrapper_el_header, wrapper_cc_header, wrapper_cdf_header, wrapper_rr_header], + include_directories : include_directories('.') ) From 0d5f0888ca8156e3933f676ec2bc002aeafdb712 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 28 Feb 2024 13:55:52 +0000 Subject: [PATCH 13/13] Add build directory as include directory for Cython compilation --- src/meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/src/meson.build b/src/meson.build index 2e7fded9954..69b06d5bef9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -128,6 +128,7 @@ ntl = cc.find_library('ntl', required: true) # have to add them manually. # https://github.com/mesonbuild/meson/issues/9562 add_project_arguments('-I', meson.current_source_dir(), language : 'cython') +add_project_arguments('-I', meson.current_build_dir(), language : 'cython') # Add global compiler flags add_project_arguments('-X auto_pickle=False', language : 'cython')