本文整理汇总了Python中semver.VersionInfo方法的典型用法代码示例。如果您正苦于以下问题:Python semver.VersionInfo方法的具体用法?Python semver.VersionInfo怎么用?Python semver.VersionInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类semver
的用法示例。
在下文中一共展示了semver.VersionInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_get_singularity_version_info
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def test_check_get_singularity_version_info():
"""Check that the version_info is correct"""
from spython.utils import get_singularity_version_info
with ScopedEnvVar("SPYTHON_SINGULARITY_VERSION", "2.3.1"):
version = get_singularity_version_info()
assert version == VersionInfo(2, 3, 1)
assert version > VersionInfo(2, 3, 0)
assert version < VersionInfo(3, 0, 0)
with ScopedEnvVar("SPYTHON_SINGULARITY_VERSION", "singularity version 3.2.1-1"):
version = get_singularity_version_info()
assert version == VersionInfo(3, 2, 1, "1")
assert version > VersionInfo(2, 0, 0)
assert version < VersionInfo(3, 3, 0)
assert version > VersionInfo(3, 2, 0)
assert version < VersionInfo(3, 2, 1)
with ScopedEnvVar("SPYTHON_SINGULARITY_VERSION", "2.6.1-pull/124.1d068a7"):
version = get_singularity_version_info()
assert version == VersionInfo(2, 6, 1, "pull", "124.1d068a7")
assert version > VersionInfo(2, 6, 0)
assert version < VersionInfo(2, 7, 0)
示例2: find_latest_version_with_matching_major
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def find_latest_version_with_matching_major(reference_version: semver.VersionInfo, versions):
latest_candidate_semver = None
latest_candidate_str = None
if isinstance(reference_version, str):
reference_version = parse_to_semver(reference_version)
for candidate in versions:
if isinstance(candidate, str):
candidate_semver = parse_to_semver(candidate)
else:
candidate_semver = candidate
# skip if major version does not match
if candidate_semver.major != reference_version.major:
continue
if candidate_semver > reference_version:
if not latest_candidate_semver or latest_candidate_semver < candidate_semver:
latest_candidate_semver = candidate_semver
latest_candidate_str = candidate
return latest_candidate_str
示例3: parse_version
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def parse_version(raw_version):
try:
# Only works for MAJOR.MINOR.PATCH(-PRE_RELEASE)
return semver.parse_version_info(raw_version)
except ValueError:
pass
try:
# Version may be missing minor eg: 10.0
version = raw_version.split(' ')[0].split('.')
version = [int(part) for part in version]
while len(version) < 3:
version.append(0)
return semver.VersionInfo(*version)
except ValueError:
# Postgres might be in development, with format \d+[beta|rc]\d+
match = re.match(r'(\d+)([a-zA-Z]+)(\d+)', raw_version)
if match:
version = list(match.groups())
return semver.parse_version_info('{}.0.0-{}.{}'.format(*version))
raise Exception("Cannot determine which version is {}".format(raw_version))
示例4: _process_version
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def _process_version(self, version_like: PackageVersionLike) -> Tuple[Any, Any]:
if isinstance(version_like, str):
return version_like, semver.VersionInfo.parse(version_like)
elif isinstance(version_like, semver.VersionInfo):
return str(version_like), version_like
else:
raise ValueError("Version type not valid.")
示例5: parse_to_semver
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def parse_to_semver(
version,
):
'''
parses the given version into a semver.VersionInfo object.
Different from strict semver, the given version is preprocessed, if required, to
convert the version into a valid semver version, if possible.
The following preprocessings are done:
- strip away `v` prefix
- append patch-level `.0` for two-digit versions
@param version: either a str, or a product.model object with a `version` attr
'''
if isinstance(version, str):
version_str = version
else:
if hasattr(version, 'version'):
if callable(version.version):
version_str = version.version()
else:
version_str = str(version.version)
else:
ci.util.warning(f'unexpected type for version: {type(version)}')
version_str = str(version) # fallback
semver_version_info, _ = _parse_to_semver_and_metadata(version_str)
return semver_version_info
示例6: find_latest_version_with_matching_minor
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def find_latest_version_with_matching_minor(reference_version: semver.VersionInfo, versions):
latest_candidate_semver = None
latest_candidate_str = None
if isinstance(reference_version, str):
reference_version = parse_to_semver(reference_version)
for candidate in versions:
if isinstance(candidate, str):
candidate_semver = parse_to_semver(candidate)
else:
candidate_semver = candidate
# skip if major version does not match
if candidate_semver.major != reference_version.major:
continue
# skip if minor version does not match
if candidate_semver.minor != reference_version.minor:
continue
if candidate_semver >= reference_version:
if not latest_candidate_semver or latest_candidate_semver < candidate_semver:
latest_candidate_semver = candidate_semver
latest_candidate_str = candidate
return latest_candidate_str
示例7: partition_by_major_and_minor
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def partition_by_major_and_minor(
versions: Iterable[semver.VersionInfo],
) -> Iterable[Set[semver.VersionInfo]]:
'''partition an iterable of semver VersionInfos by their joined major and minor version
'''
partitions = collections.defaultdict(set)
for version_info in versions:
partitions[(version_info.major,version_info.minor)].add(version_info)
yield from [
sorted(partition, reverse=True)
for partition in partitions.values()
]
示例8: test_parse_version
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def test_parse_version():
"""
Test _get_version() to make sure the check is properly parsing Postgres versions
"""
version = parse_version('9.5.3')
assert version == VersionInfo(9, 5, 3)
# Test #.# style versions
v10_2 = parse_version('10.2')
assert v10_2 == VersionInfo(10, 2, 0)
v11 = parse_version('11')
assert v11 == VersionInfo(11, 0, 0)
# Test #beta# style versions
beta11 = parse_version('11beta3')
assert beta11 == VersionInfo(11, 0, 0, prerelease='beta.3')
assert v10_2 < beta11
assert v11 > beta11
# Test #rc# style versions
version = parse_version('11rc1')
assert version == VersionInfo(11, 0, 0, prerelease='rc.1')
# Test #nightly# style versions
version = parse_version('11nightly3')
assert version == VersionInfo(11, 0, 0, 'nightly.3')
示例9: check
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def check():
c = PostgreSql('postgres', {}, [{'dbname': 'dbname', 'host': 'localhost', 'port': '5432', 'username': USER}])
c._version = VersionInfo(9, 2, 0)
return c
示例10: test_wrong_version
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def test_wrong_version(aggregator, integration_check, pg_instance):
check = integration_check(pg_instance)
# Enforce to cache wrong version
check._version = VersionInfo(*[9, 6, 0])
check.check(pg_instance)
assert_state_clean(check)
check.check(pg_instance)
assert_state_set(check)
示例11: test_get_instance_metrics_lt_92
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def test_get_instance_metrics_lt_92(integration_check, pg_instance):
"""
check output when 9.2+
"""
pg_instance['collect_database_size_metrics'] = False
check = integration_check(pg_instance)
res = check.metrics_cache.get_instance_metrics(VersionInfo(9, 1, 0))
assert res['metrics'] == util.COMMON_METRICS
示例12: test_get_instance_metrics_state
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def test_get_instance_metrics_state(integration_check, pg_instance):
"""
Ensure data is consistent when the function is called more than once
"""
pg_instance['collect_database_size_metrics'] = False
check = integration_check(pg_instance)
res = check.metrics_cache.get_instance_metrics(VersionInfo(9, 2, 0))
assert res['metrics'] == dict(util.COMMON_METRICS, **util.NEWER_92_METRICS)
res = check.metrics_cache.get_instance_metrics('foo') # metrics were cached so this shouldn't be called
assert res['metrics'] == dict(util.COMMON_METRICS, **util.NEWER_92_METRICS)
示例13: test_get_instance_metrics_database_size_metrics
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def test_get_instance_metrics_database_size_metrics(integration_check, pg_instance):
"""
Test the function behaves correctly when `database_size_metrics` is passed
"""
pg_instance['collect_default_database'] = True
pg_instance['collect_database_size_metrics'] = False
check = integration_check(pg_instance)
expected = util.COMMON_METRICS
expected.update(util.NEWER_92_METRICS)
expected.update(util.DATABASE_SIZE_METRICS)
res = check.metrics_cache.get_instance_metrics(VersionInfo(9, 2, 0))
assert res['metrics'] == expected
示例14: test_get_instance_with_default
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def test_get_instance_with_default(check):
"""
Test the contents of the query string with different `collect_default_db` values
"""
version = VersionInfo(9, 2, 0)
res = check.metrics_cache.get_instance_metrics(version)
assert " AND psd.datname not ilike 'postgres'" in res['query']
check.config.collect_default_db = True
res = check.metrics_cache.get_instance_metrics(version)
assert " AND psd.datname not ilike 'postgres'" not in res['query']
示例15: _sort_versions
# 需要导入模块: import semver [as 别名]
# 或者: from semver import VersionInfo [as 别名]
def _sort_versions(
versions
):
'''
sorts the given versions (which may be a sequence containing any combination of
str, semver.VersionInfo, or model element bearing a `version` attr) on a best-effort
base.
Firstly, it is checked whether all versions are semver-parsable, using this module's
`parse_to_semver` (which allows some deviations from strict semver-v2). If all versions
are parsable, str representations of the originally given versions are returned, ordered
according to semver artithmetics.
Otherwise, sorting falls back to alphabetical sorting as implemented by python's str.
Note that there is _no_ validation of any kind w.r.t. to the sanity of the passed values.
This function is not intended to be used by external users, and is planned to be removed
again.
'''
if not versions:
return
def to_ver(version_obj):
if hasattr(version_obj, 'version'):
if callable(version_obj.version):
return version_obj.version()
else:
return version_obj.version
else:
return str(version_obj)
try:
# try if all versions are semver-compatible
for version_str in map(to_ver, versions):
parse_to_semver(version_str)
return sorted(
versions,
key=lambda vo: parse_to_semver(to_ver(vo)),
)
except ValueError:
pass # ignore and fall-back to str-sorting
return sorted(
versions,
key=to_ver,
)