From 4002a7d421ff10780c28a3643683af7a9754f87f Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Wed, 23 Nov 2022 23:40:23 +0100 Subject: BLD: enable building NumPy with Meson This enables building with NumPy on Linux and macOS. Windows support should be complete to, but is untested as of now and may need a few tweaks. This contains: - A set of `meson.build` files and related code generation script tweaks, header templates, etc. - One CI job on Linux - Basic docs on using Meson to build NumPy (not yet integrated in the html docs, it's too early for that - this is for early adopters right now). The build should be complete, with the major exception of SIMD support. The full test suite passes. See gh-22546 for the tracking issue with detailed notes on the plan for switching NumPy to Meson as its build system. Co-authored-by: Stefan van der Walt --- numpy/_build_utils/process_src_template.py | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 numpy/_build_utils/process_src_template.py (limited to 'numpy/_build_utils/process_src_template.py') diff --git a/numpy/_build_utils/process_src_template.py b/numpy/_build_utils/process_src_template.py new file mode 100644 index 000000000..4a0915e25 --- /dev/null +++ b/numpy/_build_utils/process_src_template.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +import sys +import os +import argparse +import importlib.util + + +def get_processor(): + # Convoluted because we can't import from numpy.distutils + # (numpy is not yet built) + conv_template_path = os.path.join( + os.path.dirname(__file__), + '..', 'distutils', 'conv_template.py' + ) + spec = importlib.util.spec_from_file_location( + 'conv_template', conv_template_path + ) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod.process_file + + +def process_and_write_file(fromfile, outfile): + """Process tempita templated file and write out the result. + + The template file is expected to end in `.src` + (e.g., `.c.src` or `.h.src`). + Processing `npy_somefile.c.src` generates `npy_somefile.c`. + + """ + process_file = get_processor() + content = process_file(fromfile) + with open(outfile, 'w') as f: + f.write(content) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "infile", + type=str, + help="Path to the input file" + ) + parser.add_argument( + "-o", + "--outfile", + type=str, + help="Path to the output file" + ) + parser.add_argument( + "-i", + "--ignore", + type=str, + help="An ignored input - may be useful to add a " + "dependency between custom targets", + ) + args = parser.parse_args() + + if not args.infile.endswith('.src'): + raise ValueError(f"Unexpected extension: {args.infile}") + + outfile_abs = os.path.join(os.getcwd(), args.outfile) + process_and_write_file(args.infile, outfile_abs) + + +if __name__ == "__main__": + main() -- cgit v1.2.1