Skip to content

Commit

Permalink
pybamm-team#3480 Modify logic that finds pybind11 CMake files
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Nov 25, 2023
1 parent 9855e9d commit 60da4cb
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,36 +251,33 @@ def run(self):

def compile_KLU():
# Return whether or not the KLU extension should be compiled.
# Return True if:
# - Not running on Windows AND
# - CMake is found AND
# - The pybind11/ directory is found in the PyBaMM project directory
# Return True if all three of the following conditions are met:
# - Not running on Windows
# - CMake is found
# - pybind11 is found as a build-time dependency
CMakeFound = True
PyBind11Found = True
windows = (not system()) or system() == "Windows"

msg = "Running on Windows" if windows else "Not running on windows"
logger.info(msg)
windows_msg = "Running on Windows" if windows else "Not running on Windows"
pybind11_msg = "Could not find pybind11. Skipping compilation of KLU module."

logger.info(windows_msg)

try:
subprocess.run(["cmake", "--version"])
logger.info("Found CMake.")
except OSError:
CMakeFound = False
logger.info("Could not find CMake. Skipping compilation of KLU module.")

pybamm_project_dir = os.path.dirname(os.path.abspath(__file__))
pybind11_dir = os.path.join(pybamm_project_dir, "pybind11")
try:
open(os.path.join(pybind11_dir, "tools", "pybind11Tools.cmake"))
logger.info("Found pybind11 directory ({})".format(pybind11_dir))
except FileNotFoundError:
from pybind11 import get_cmake_dir
pybind11_config = os.path.join(get_cmake_dir(), "pybind11Tools.cmake")
logger.info(f"Found pybind11 at {pybind11_config}")
except ModuleNotFoundError or FileNotFoundError:
logger.info(pybind11_msg)

PyBind11Found = False
msg = (
"Could not find PyBind11 directory ({})."
" Skipping compilation of KLU module.".format(pybind11_dir)
)
logger.info(msg)

return CMakeFound and PyBind11Found

Expand Down

0 comments on commit 60da4cb

Please sign in to comment.