setup.py(setuptools)和源代码中的自动版本号? [英] Automatic version number both in setup.py (setuptools) AND source code?

查看:198
本文介绍了setup.py(setuptools)和源代码中的自动版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

状态:



我有一个python库,由git控制,并捆绑distutils / setuptools。我想自动生成基于git标签的版本号,既可以用于 setup.py sdist 等类似的命令,也可以用于库本身。



对于第一个任务,我可以使用 git describe 或类似的解决方案(请参阅)。

例如,当我处于'0.1'标签并且要求'setup.py sdist'时,我得到'mylib-0.1。 tar.gz的;或'mylib-0.1-3-abcd.tar.gz',如果我在标记后更改了代码。这很好。



问题在于:



希望这个版本号可用于库本身,所以它可以将它作为'mylib / 0.1-3-adcd'作为User-Agent HTTP头发送。



如果我添加 setup.py version 命令,如,然后这个version.py在标签,因为它使用标签作为值。但在这种情况下,我需要在版本标记完成后再做一次提交,以使代码一致。反过来,这需要一个新的标签进一步捆绑。



问题是:



如何打破这个依赖关系(generate-commit-tag-generate-commit-tag -...)? p

你也可以逆转依赖:将版本放在 mylib / __ init __。py 中,解析setup.py中的文件以获取版本参数,并使用git在命令行标记$(setup.py --version)来创建您的标记。

  git tag -av $(python setup.py --version)-m'版本描述'

有没有更复杂的东西需要要做到这一点我还没有明白?


SITUATION:

I have a python library, which is controlled by git, and bundled with distutils/setuptools. And I want to automatically generate version number based on git tags, both for setup.py sdist and alike commands, and for the library itself.

For the first task I can use git describe or alike solutions (see How can I get the version defined in setup.py (setuptools) in my package?).

And when, for example, I am in a tag '0.1' and call for 'setup.py sdist', I get 'mylib-0.1.tar.gz'; or 'mylib-0.1-3-abcd.tar.gz' if I altered the code after tagging. This is fine.

THE PROBLEM IS:

The problem comes when I want to have this version number available for the library itself, so it could send it in User-Agent HTTP header as 'mylib/0.1-3-adcd'.

If I add setup.py version command as in How can I get the version defined in setup.py (setuptools) in my package?, then this version.py is generated AFTER the tag is made, since it uses the tag as a value. But in this case I need to make one more commit after the version tag is made to make the code consistent. Which, in turns, requires a new tag for further bundling.

THE QUESTION IS:

How to break this circle of dependencies (generate-commit-tag-generate-commit-tag-...)?

解决方案

You could also reverse the dependency: put the version in mylib/__init__.py, parse that file in setup.py to get the version parameter, and use git tag $(setup.py --version) on the command line to create your tag.

git tag -a v$(python setup.py --version) -m 'description of version'

Is there anything more complicated you want to do that I haven’t understood?

这篇关于setup.py(setuptools)和源代码中的自动版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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