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
4 changes: 2 additions & 2 deletions codepy/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def get_numpy_incpath() -> str:

def add_py_module(toolchain: Toolchain, name: str) -> None:
def get_module_include_path(name: str) -> str:
from pkg_resources import Requirement, resource_filename
return resource_filename(Requirement.parse(name), f"{name}/include")
from importlib.resources import files
return str(files(name) / "include")

Comment on lines +188 to 190
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.

importlib.resources.files() returns a Traversable that is not guaranteed to be a real filesystem path (e.g., zip/egg installs). Converting it to str and passing it as a compiler -I include dir can yield a non-existent path and break compilation, whereas pkg_resources.resource_filename() previously extracted resources to a real path. Consider resolving the package location via importlib.util.find_spec(...).submodule_search_locations (filesystem-only, like add_numpy) or materializing the directory with importlib.resources.as_file() and ensuring the extracted path remains valid for the entire build.

Suggested change
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")

Copilot uses AI. Check for mistakes.
toolchain.add_library(name, [get_module_include_path(name)], [], [])

Expand Down
Loading