Skip to content

Commit 0914e94

Browse files
authored
BLD: Add meson build scripts (#49114)
* BLD: Add script to generate pxi from pxi.in for meson * BLD: Add scripts to generate the project version
1 parent e7e5df5 commit 0914e94

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Diff for: scripts/generate_pxi.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import argparse
2+
import os
3+
4+
from Cython import Tempita
5+
6+
7+
def process_tempita(pxifile, outfile):
8+
with open(pxifile) as f:
9+
tmpl = f.read()
10+
pyxcontent = Tempita.sub(tmpl)
11+
12+
with open(outfile, "w") as f:
13+
f.write(pyxcontent)
14+
15+
16+
def main():
17+
parser = argparse.ArgumentParser()
18+
parser.add_argument("infile", type=str, help="Path to the input file")
19+
parser.add_argument("-o", "--outdir", type=str, help="Path to the output directory")
20+
args = parser.parse_args()
21+
22+
if not args.infile.endswith(".in"):
23+
raise ValueError(f"Unexpected extension: {args.infile}")
24+
25+
outdir_abs = os.path.join(os.getcwd(), args.outdir)
26+
outfile = os.path.join(
27+
outdir_abs, os.path.splitext(os.path.split(args.infile)[1])[0]
28+
)
29+
30+
process_tempita(args.infile, outfile)
31+
32+
33+
main()

Diff for: scripts/generate_version.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import argparse
2+
import os
3+
4+
import versioneer
5+
6+
7+
def write_version_info(path):
8+
if os.environ.get("MESON_DIST_ROOT"):
9+
# raise ValueError("dist root is", os.environ.get("MESON_DIST_ROOT"))
10+
path = os.path.join(os.environ.get("MESON_DIST_ROOT"), path)
11+
with open(path, "w") as file:
12+
file.write(f'__version__="{versioneer.get_version()}"\n')
13+
file.write(
14+
f'__git_version__="{versioneer.get_versions()["full-revisionid"]}"\n'
15+
)
16+
17+
18+
def main():
19+
parser = argparse.ArgumentParser()
20+
parser.add_argument(
21+
"-o", "--outfile", type=str, help="Path to write version info to"
22+
)
23+
args = parser.parse_args()
24+
25+
if not args.outfile.endswith(".py"):
26+
raise ValueError(
27+
f"Output file must be a Python file. "
28+
f"Got: {args.outfile} as filename instead"
29+
)
30+
31+
write_version_info(args.outfile)
32+
33+
34+
main()

0 commit comments

Comments
 (0)