`python setup.py check`实际上做了什么?

时间:2015-05-19 14:17:51

标签: python python-2.7 distutils

python setup.py check究竟做了什么?

1 个答案:

答案 0 :(得分:11)

第一站,distutils package documentation

  

check命令对包的元数据执行一些测试。例如,它验证所有必需的元数据是作为传递给setup()函数的参数提供的。

因此,它会测试您是否正确填写了元数据;在创建Python包时将其视为质量控制步骤。

接下来,我们可以检查命令行是否提供任何帮助:

$ python setup.py --help-commands | grep check
  check             perform some checks on the package
$ python setup.py check --help
# ...
Options for 'check' command:
  --metadata (-m)          Verify meta-data
  --restructuredtext (-r)  Checks if long string meta-data syntax are
                           reStructuredText-compliant
  --strict (-s)            Will exit with an error if a check fails

因此我们可以检查元数据并将长描述验证为reStructuredText。后者要求您安装docutils

$ python setup.py check -rs
running check
error: The docutils package is needed.

如果你安装了它并且没有问题,那么脚本只运行并退出而没有消息:

$ python setup.py check -r
running check

但如果缺少必需的元数据,则会收到警告消息:

$ python setup.py check -r
running check
warning: check: missing required meta-data: url

warning: check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied

如果您有-s标志,则会出现错误:

$ python setup.py check -rs
running check
warning: check: missing required meta-data: url

warning: check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied

error: Please correct your package.

默认情况下,-m已启用,-r-s已停用。

另见command source code