setup.py:先运行build_ext [英] setup.py: run build_ext before anything else

查看:109
本文介绍了setup.py:先运行build_ext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用setup.py,该文件在build_ext步骤期间创建了一堆SWIG接口文件。这需要首先运行,因为后续的构建步骤需要完整的python文件列表才能正常工作(例如,将python文件复制到package目录,创建egg,创建源列表等)。

I'm working with a setup.py that creates a whole bunch of SWIG interface files during the build_ext step. This needs to run first, because subsequent build steps need a full list of the python files to work properly (like copying the python files to the package directory, creating the egg, creating the sources list, etc.).

这是当您执行 setup.py install 时当前发生的情况:

This is what currently happens when you do setup.py install:

running install
running bdist_egg
running egg_info
running install_lib
running build_py
running build_ext

build_py 步骤尝试复制所有的python文件它找到构建目录。这些文件在 build_ext 运行之前不存在(swig创建了一堆.py文件)。

The build_py step tries to copy all the python files that it finds to the build directory. Those files don't exist until build_ext runs (swig creates a bunch of .py files).

此答案建议更改 sub_commands ,但这似乎无济于事。

This answer recommends changing sub_commands but that didn't appear to do anything.

我只是尝试将 install 命令类子类化,以运行 build_ext 之前的其他事情:

I tried just subclassing the install command class like this to run build_ext before anything else:

class Build_ext_first(setuptools.command.install.install):
    def run(self):
        self.run_command("build_ext")
        super(Build_ext_first, self).run()

..然后使用 cmdclass 进行设置:

..and then working it in to setup with cmdclass:

setup(
    ...
    cmdclass = {'install' : Build_ext_first}
)

但这没用,因为 super 不适用于老式类和 install 显然不是从 object 继承的。

But that didn't work because super doesn't work with old-style classes and install apparently doesn't inherit from object.

我应该如何首先

How do I do build_ext first?

推荐答案

看来,做super()的旧方法是向前兼容的,所以我只是这样做:

It appears the old way of doing super() is forwards-compatible so I just did that:

class Build_ext_first(setuptools.command.install.install):
    def run(self):
        self.run_command("build_ext")
        return setuptools.command.install.install.run(self)


setup(
    ...,
    cmdclass = {'install' : Build_ext_first}
)

这篇关于setup.py:先运行build_ext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆