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

Dav*_*ave 11 python distutils python-2.7

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

Mar*_*ers 14

第一站,distutils包文档:

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
Run Code Online (Sandbox Code Playgroud)

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

$ python setup.py check -rs
running check
error: The docutils package is needed.
Run Code Online (Sandbox Code Playgroud)

如果确实安装了它并且没有问题,则脚本只运行并退出而不显示任何消息:

$ python setup.py check -r
running check
Run Code Online (Sandbox Code Playgroud)

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

$ 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
Run Code Online (Sandbox Code Playgroud)

如果您-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.
Run Code Online (Sandbox Code Playgroud)

默认情况下,-m已启用,-r-s已禁用.

另请参阅命令源代码.