From d4bc1e85ecfebcf85712860948cb41672bcacc12 Mon Sep 17 00:00:00 2001 From: Andrew McNulty Date: Tue, 20 Feb 2024 18:22:40 +0100 Subject: [PATCH] Cython: check for files Pushing in new branch to get it up to GH so I can pull it down to a machine which has an old version of Cython --- mesonbuild/modules/python.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index b100d86d8d39..91d1d845a744 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -216,8 +216,33 @@ def extension_module_method(self, args: T.Tuple[str, T.List[BuildTargetSource]], kwargs['link_args'] = new_link_args cython_compiler = next((c for c in compilers.values() if c.get_id() == 'cython'), None) - if cython_compiler is not None and mesonlib.version_compare(cython_compiler.version, '< 3.0.0'): - mlog.warning(f'Limited API not supported by Cython versions < 3.0.0 (detected: {cython_compiler.version})', location=self.current_node) + if cython_compiler is not None: + # Determine if any of the supplied source files are Cython source. + cython_suffixes = cython_compiler.file_suffixes + def has_cython_files(args: T.List[BuildTargetSource]): + for arg in args: + if isinstance(arg, StructuredSources): + if has_cython_files(arg.as_list()): + return True + continue + if isinstance(arg, GeneratedList): + if has_cython_files(arg.get_outputs()): + return True + continue + + if isinstance(arg, mesonlib.File): + arg = arg.fname + suffix = os.path.splitext(arg)[1][1:].lower() + if suffix in cython_suffixes: + return True + return False + + # Cython's support for the Limited API was added in version 3.0 + def has_cython_limited_api(cython_compiler: compilers.Compiler): + return mesonlib.version_compare(cython_compiler.version, '>= 3.0.0') + + if has_cython_files(args[1]) and not has_cython_limited_api(cython_compiler): + raise mesonlib.MesonException(f'Python Limited API not supported by Cython versions < 3.0.0 (detected {cython_compiler.version})') kwargs['dependencies'] = new_deps