automaticly update `__version__` with mercurial? [duplicate]

寵の児 提交于 2019-12-24 03:19:14

问题


Possible Duplicate:
How to display current working copy version of an hg repository on a PHP page

Similar to How can I rewrite python __version__ with git?, what it is the best method to store an automatically updated version number inside a python file?

How good is my method of embedding version numbers into my application using Mercurial hooks? and the Mercurial keyword plan make it clear the svn-style method of automatically updating $Revision$ or $Id$ is not desirable and that the build system should do that work instead. This is python though, there is no build system and this is for a small program wholly contained in one file, so there is no packaging.


回答1:


You can always add a build system, no matter which language you write your program in. You might say "but language X doesn't need a build system", but this question shows that it does: it needs it for those repetitive tasks that needs to be done before any release. This is tasks like building the documentation, running tests, and uploading the result somewhere.

A simple Makefile or a shell script is enough:

all: version

version:
    hg id > __version__

test: version
    @echo -n "running tests... "
    @sleep 1
    @echo " done."

doc: version
    @echo -n "building documentation... "
    @sleep 1
    @echo "done."

upload: test doc
    @echo -n "creating tarball... "
    @sleep 1
    @echo "done."
    @echo -n "publishing on website... "
    @sleep 1
    @echo "done."

.PHONY: version test upload doc


来源:https://stackoverflow.com/questions/7426341/automaticly-update-version-with-mercurial

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!