此行为已在distutils包中定义。distutils使用sysconfig和“EXT_SUFFIX”配置变量:# Lib\distutils\command\build_ext.py
def get_ext_filename(self, ext_name):
r"""Convert the name of an extension (eg. "foo.bar") into the name
of the file from which it will be loaded (eg. "foo/bar.so", or
"foo\bar.pyd").
"""
from distutils.sysconfig import get_config_var
ext_path = ext_name.split('.')
ext_suffix = get_config_var('EXT_SUFFIX')
return os.path.join(*ext_path) + ext_suffix
从python3.5开始,“EXT_SUFFIX”变量包含平台信息,例如“.cp35-win_amd64”。在
我编写了以下函数:
^{pr2}$
和自定义build\u ext命令:from Cython.Distutils import build_ext
class BuildExtWithoutPlatformSuffix(build_ext):
def get_ext_filename(self, ext_name):
filename = super().get_ext_filename(ext_name)
return get_ext_filename_without_platform_suffix(filename)
用法:setup(
...
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
...
)