Skip to content

Commit c7cfbc0

Browse files
committed
Build python in setup
Ensure that the Python build method is called when running setup so that the C++ template strings are always in line with the C++ code.
1 parent 20747ba commit c7cfbc0

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

parametric_plasma_source/build_python.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
py_file = "source.py"
99

10-
if os.path.exists(py_file):
11-
os.remove(py_file)
12-
1310
def write_disclaimer(py_file_path):
1411
disclaimer = "\"\"\"\n"
1512
disclaimer += "Auto-generated file. To edit, run `python build_python.py`.\n"
@@ -29,8 +26,31 @@ def generate_variable(cpp_file_path, variable_name, py_file_path, end_str="\n\n"
2926
with open(py_file_path, "a+") as f_py:
3027
f_py.write(py_lines)
3128

32-
write_disclaimer(py_file)
33-
generate_variable(source_sampling_cpp, "source_sampling_cpp", py_file)
34-
generate_variable(plasma_source_cpp, "plasma_source_cpp", py_file)
35-
generate_variable(plasma_source_hpp, "plasma_source_hpp", py_file)
36-
generate_variable(make_file, "make_file", py_file, "\n")
29+
def build(source_dir="."):
30+
output_path = os.path.join(source_dir, py_file)
31+
32+
if os.path.exists(output_path):
33+
os.remove(output_path)
34+
35+
write_disclaimer(output_path)
36+
generate_variable(
37+
os.path.join(source_dir, source_sampling_cpp),
38+
"source_sampling_cpp",
39+
output_path
40+
)
41+
generate_variable(
42+
os.path.join(source_dir, plasma_source_cpp),
43+
"plasma_source_cpp",
44+
output_path
45+
)
46+
generate_variable(
47+
os.path.join(source_dir, plasma_source_hpp),
48+
"plasma_source_hpp",
49+
output_path
50+
)
51+
generate_variable(
52+
os.path.join(source_dir, make_file),
53+
"make_file",
54+
output_path,
55+
"\n"
56+
)

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from setuptools import setup, find_packages, Extension
66
from setuptools.command.build_ext import build_ext
77

8+
from parametric_plasma_source.build_python import build as build_python
89

910
class CMakeExtention(Extension):
1011
def __init__(self, name, sourcedir=""):
@@ -63,6 +64,8 @@ def build_extension(self, ext):
6364
with open("README.md", "r") as fh:
6465
long_description = fh.read()
6566

67+
build_python(source_dir="parametric_plasma_source")
68+
6669
setup(
6770
name="parametric_plasma_source",
6871
version="0.0.6",

0 commit comments

Comments
 (0)