Use generate_docstring_hpp.py of opm-common and delete the one here

This commit is contained in:
Lisa Julia Nebel
2024-05-16 15:45:49 +02:00
parent eea42f7363
commit fa3392fb7d
2 changed files with 7 additions and 43 deletions

View File

@@ -1,41 +0,0 @@
import json
import sys
def generate_hpp_from_json(json_path: str, output_hpp_path: str):
with open(json_path, 'r', encoding='utf-8') as file:
docstrings = json.load(file)
hpp_content = """\
#ifndef PYBLACKOILSIMULATORDOC_HPP
#define PYBLACKOILSIMULATORDOC_HPP
// Generated docstrings for PyBlackOilSimulator
namespace Opm::Pybind::DocStrings {
"""
for func_name, info in docstrings.items():
signature = info['signature']
doc = info['doc'].replace('\n', '\n ')
hpp_content += f"""
static constexpr char {func_name}_docstring[] = R\"doc(
{doc}
)doc\";\n"""
hpp_content += """\
} // namespace Opm::Pybind::DocStrings
#endif // PYBLACKOILSIMULATORDOC_HPP
"""
with open(output_hpp_path, 'w', encoding='utf-8') as file:
file.write(hpp_content)
if __name__ == "__main__":
# Check that exactly two command line arguments are provided
if len(sys.argv) != 3:
print("Usage: python generate_docstring_hpp.py <json_path> <output_hpp_path>")
sys.exit(1)
# Extract json_path and output_hpp_path from command line arguments
json_path = sys.argv[1]
output_hpp_path = sys.argv[2]
generate_hpp_from_json(json_path, output_hpp_path)

View File

@@ -7,11 +7,16 @@ set(PYTHON_DOCSTRINGS_GENERATED_HPP "${PROJECT_BINARY_DIR}/python/PyBlackOilSimu
# ${PYTHON_EXECUTABLE} is set there to ${Python3_EXECUTABLE}
#
# Command to run the Python script
find_file(PYTHON_GENERATE_DOCSTRINGS_PY generate_docstring_hpp.py
PATHS ${opm-common_DIR} ${opm-common_PYTHON_COMMON_DIR}
PATH_SUFFIXES python NO_DEFAULT_PATH REQUIRED)
add_custom_command(
OUTPUT ${PYTHON_DOCSTRINGS_GENERATED_HPP}
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_SOURCE_DIR}
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/python/generate_docstring_hpp.py
${PYTHON_DOCSTRINGS_FILE} ${PYTHON_DOCSTRINGS_GENERATED_HPP}
${PYTHON_EXECUTABLE} ${PYTHON_GENERATE_DOCSTRINGS_PY}
${PYTHON_DOCSTRINGS_FILE} ${PYTHON_DOCSTRINGS_GENERATED_HPP} PYBLACKOILSIMULATORDOC_HPP "Opm::Pybind::DocStrings"
DEPENDS ${PYTHON_DOCSTRINGS_FILE}
COMMENT "Generating PyBlackOilSimulatorDoc.hpp from JSON file"
)