Skip to content

Commit

Permalink
Allow libclang path to be found or set
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcoe committed Mar 31, 2024
1 parent b4af43b commit cbac218
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion test_py_cppmodel.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit cbac218

Please sign in to comment.