For a couple projects I’m working on, I need to be able to identify binary extension files and extract the names of the modules they provide. importlib.machinery.EXTENSION_SUFFIXES
only gives me what I need for the current Python and the machine it’s running on, whereas I need to work with extension files for any Python. There doesn’t seem to be a library for this already, so I’ve had to investigate this on my own, and I’ve come to you to double-check my findings.
What I’ve determined so far:
-
Linux/manylinux binary extension modules have names of the form
{module}.{implementation}-{abi}-{arch}-linux-gnu.so
(Can thegnu
part vary, or is that attached tolinux
?). Example:foo.cpython-38-x86_64-linux-gnu.so
-
macOS binary extension modules have names of the form
{module}.{implementation}-{abi}-darwin.so
-
Windows binary extension modules have names of the form
{module}.{impl_abbrev}{abi}-{win}.pyd
wherewin
iswin_amd64
orwin32
(or other values?). Example:foo.cp38-win_amd64.pyd
-
Certain Linux & macOS extension modules (ones built for Python 2?) have names simply of the form
{module}.so
.
Is there anything important I’ve missed? Would r'(?:\.[-A-Za-z0-9_]+\.(?:pyd|so)|\.so)\Z'
be an appropriate regex for matching any & all binary extension module file extensions?