动态设置 Python 车轮版本标签 [英] Set Python wheel version tag dynamically
问题描述
我正在尝试将车轮文件的构建整合到 Bamboo 计划中.最终,我想以某种方式将 .whl 文件的部分版本标签与 Bamboo 内部版本号相关联,即版本 0 的预发布版本将是 0.dev1、0.dev2、0.dev3,用于连续构建.
I'm trying to integrate building of a wheel file into a Bamboo plan. Ultimately, I'd like to tie part of the version tag of the .whl file to the Bamboo build number in someway, i.e. the pre-release for version 0 would be 0.dev1, 0.dev2, 0.dev3 for successive builds.
用于允许 --tag_build
选项的旧 Egg 格式,该选项允许您指定附加到 version
参数中的标签 setup.py
文件中的 >setup 函数.bdist_wheel
命令显然没有等效的选项.
The old egg format used to allow the --tag_build
option, which would allow you to specify a tag that is appended to the version
parameter defined in the setup
function in the setup.py
file. The bdist_wheel
command apparently doesn't have an equivalent option.
这使我希望使用 Bamboo 版本号变量从脚本运行 setup.py
的希望破灭.除了将构建脚本转换为 Powershell 或在每次构建时动态生成 setup.py
之外,我正在寻找任何其他建议.
This dashed my hopes of running setup.py
from a script, using the Bamboo build number variable. I'm looking for any other suggestions other than either converting the build script to Powershell, or generating setup.py
on the fly each build.
推荐答案
wheel 文件名中的 version 标签只是包版本号,由 setup.py
和 setup 定义.py
是一个 Python 脚本,它具有 Python 的所有功能.因此,setup.py
可以根据bamboo_buildNumber
环境简单地设置setup()
函数的version
参数变量:
The version tag in the wheel filename is just the package version number, defined by setup.py
, and setup.py
is a Python script with all the power of Python available to it. Thus, setup.py
can simply set the version
parameter of the setup()
function based on the bamboo_buildNumber
environment variable:
import os
version = whatever_the_version_would_be_otherwise
try:
version += '.dev' + os.environ['bamboo_buildNumber']
except KeyError: # bamboo_buildNumber isn't defined, so we're not running in Bamboo
pass
setup(
version = version,
...
)
这篇关于动态设置 Python 车轮版本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!