Python Setuptools和PBR-如何使用git标签作为版本创建软件包发行版? [英] Python Setuptools and PBR - how to create a package release using the git tag as the version?

查看:203
本文介绍了Python Setuptools和PBR-如何使用git标签作为版本创建软件包发行版?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上如何使用setuptoolspbr创建使用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?

关于所需的基本设置和配置,有很多信息:

There is plenty of information on the basic setup and configuration required:

  • SetupTools Documentation - setup() and setup.py configuration
  • Python Packaging User Guide - Installing Packages
  • PBR v3.1.1 documentation
  • StackOverflow: How to use version info generated using setuptools and pbr

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

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

即我正在寻找任何找到带有版本信息的git标记并将其拉入配置信息的命令,以便可以分发具有该新版本信息的源,并且可以使用描述的方法从脚本中发现版本信息在此答案中.

i.e. I'm looking for whatever command finds the git tag with the version info and pulls it into the configuration info, so the source with that new version info can be distributed, and the version info is discoverable from the scripts, using a method like described in this answer.

我正在开发一个项目,该项目只能通过git repo而不是通过 PyPi 分发给其他开发人员.该项目将使用pyinstaller作为可执行文件发布给用户,因此此程序包分发仅用于几个关键目的:

I'm working on a project that will be distributed to other developers only through a git repo, not through PyPi. The project will be released to users as an executable using pyinstaller, so this package distribution will only serve a few key purposes:

  1. 为其他开发人员安装/设置软件包,以便可以完全重新创建依赖关系/环境.
  2. 管理版本控制-当前的计划是使用pbr从Git repo标签生成版本,因此这些标签可以成为我们进行版本控制的真实来源
  3. pbr用于从Git自动生成其他世俗项目,例如作者,manifest.in文件,发行说明等.
  1. Install/Setup the package for other developers so that dependencies/environment can be recreated cleanly.
  2. Manage versioning - Current plan is to use pbr to generate versions from the Git repo tags, so those tags can be our source of truth for versioning
  3. Use pbr for other auto generation of mundane items from Git, such as authors, manifest.in file, release notes, etc.

由于setuptools文档专注于使用 PyPi pip设置完全可分发和可重用的软件包,而pbr文档仅真正告诉您如何修改setuptools配置以使用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.

我确定它存在于文档中的某个地方,但是在几次错误的开始之后,我要问这里.在我看来,到处都有暗示,每个人要么知道如何做到这一点,要么就神奇地发生在过程中.

I'm sure it exists somewhere in the documentation, but after several false starts I'm asking here. It is implied everywhere I look that everyone either knows how to do this or it just magically happens as a part of the process.

我只是想念明显的东西吗?

Am I just missing the obvious?

更新:

基于sinoroc的回答,看来我需要研究开发模式的安装.即开发该项目的任何人都将从git克隆,然后使用setuptools开发安装模式进行安装.

Based on sinoroc's answer, it appears I need to look into development mode installs. i.e. Anyone developing the project will clone from git, and then install via using setuptools development install mode.

这不是原始问题的直接一部分,而是暗含的,我相信同样情况下的人们也会对此感兴趣(我无法轻易找到的信息).

This wasn't directly a part of the original question, but implied, and I believe will be of interest to people in the same situation (info I couldn't easily find).

他的回答中提供了有关更新某些元数据的更多信息,并通过

More info is available in his answer on updating some of the metadata, and via this setuptools documentation link to working in "Development Mode"

推荐答案

简而言之:

  • 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.

      这篇关于Python Setuptools和PBR-如何使用git标签作为版本创建软件包发行版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆