如何利用PB设置python包的生产版本

2024-10-02 12:37:39 发布

您现在位置:Python中文网/ 问答频道 /正文

对于我的包,我有以下setup.py

import setuptools


setuptools.setup(
    setup_requires=['pbr>=2.0.0'],
    pbr=True
)

当我运行python setup.py sdist时,被标记到tar文件的版本是module-0.0.1.dev1207。如果我将setup.cfg修改为具有以下条目

^{pr2}$

标记到tar文件的版本是-1.0.1.dev1207。在

我对pbr进行了一些阅读,发现它使用git提交和标记来创建其版本控制。在

在他们的documentation上,它声明

Versions can be managed two ways - postversioning and preversioning. Postversioning is the default, and preversioning is enabled by setting version in the setup.cfg metadata section. In both cases version strings are inferred from git.

If the currently checked out revision is tagged, that tag is used as the version.

If the currently checked out revision is not tagged, then we take the last tagged version number and increment it to get a minimum target version.

We then walk git history back to the last release. Within each commit we look for a Sem-Ver: pseudo header, and if found parse it looking for keywords. Unknown symbols are not an error (so that folk can’t wedge pbr or break their tree), but we will emit an info level warning message. Known symbols: feature, api-break, deprecation, bugfix. A missing Sem-Ver line is equivalent to Sem-Ver: bugfix. The bugfix symbol causes a patch level increment to the version. The feature and deprecation symbols cause a minor version increment. The api-break symbol causes a major version increment.

If postversioning is in use, we use the resulting version number as the target version.

If preversioning is in use we check that the version set in the metadata section of setup.cfg is greater than the version we infer using the above method. If the inferred version is greater than the preversioning value we raise an error, otherwise we use the version from setup.cfg as the target.

We then generate dev version strings based on the commits since the last release and include the current git sha to disambiguate multiple dev versions with the same number of commits since the release.

但这让我不确定以下问题:

  1. 如何启用预版本?在
  2. 如果回购中从来没有标记或,因为pbr似乎说至少有一个标记是pbr正常工作所必需的?在
  3. 如何删除版本中的dev1207部分?在
  4. 如何设置setup.cfg从我的main.py读取版本,而不是必须在setup.cfg文件中指定它?在

Tags: andthetoin标记git版本if
1条回答
网友
1楼 · 发布于 2024-10-02 12:37:39

默认情况下,在PBR中基于字符串语义启用了preversion和postversioning。有关the latest SemVer versioning standard can be found here的详细信息。在

不过,我认为您需要的是如何从git更新版本。要做到这一点,只需添加一个带有SemVer字符串的标记,例如v1.0.1,甚至只是1.0.1。其他选项-请参阅上面的Sever文档。在

PBR将使用它能找到的最新标记-我相信在当前签出的分支中。如果找不到有效的标记(这似乎是您的repo的情况),它肯定首先会默认为0.0.1,但似乎也会恢复为使用setup.cfg中元数据中的版本字符串。在

一旦它有了这个版本,如果在最后一个标记的版本之后有任何提交,它会在版本字符串后面附加一个.devN后缀,每次未标记的提交都会递增。在

所以,我猜你有一个大的主分支,有1209个提交,但没有标记?无论如何,都是这样的。在

当你有一个发布版本时,就开始标记你的提交,或者坚持使用devN风格的版本。这真的取决于你。在

相关问题 更多 >

    热门问题