似乎
setuptools没有提供完全更改或摆脱后缀的选项。魔术发生在
distutils/command/build_ext.py:
def get_ext_filename(self, ext_name): 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似乎我将需要添加构建后重命名操作。
从08/12/2016更新:
好的,我忘了实际发布解决方案。实际上,我通过重载内置
install_lib命令来实现了重命名操作。这是逻辑:
from distutils.command.install_lib import install_lib as _install_libdef batch_rename(src, dst, src_dir_fd=None, dst_dir_fd=None): '''Same as os.rename, but returns the renaming result.''' os.rename(src, dst, src_dir_fd=src_dir_fd, dst_dir_fd=dst_dir_fd) return dstclass _CommandInstallCythonized(_install_lib): def __init__(self, *args, **kwargs): _install_lib.__init__(self, *args, **kwargs) def install(self): # let the distutils' install_lib do the hard work outfiles = _install_lib.install(self) # batch rename the outfiles: # for each file, match string between # second last and last dot and trim it matcher = re.compile('.([^.]+).so$') return [batch_rename(file, re.sub(matcher, '.so', file)) for file in outfiles]现在您要做的就是在
setup函数中重载命令:
setup( ... cmdclass={ 'install_lib': _CommandInstallCythonized, }, ...)尽管如此,我对重载标准命令还是不满意。如果您找到更好的解决方案,请将其发布,我会接受您的回答。



