diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0c4ddccf90e05122277901c3cfbf4c9b2957cb68..bbb5ac77747722108e18ff4e0208b14bd76cb16e 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,2 +1,11 @@ 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() diff --git a/python/dumux/common/properties.py b/python/dumux/common/properties.py index e72dc23f05a089a4c44c2a4fd62f0ab2ca22f696..0e791e1edb85fa349ecefef5fa5444035b7dce98 100644 --- a/python/dumux/common/properties.py +++ b/python/dumux/common/properties.py @@ -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: