本文整理汇总了Python中distutils.version.LooseVersion类的典型用法代码示例。如果您正苦于以下问题:Python LooseVersion类的具体用法?Python LooseVersion怎么用?Python LooseVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LooseVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compare
def compare(current, operator, reference):
# if len(sys.argv) < 4:
# script_name = sys.argv[0]
# print 'Usage:'
# print '{} current-version operator reference-version'.format(script_name)
# print '{} v0.10.29 \'>=\' v0.10.20'.format(script_name)
# print '{} v0.10.29 \'<\' v0.12.00'.format(script_name)
# sys.exit(1)
current = LooseVersion(current.replace('v', ''))
reference = LooseVersion(reference.replace('v', ''))
if operator == '>=':
if not current >= reference:
sys.exit(1)
elif operator == '>':
if not current > reference:
sys.exit(1)
elif operator == '<=':
if not current <= reference:
sys.exit(1)
elif operator == '<':
if not current < reference:
sys.exit(1)
else:
print 'Unknown operator {}'.format(operator)
sys.exit(1)
示例2: __init__
def __init__(self, version):
# Can't use super, LooseVersion's base class is not a new-style class.
LooseVersion.__init__(self, version)
# Take the first three integer components, stopping at the first
# non-integer and padding the rest with zeroes.
(self.major, self.minor, self.patch) = list(itertools.chain(
itertools.takewhile(lambda x:isinstance(x, int), self.version),
(0, 0, 0)))[:3]
示例3: isCompatibleVersionNumber
def isCompatibleVersionNumber(self, version):
v = LooseVersion(version).version
ref = LooseVersion(self._version).version
try:
for cpt in ref:
head = v.pop(0)
if cpt != head:
return False
return True
except:
return False
示例4: __init__
def __init__(self, string):
match = re.match(self.version_re, string)
if not match:
raise Exception("invalid version string format")
LooseVersion.__init__(self, string)
self.epoch = match.group(1) or 0
self.version = match.group(2)
# someone please inform foobnix's maintainer that the letter "o" should
# never, ever, ever, *ever* be used to represent zero.
if match.group(3) == "o":
self.release = 0
else:
self.release = int(match.group(3)) if match.group(3) else 1
示例5: __init__
def __init__(self, version_string):
self.is_dev = (version_string.lower() == "dev")
if self.is_dev:
version_string = kafkatest_version()
# Drop dev suffix if present
dev_suffix_index = version_string.find(".dev")
if dev_suffix_index >= 0:
version_string = version_string[:dev_suffix_index]
# Don't use the form super.(...).__init__(...) because
# LooseVersion is an "old style" python class
LooseVersion.__init__(self, version_string)
示例6: bump_version
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
示例7: __init__
def __init__(self, version_string):
self.is_trunk = (version_string.lower() == "trunk")
if self.is_trunk:
# Since "trunk" may actually be a branch that is not trunk,
# use kafkatest_version() for comparison purposes,
# and track whether we're in "trunk" with a flag
version_string = kafkatest_version()
# Drop dev suffix if present
dev_suffix_index = version_string.find(".dev")
if dev_suffix_index >= 0:
version_string = version_string[:dev_suffix_index]
# Don't use the form super.(...).__init__(...) because
# LooseVersion is an "old style" python class
LooseVersion.__init__(self, version_string)
示例8: __init__
def __init__(self, source=None):
PwebFormatter.__init__(self, source)
pandoc_ver = False
try:
pandoc = Popen(["pandoc", "--version"], stdin=PIPE, stdout=PIPE)
pandoc_ver = pandoc.communicate()[0].decode('utf-8').split("\n")[0]
pandoc_ver = LooseVersion(pandoc_ver.split(" ")[1])
except:
pandoc_ver = LooseVersion("0.0.1")
print("Error in trying to detect pandoc version")
if pandoc_ver < LooseVersion("1.16.0"):
self.new_pandoc = False
print("Your pandoc version is below 1.16, not setting figure size and id")
else:
self.new_pandoc = True
示例9: deprecated
def deprecated(self, msg, cur_ver, max_ver, depth=2, exception=None, *args, **kwargs):
"""
Log deprecation message, throw error if current version is passed given threshold.
Checks only major/minor version numbers (MAJ.MIN.x) by default, controlled by 'depth' argument.
"""
loose_cv = LooseVersion(cur_ver)
loose_mv = LooseVersion(max_ver)
loose_cv.version = loose_cv.version[:depth]
loose_mv.version = loose_mv.version[:depth]
if loose_cv >= loose_mv:
self.raiseException("DEPRECATED (since v%s) functionality used: %s" % (max_ver, msg), exception=exception)
else:
deprecation_msg = "Deprecated functionality, will no longer work in v%s: %s" % (max_ver, msg)
self.warning(deprecation_msg)
示例10: version_tuple
def version_tuple(self):
"""Return a tuple in the format of django.VERSION."""
version = self.version.replace("-", "").replace("_", "")
version = LooseVersion(version).version
if len(version) == 2:
version.append(0)
if not isinstance(version[2], int):
version.insert(2, 0)
if len(version) == 3:
version.append("final")
if version[3] not in ("alpha", "beta", "rc", "final"):
version[3] = {"a": "alpha", "b": "beta", "c": "rc"}[version[3]]
if len(version) == 4:
version.append(0)
return tuple(version)
示例11: version_tuple
def version_tuple(self):
"""Return a tuple in the format of django.VERSION."""
version = self.version.replace('-', '').replace('_', '')
version = LooseVersion(version).version
if len(version) == 2:
version.append(0)
if not isinstance(version[2], int):
version.insert(2, 0)
if len(version) == 3:
version.append('final')
if version[3] not in ('alpha', 'beta', 'rc', 'final'):
version[3] = {'a': 'alpha', 'b': 'beta', 'c': 'rc'}[version[3]]
if len(version) == 4:
version.append(0)
return tuple(version)
示例12: _cmp
def _cmp (self, other):
if isinstance(other, str):
other = LooseVersion(other)
stypes = map(lambda c: str if isinstance(c, str) else int, self.version)
otypes = map(lambda c: str if isinstance(c, str) else int, other.version)
for i, (stype, otype) in enumerate(zip(stypes, otypes)):
if stype == str and otype == int:
other.version[i] = str(other.version[i])
if stype == int and otype == str:
self.version[i] = str(self.version[i])
if self.version == other.version:
return 0
if self.version < other.version:
return -1
if self.version > other.version:
return 1
示例13: __init__
def __init__(self, vstring=None, v_prefix=None):
self._v_prefix = v_prefix
if isinstance(vstring, (list, tuple)):
type_ = type(vstring)
vstring = '.'.join(str(i) for i in vstring)
else:
type_ = list
vstring = vstring.strip()
if vstring.startswith('v'):
vstring = vstring[1:]
if vstring.startswith('!'):
raise ValueError('Invalid use of epoch')
if v_prefix is not False:
self._v_prefix = True
# Can not use super(..) on Python 2.7
LooseVersion.__init__(self, vstring)
if self._v_prefix:
self.vstring = 'v' + self.vstring
if len(self.version) > 1 and self.version[1] == '!':
self._epoch = self.version[0]
if not isinstance(self._epoch, int) or len(self.version) < 3:
raise ValueError('Invalid use of epoch')
# Normalise to lower case
self.version = [
x if isinstance(x, int) else x.lower() for x in self.version
if x not in ('-', '_')]
if self.version[-1] != '*' and not isinstance(self.version[-1], int):
self.version += (0, )
if type_ is tuple:
self.version = tuple(self.version)
self._final = None
self._previous = None
示例14: LooseVersion
examples = glob.glob(os.path.join(example_path, '*.ipynb'))
for example in examples:
_, filename = os.path.split(example)
mod = filename.split('_')[0]
target = os.path.join(root, mod, filename)
shutil.copyfile(example, target)
# -- Project information -----------------------------------------------------
project = 'arch'
copyright = '2018, Kevin Sheppard'
author = 'Kevin Sheppard'
# The short X.Y version
version = arch.__version__
ver = LooseVersion(arch.__version__).version
if '+' in ver:
loc = ver.index('+')
version = '.'.join(map(str, ver[:loc]))
version += ' (+{0})'.format(ver[loc+1])
# The full version, including alpha/beta/rc tags.
release = arch.__version__
# -- General configuration ---------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
示例15: __str__
def __str__(self):
if self.is_trunk:
return "trunk"
else:
return LooseVersion.__str__(self)