Hi all,
I’ve posted this to poetry, but was directed to PyPA, so I’m reposting here.
Background
Python has historically used runtime functions like ctypes.util.find_library
by invoking ldconfig
and gcc
to get the flags and libraries for native dependencies.
Not only does this cause performance issues on startup, but it’s also extremely inconvenient to provide such information at runtime when it’s primarily a configuration matter.
There are tons of patches in nixpkgs to support this. Most importantly, it makes the whole Python development experience on Nix(OS) nearly unusable.
Moreover, setting LD_LIBRARY_PATH
to discover the paths at runtime causes numerous issues. As a result, we’re exploring using manylinux at devenv.sh, but we’d like to address this issue properly within Python packaging.
Implementation
At the time of installing a package, the pkg-config
executable would be invoked to collect metadata from .pc
files.
The resulting metadata would be stored in a parseable format as the primary source for ctypes.util.find_library
(retaining the current logic as a fallback). This would also serve importlib_metadata
for querying the information at runtime.
Proposal
We propose supporting a pkgconfig section in pyproject.toml
itself, inspired by the autotools interface.
tomlCopy code
[pkgconfig.dependencies]
gtk-2.0 = {version = "^3.0", platform = "darwin"}
zlib = "*"
Dependency alternatives
At times, there might be a need to fallback to another library, so we can accommodate that as well:
tomlCopy code
[pkgconfig.dependencies]
libsodium = {version = "*", alternative = "openssl = *" }
Runtime querying
importlib_metadata
would be augmented to include pkgconfig
metadata.
Open Questions
How should we address cases where pkg-config
is unavailable? Consider how this impacted the cabal implementation.
Note that I’d like to gather feedback, hopefully we can turn it into a PEP.
Domen