Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions codepy/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ def get_numpy_incpath() -> str:

def add_py_module(toolchain: Toolchain, name: str) -> None:
def get_module_include_path(name: str) -> str:
from importlib.resources import files
return str(files(name) / "include")
from importlib.util import find_spec
spec = find_spec(name)
if spec is None:
raise RuntimeError(f"Could not find module '{name}'")
libdir = spec.submodule_search_locations
assert libdir is not None
from os.path import join
return join(libdir[0], "include")
Comment on lines +188 to +195
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from importlib.resources.files to find_spec with submodule_search_locations makes this function consistent with add_numpy above, but moves away from the more modern and robust approach. The importlib.resources.files API is the recommended way to access package resources and works with any import mechanism including zip files, while the new approach assumes filesystem-based packages. For this use case (finding C/C++ include directories), filesystem-based packages are expected, so the practical impact is minimal. However, if consistency is the goal, consider updating add_numpy to also use importlib.resources.files for better maintainability.

Copilot uses AI. Check for mistakes.

toolchain.add_library(name, [get_module_include_path(name)], [], [])

Expand Down
Loading