diff --git a/test.sh b/test.sh index 8e009e5..b46ce68 100755 --- a/test.sh +++ b/test.sh @@ -7,4 +7,5 @@ python3 -m venv .venv # Create a Python virtual env source ./.venv/bin/activate # Activate the virtual env for bash by source. python -m mypy *.py --check-untyped-defs # Run mypy to check type hints +PY_CPPMODEL_LIBCLANG_PATH=/Library/Developer/CommandLineTools/usr/lib/libclang.dylib \ python -m unittest discover . # Run tests diff --git a/test_py_cppmodel.py b/test_py_cppmodel.py index 0f2b58c..5affa53 100644 --- a/test_py_cppmodel.py +++ b/test_py_cppmodel.py @@ -1,8 +1,17 @@ import clang +import os import py_cppmodel import unittest -clang.cindex.Config.set_library_path("/Library/Developer/CommandLineTools/usr/lib/") # type: ignore +from ctypes.util import find_library + +LIBCLANG_PATH = os.environ.get("PY_CPPMODEL_LIBCLANG_PATH") +if not LIBCLANG_PATH: + LIBCLANG_PATH = find_library("clang") + if not LIBCLANG_PATH: + raise RuntimeError("PY_CPPMODEL_LIBCLANG_PATH is unset") + +clang.cindex.Config.set_library_file(LIBCLANG_PATH) # type: ignore from clang.cindex import TranslationUnit