diff options
author | Ralf Gommers <ralf.gommers@gmail.com> | 2022-11-23 23:40:23 +0100 |
---|---|---|
committer | Ralf Gommers <ralf.gommers@gmail.com> | 2022-11-25 12:37:46 +0100 |
commit | 4002a7d421ff10780c28a3643683af7a9754f87f (patch) | |
tree | a06d4c10642d1c93d552f80f1e90f393c9953c18 /numpy/_build_utils/tempita.py | |
parent | 632f573f12c641990bfac24cf4df435804340a7f (diff) | |
download | numpy-4002a7d421ff10780c28a3643683af7a9754f87f.tar.gz |
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 <stefanv@berkeley.edu>
Diffstat (limited to 'numpy/_build_utils/tempita.py')
-rwxr-xr-x | numpy/_build_utils/tempita.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/numpy/_build_utils/tempita.py b/numpy/_build_utils/tempita.py new file mode 100755 index 000000000..3bcc789c5 --- /dev/null +++ b/numpy/_build_utils/tempita.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import sys +import os +import argparse + +from Cython import Tempita as tempita + +# XXX: If this import ever fails (does it really?), vendor either +# cython.tempita or numpy/npy_tempita. + + +def process_tempita(fromfile, outfile=None): + """Process tempita templated file and write out the result. + + The template file is expected to end in `.c.in` or `.pyx.in`: + E.g. processing `template.c.in` generates `template.c`. + + """ + if outfile is None: + # We're dealing with a distutils build here, write in-place + outfile = os.path.splitext(fromfile)[0] + + from_filename = tempita.Template.from_filename + template = from_filename(fromfile, encoding=sys.getdefaultencoding()) + + content = template.substitute() + + 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('.in'): + raise ValueError(f"Unexpected extension: {args.infile}") + + outfile_abs = os.path.join(os.getcwd(), args.outfile) + process_tempita(args.infile, outfile_abs) + + +if __name__ == "__main__": + main() |