Skip to content

setup.py: look up pycairo headers without importing the module

Up until now pycairo provided a cairo.get_include() helper which could be used to find the required include directory matching the module, considering various scenarios.

Starting with 3.8 this leads to problems on Windows since CPython on Windows will no longer use PATH for the DLL lookup and expects the library user to explicitely pass the directory where the cairo DLL can be found.

In a build environment the user has no control over this though, so we have to find the include directory without loading/importing pycairo again.

This now uses a combination of importlib.util.find_spec() for finding the module and importlib.metadata.distribution() for finding the package version.

Hopefully this covers all cases.

Merge request reports