|
| 1 | +import os |
| 2 | + |
| 3 | +plasma_source_cpp = "plasma_source.cpp" |
| 4 | +plasma_source_hpp = "plasma_source.hpp" |
| 5 | +source_sampling_cpp = "source_sampling.cpp" |
| 6 | +make_file = "Makefile" |
| 7 | + |
| 8 | +py_file = "source.py" |
| 9 | + |
| 10 | +if os.path.exists(py_file): |
| 11 | + os.remove(py_file) |
| 12 | + |
| 13 | +def write_disclaimer(py_file_path): |
| 14 | + disclaimer = "\"\"\"\n" |
| 15 | + disclaimer += "Auto-generated file. To edit, run `python build_python.py`.\n" |
| 16 | + disclaimer += "This will need to be run whenever a new C++ version is made available.\n" |
| 17 | + disclaimer += "\"\"\"\n\n" |
| 18 | + with open(py_file_path, "a+") as f_py: |
| 19 | + f_py.write(disclaimer) |
| 20 | + |
| 21 | +def generate_variable(cpp_file_path, variable_name, py_file_path, end_str="\n\n"): |
| 22 | + with open(cpp_file_path, "r") as f_cpp: |
| 23 | + lines = f_cpp.readlines() |
| 24 | + py_lines = variable_name |
| 25 | + py_lines += " = (\n\"\"\"" |
| 26 | + py_lines += "".join(lines) |
| 27 | + py_lines += "\"\"\"\n)" |
| 28 | + py_lines += end_str |
| 29 | + with open(py_file_path, "a+") as f_py: |
| 30 | + f_py.write(py_lines) |
| 31 | + |
| 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") |
0 commit comments