如果我有建立鸡蛋,基本上由运行脚本

python setup.py bdist_egg --exclude-source-files

对于一些使用setuptools来定义鸡蛋如何构建setup.py文件,有一个简单的方法来确定是否有在建设蛋任何错误?

一个情况我最近有,是,有一个模块中的语法错误。 setuptools的吐出一个消息到标准误差,但继续创建蛋,省略破碎模块。因为这是一个批处理创建多个鸡蛋的一部分,该误差被错过了,并且结果是无用的。

有没有办法编程构建一个鸡蛋时发现错误,不只是捕捉标准错误,并解析其他?

有帮助吗?

解决方案

distutils使用py_compile.compile()函数来编译源文件。此功能需要一个doraise的说法,当设置为True提高对编译错误异常(默认是打印错误到stderr)。 distutils不调用py_compile.compile()doraise=True,所以编译未被中止上编译错误。

要停止的错误,并能够检查setup.py返回代码(这将是错误的非零),你可以修补py_compile.compile()功能。例如,在你的setup.py

from setuptools import setup
import py_compile

# Replace py_compile.compile with a function that calls it with doraise=True
orig_py_compile = py_compile.compile

def doraise_py_compile(file, cfile=None, dfile=None, doraise=False):
    orig_py_compile(file, cfile=cfile, dfile=dfile, doraise=True)

py_compile.compile = doraise_py_compile

# Usual setup...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top