本文整理汇总了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