在version.py
中,当我执行get_git_version()
./manage.py runserver
从version.py
文件中引发此错误时,有一个方法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
引发ValueError(“找不到版本号!”)
{{1}}
答案 0 :(得分:3)
此脚本需要来自git带注释标记(call_git_describe()
)的版本号,或者查找名为RELEASE-VERSION
的文件中的版本号。它失败了,因为找不到这两件事,所以要解决其中一件事。
在项目中运行此命令以为当前提交创建带注释的标记:
git tag 1.0 -m "this is version 1.0"
我倾向于标记版本管理,但文本文件中的版本也很好,YMMV。