python扩展文件_向Python扩展添加输出文件

我定义了一个自定义的build_ext来构建一个有趣的扩展,我试图使pip友好。以下是我正在做的事情的精简版。在foo_ext = Extension(

name='foo/_foo',

sources=foo_sources,

)

class MyBuildExt(build_ext):

def build_extension(self, ext):

# This standalone script builds the __init__.py file

# and some .h files for the extension

check_call(['python', 'build_init_file.py'])

# Now that we've created all the init and .h code

# build the C/C++ extension using setuptools/distutils

build_ext.build_extension(self, ext)

# Include the generated __init__.py in the build directory

# which is something like `build/lib.linux-x86/foo/`.

# How can I get setuptools/distutils to install the

# generated file automatically?!

generated_file = 'Source/foo/__init__.py'

output_path = '/'.join(self.get_outputs()[0].split('/')[:-1])

self.move_file(generated_file, output_path)

setup(

...,

ext_modules = [foo_ext],

cmdclass={'build_ext' : MyBuildExt},

)

在打包这个模块并用pip安装之后,我在virtualenv的site packages目录中有一个模块foo。目录结构如下所示。在

^{pr2}$

egg-info/SOURCES.txt文件不包括我手动创建/移动的__init__.py文件。当我执行pip uninstall foo时,该命令将foo/__init__.py留在virtualenv的站点包中。我想让皮普删除整个包。如何将生成的__init__.py文件手动移到构建目录中,添加到已安装的输出文件列表中?在

我知道这是令人厌恶的和老套的,所以我欢迎恶心和粗糙的答案!在

尝试次数:添加了packages=['foo']——当我这样做时,pip不构建扩展。还尝试调整包名的文件路径/命名空间版本——没有区别。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值