栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

更改.so文件的Cython命名规则

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

更改.so文件的Cython命名规则

似乎

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,    },    ...)

尽管如此,我对重载标准命令还是不满意。如果您找到更好的解决方案,请将其发布,我会接受您的回答。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/660957.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号