本文整理匯總了Python中distutils.version.LooseVersion.get方法的典型用法代碼示例。如果您正苦於以下問題:Python LooseVersion.get方法的具體用法?Python LooseVersion.get怎麽用?Python LooseVersion.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類distutils.version.LooseVersion
的用法示例。
在下文中一共展示了LooseVersion.get方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: bump_version
# 需要導入模塊: from distutils.version import LooseVersion [as 別名]
# 或者: from distutils.version.LooseVersion import get [as 別名]
def bump_version(ctx, major=False, minor=False, micro=False):
"""
Bump the version number in the VERSION file.
"""
from distutils.version import LooseVersion
if major == minor == micro == False:
micro = True
with open('VERSION') as F:
vdata = F.read()
version = LooseVersion(vdata).version
version = dict(enumerate(version))
# Fix major
if major:
version[0] += 1
for k, v in version.items():
if isinstance(v, int) and not k == 0:
version[k] = 0
# Fix minor
minor_idx = 1
if minor:
while isinstance(version.get(minor_idx), str):
minor_idx += 1
version[minor_idx] = version.get(minor_idx, 0) + 1
for k, v in version.items():
if isinstance(v, int) and k > minor_idx:
version[k] = 0
# Fix micro
micro_idx = minor_idx + 1
if micro:
while isinstance(version.get(micro_idx), str):
micro_idx += 1
version[micro_idx] = version.get(micro_idx, 0) + 1
for k in list(version):
if k > micro_idx:
del version[k]
# Reconstruct version string
vstring = ''
for (i, v) in sorted(version.items()):
if i and isinstance(v, int) and isinstance(version[i - 1], int):
vstring += '.%s' % v
else:
vstring += str(v)
vstring += '\n'
# Save version
with open('VERSION', 'w') as F:
F.write(vstring)
print('Version bumped from %s to %s' % (vdata.strip(), vstring.strip()))
return vstring