Skip to content
Snippets Groups Projects
Commit d8a6a26d authored by Timo Koch's avatar Timo Koch
Browse files

[python] Use metadata file to find properties.hh if available

parent c17e03aa
No related branches found
No related tags found
1 merge request!2934[python] Make bindings work with dune 2.9
add_subdirectory(dumux)
configure_file(setup.py.in setup.py)
# link properties.hh needed by the Python bindings
# to determine the list of properties
# create copy for Windows and symlink otherwise
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
execute_process(COMMAND ${CMAKE_COMMAND} "-E" "copy" "${CMAKE_SOURCE_DIR}/dumux/common/properties.hh" "${CMAKE_CURRENT_BINARY_DIR}/properties.hh")
else()
execute_process(COMMAND ${CMAKE_COMMAND} "-E" "create_symlink" "${CMAKE_SOURCE_DIR}/dumux/common/properties.hh" "${CMAKE_CURRENT_BINARY_DIR}/properties.hh")
endif()
......@@ -7,6 +7,7 @@ import os
from dataclasses import dataclass
from typing import List, Union
from dune.common.hashit import hashIt
import dumux
@dataclass
......@@ -146,12 +147,46 @@ def listTypeTags():
print("\n**********************************")
def predefinedProperties():
"""Create a list of properties defined in properties.hh"""
def propertiesHeaderPath():
"""Find the path to the properties.hh C++ header"""
path, _ = os.path.split(dumux.__file__)
metaDataFile = os.path.join(path, "data/metadata.cmake")
if os.path.exists(metaDataFile):
data = {}
with open(metaDataFile, "r") as metaData:
for line in metaData:
try:
key, value = line.split("=", 1)
data[key] = value.strip()
except ValueError: # no '=' in line
pass
return os.path.abspath(
os.path.join(
data["DEPBUILDDIRS"].split(";")[0],
"python",
"properties.hh",
)
)
# as fall-back try relative path
propertiesHeader = os.path.abspath(
os.path.dirname(__file__) + "/../../../../dumux/common/properties.hh"
os.path.join(
os.path.dirname(__file__),
"../../../../dumux/common/properties.hh",
)
)
if os.path.exists(propertiesHeader):
return propertiesHeader
raise RuntimeError("Could not find properties.hh header")
def predefinedProperties():
"""Create a list of properties defined in properties.hh"""
propertiesHeader = propertiesHeaderPath()
with open(propertiesHeader, encoding="utf-8") as header:
properties = []
for line in header:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment