6

在我执行时version.py有一种方法从文件中引发此错误get_git_version()./manage.py runserverversion.py

raise ValueError("找不到版本号!")

def get_git_version(abbrev=4):
    # Read in the version that's currently in RELEASE-VERSION.

    release_version = read_release_version()

    # First try to get the current version using "git describe".

    version = call_git_describe(abbrev)

    # If that doesn't work, fall back on the value that's in
    # RELEASE-VERSION.

    if version is None:
        version = release_version

    # If we still don't have anything, that's an error.

    if version is None:
        raise ValueError("Cannot find the version number!")

    # If the current version is different from what's in the
    # RELEASE-VERSION file, update the file to be current.

    if version != release_version:
        write_release_version(version)

    # Finally, return the current version.

    return version


def read_release_version():
    try:
        f = open("RELEASE-VERSION", "r")

        try:
            version = f.readlines()[0]
            return version.strip()

        finally:
            f.close()
    except:
        return None
4

1 回答 1

4

这个脚本需要一个来自 git 注释标签 ( call_git_describe()) 的版本号,或者通过在一个名为RELEASE-VERSION. 它失败是因为没有找到这两个东西,所以修复其中一个。

在你的项目中运行它来为当前提交创建带注释的标签:

git tag 1.0 -m "this is version 1.0"

我更喜欢标记版本管理,但文本文件中的版本也很好,YMMV。

于 2012-05-29T10:27:15.040 回答