我正在使用project.toml文件来打包我的模块,我想使用
setuptools_scm
模块从git标签中提取版本。
当我运行
python setup.p y --version
命令时,它会给出此输出 0.0.1.post1.dev0
。如何仅获取 0.0.1
值并忽略 .post.dev0
值?
这是project.toml文件设置:
[build-system]
requires = ["setuptools>=46.1.0", "setuptools_scm[toml]>=5"]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
version_scheme = "no-guess-dev"
local_scheme="no-local-version"
write_to = "src/showme/version.py"
git_describe_command = "git describe --dirty --tags --long --match v* --first-parent"
[tool.setuptools.dynamic]
version = {attr = "showme.__version__"}
输出:
python setup.py --version
setuptools/config/pyprojecttoml.py:108: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
warnings.warn(msg, _BetaConfiguration)
0.0.1.post1.dev0
谢谢
setuptools_scm
开箱即用生成开发和发布后版本。
要生成像
0.0.1
这样的发布版本,您可以将可调用对象传递给use_scm_version
:
# content of setup.py
def my_version():
from setuptools_scm.version import SEMVER_MINOR, guess_next_simple_semver, release_branch_semver_version
def my_release_branch_semver_version(version):
v = release_branch_semver_version(version)
if v == version.format_next_version(guess_next_simple_semver, retain=SEMVER_MINOR):
return version.format_next_version(guess_next_simple_semver, fmt="{guessed}", retain=SEMVER_MINOR)
return v
return {
'version_scheme': my_release_branch_semver_version,
'local_scheme': 'no-local-version',
}
setup(use_scm_version=myversion)
参考:https://github.com/pypa/setuptools_scm#importing-in-setuppy