Skip to content

Commit b7c0f4d

Browse files
authored
Checking in generated kernels files separately to help versioning (#141)
* generating kernels separately * unneeded imports [ci skip]
1 parent 1c866e7 commit b7c0f4d

File tree

7 files changed

+3764
-17
lines changed

7 files changed

+3764
-17
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,4 @@ build
1212
*.cpp
1313
.coverage
1414
src/george/george_version.py
15-
src/george/kernels.py
16-
src/george/kerneldefs.pxd
17-
src/george/solvers/kerneldefs.pxd
18-
src/george/include/george/kernels.h
1915
kernels/MyLocalGaussian.yml

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2+
graft vendor/eigen/Eigen
3+
24
exclude .*
35
prune .github
46
prune docs
57
prune paper
8+
prune kernels
9+
prune templates

generate_kernels.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
import glob
6+
import yaml
7+
from jinja2 import Template
8+
9+
10+
def compile_kernels(fns):
11+
template_dir = "templates"
12+
output_dir = os.path.join("src", "george")
13+
14+
with open(os.path.join(template_dir, "parser.h")) as f:
15+
PARSER_TEMPLATE = Template(f.read())
16+
with open(os.path.join(template_dir, "kernels.h")) as f:
17+
CPP_TEMPLATE = Template(f.read())
18+
with open(os.path.join(template_dir, "kernels.py")) as f:
19+
PYTHON_TEMPLATE = Template(f.read())
20+
21+
specs = []
22+
for i, fn in enumerate(fns):
23+
with open(fn, "r") as f:
24+
spec = yaml.load(f.read(), Loader=yaml.FullLoader)
25+
print("Found kernel '{0}'".format(spec["name"]))
26+
spec["index"] = i
27+
spec["reparams"] = spec.get("reparams", {})
28+
specs.append(spec)
29+
print("Found {0} kernel specifications".format(len(specs)))
30+
31+
fn = os.path.join(output_dir, "include", "george", "parser.h")
32+
with open(fn, "w") as f:
33+
print("Saving parser to '{0}'".format(fn))
34+
f.write(PARSER_TEMPLATE.render(specs=specs))
35+
fn = os.path.join(output_dir, "include", "george", "kernels.h")
36+
with open(fn, "w") as f:
37+
print("Saving C++ kernels to '{0}'".format(fn))
38+
f.write(CPP_TEMPLATE.render(specs=specs))
39+
fn = os.path.join(output_dir, "kernels.py")
40+
with open(fn, "w") as f:
41+
print("Saving Python kernels to '{0}'".format(fn))
42+
f.write(PYTHON_TEMPLATE.render(specs=specs))
43+
44+
45+
if __name__ == "__main__":
46+
# If the kernel specifications are included (development mode) re-compile
47+
# them first.
48+
kernel_specs = glob.glob(os.path.join("kernels", "*.yml"))
49+
compile_kernels(kernel_specs)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=40.6.0", "wheel", "setuptools_scm[toml]", "PyYAML", "jinja2", "pybind11"]
2+
requires = ["setuptools>=40.6.0", "wheel", "setuptools_scm[toml]", "pybind11"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.setuptools_scm]

setup.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,11 @@ def compile_kernels(fns):
4444

4545

4646
if __name__ == "__main__":
47-
import sys
48-
import glob
49-
5047
# The include directory for the Eigen headers
5148
localincl = "vendor"
5249
if not os.path.exists(os.path.join(localincl, "eigen", "Eigen", "Core")):
5350
raise RuntimeError("couldn't find Eigen headers")
5451

55-
# If the kernel specifications are included (development mode) re-compile
56-
# them first.
57-
kernel_specs = glob.glob(os.path.join("kernels", "*.yml"))
58-
if len(kernel_specs):
59-
print("Compiling kernels")
60-
compile_kernels(kernel_specs)
61-
if "kernels" in sys.argv:
62-
sys.exit()
63-
6452
include_dirs = [
6553
os.path.join("src", "george", "include"),
6654
os.path.join(localincl, "eigen"),

0 commit comments

Comments
 (0)