且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python Setuptools和PBR-如何使用git标签作为版本创建软件包发行版?

更新时间:2023-11-17 22:03:46

简而言之:

  • python3 setup.py sdist
  • python3 setup.py bdist_wheel
  • python3 setup.py sdist
  • python3 setup.py bdist_wheel

我实际上如何使用setuptools和pbr创建使用git repo标签进行版本控制的python软件包的发行版/发行版?

How do I actually create a release/distro of a python package that uses a git repo tag for the versioning, using setuptools and pbr?

使用 setuptools 创建Python软件包的(源代码和源代码)发行版的常用命令是python3 setup.py sdistpython3 setup.py bdist_wheel.然后,默认情况下可以在dist目录中找到这些分布.

The usual commands to create (source and wheel) distributions of your Python package with setuptools are: python3 setup.py sdist and python3 setup.py bdist_wheel. The distributions can then be found in the dist directory by default.

由于setuptools文档致力于通过PyPi和pip设置完全可分发和可重用的软件包,而pbr文档仅真正告诉您如何修改setuptools配置以使用pbr,因此我找不到有关如何仅运行pbr的信息.分发/发布过程.

Since setuptools docs focus on setting up a fully distributable and reusable package with PyPi and pip, and pbr docs only really tell you how to modify setuptools configuration to use pbr, I can't find the info on how to just run the distribution/release process.

setuptools 确实没有对此进行说明.它仅将差异记录在distutils中,的确令人困惑.请参阅下面的实际文档...

It is true that setuptools does not document this. It only documents the differences to distutils, and it is confusing indeed. See below for actual documentation...

但是关于如何实际创建发行版的简单信息在哪里?

But where is the simple info on how to actually create the distro?

  • https://packaging.python.org/tutorials/包装项目/#generating-distribution-archives
  • https://docs.python.org/3/distutils/sourcedist.html
  • https://docs.python.org/3/distutils/builtdist.html
    • https://packaging.python.org/tutorials/packaging-projects/#generating-distribution-archives
    • https://docs.python.org/3/distutils/sourcedist.html
    • https://docs.python.org/3/distutils/builtdist.html
    • 更新

      由于您不打算在诸如 PyPI 的索引上发布项目的发行版,而是打算使用 pyinstaller 进行发布,因此您确实有可能忽略 setuptools 命令,例如sdistbdist_wheel.

      Since you don't plan on publishing distributions of your project on an index such as PyPI, and you plan on using pyinstaller instead, then you can indeed most likely disregard the setuptools commands such as sdist and bdist_wheel.

      在开发阶段您仍然可能想知道以下命令:

      Still you might want to know these commands for the development phase:

      • 使用python3 setup.py --versionpython3 setup.py --fullname之类的命令来确定setuptools(在您的情况下为pbr)是否捕获了正确的信息.
      • 使用python3 setup.py develop(或pip install --editable .)在您的站点包中放置一个指向您正在进行的工作的伪链接(egg-link).这样,您的更改始终可以安装并导入.重要提示:请勿使用python3 setup.py install,这会将当前版本复制到 site-packages ,并且较新的更改将无法导入.
      • Use commands such as python3 setup.py --version, python3 setup.py --fullname to figure out if setuptools (and in your case pbr) is catching the right info.
      • Use python3 setup.py develop (or pip install --editable .) to place a pseudo link (egg-link) in your site-packages that points at your work in progress. This way your changes are always installed and importable. Important: don't use python3 setup.py install, this would copy the current version to site-packages and newer changes would not be importable.

      现在,我不知道一旦转到 pyinstaller ,这一切将如何工作.特别是因为您提到要从脚本中发现元信息(例如版本号). setuptools pkg_resources的技术可能在 pyinstaller 上下文中起作用或不起作用.

      Now I don't know how all this will work once you move on to pyinstaller. Especially since you mentioned that you want the meta info (such as the version number) to be discoverable from within your scripts. The technique with setuptools pkg_resources may or may not work in the pyinstaller context.