Skip to content

Commit 20747ba

Browse files
authored
Merge pull request #1 from DanShort12/read_cpp_files
Read C++ and Makefile files into Python file
2 parents 4be816e + 439e321 commit 20747ba

4 files changed

Lines changed: 683 additions & 579 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
*.out
3232
*.app
3333

34+
35+
# Compiled Python
36+
*.pyc
37+
3438
# Build path
3539
build/
3640
dist/
@@ -39,3 +43,4 @@ dist/
3943
# Python
4044
__pycache__/
4145
*.py[cod]
46+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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

Comments
 (0)