用于构建发行版 setup.py build 与 python -m build 的 Python 命令

oet*_*ter 22 python setuptools setup.py python-packaging

我正在学习 Python 打包,根据本指南,构建 python 分发包的命令似乎是python3 -m build.

\n

但我还发现 setuptools 中有一个用于 setup.py 文件的命令行界面:

\n
$ python setup.py --help-commands\nStandard commands:\n  build             build everything needed to install\n  sdist             create a source distribution (tarball, zip file, etc.)\n  bdist             create a built (binary) distribution\n  bdist_dumb        create a "dumb" built distribution\n  bdist_rpm         create an RPM distribution\n  ...\n
Run Code Online (Sandbox Code Playgroud)\n

似乎python setup.py build,sdist或者 也bdist可以构建发行版,但我没有找到这些命令的详细说明,setuptools 命令参考缺少对build sdist bdist.

\n

所以我有点困惑,python setup.py build和之间有什么区别python -m build,或者python setup.py sdist和之间有什么区别python -m build --sdist?该python setup.py命令是否已被弃用,因此缺乏完整的文档?我什么时候应该使用python -m buildor python setup.py build

\n

任何帮助,将不胜感激。

\n
\n

更新:\n模块的文档build说 \xe2\x80\x9cbuild 大致相当于setup.py sdist bdist_wheel但具有 PE​​P 517 支持,允许与不\xe2\x80\x99t 使用 setuptools\xe2\x80\x9d 的项目一起使用。

\n

那么我应该总是更喜欢构建模块而不是手动运行 python setup.py 吗?仍然有用例吗setup.py build

\n

Nic*_*ert 17

引用Paul Ganssle 的《为什么你不应该直接调用 setup.py》 。

  • setuptools 项目多年前就已停止维护 setup.py 的所有直接调用,并且 distutils 已被弃用。
  • 毫无疑问,今天基于 setup.py 的系统有多种损坏方式,即使它的故障不是很大或很明显。
  • 直接调用 setup.py 无法引导其自己的依赖项,因此需要一些 CLI 来进行依赖项管理。
  • setuptools 项目不再希望提供任何公共 CLI,并将主动删除现有接口(尽管这需要很长的时间)。
  • PEP 517、518 和其他基于标准的打包是 Python 生态系统的未来,并且在无缝升级方面已经取得了很多进展。

setup.py下面是该方式和较新推荐方法的汇总表:

安装程序.py 新命令
setup.py sdist python -m build (使用build
setup.py bdist_wheel python -m build (使用build
setup.py测试 pytest(通常通过toxnox
setup.py 安装 点安装
setup.py开发 pip安装-e
setup.py上传 绳线上传(用绳线
setup.py 检查 麻线检查(这不会执行所有相同的检查,但这是一个开始)
自定义命令 有毒氮氧化物环境。