Python semver.VersionInfo() Examples
The following are 15
code examples of semver.VersionInfo().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
semver
, or try the search function
.
Example #1
Source File: test_utils.py From singularity-cli with Mozilla Public License 2.0 | 6 votes |
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)
Example #2
Source File: version.py From cc-utils with Apache License 2.0 | 6 votes |
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
Example #3
Source File: version_utils.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #4
Source File: base.py From agents-aea with Apache License 2.0 | 5 votes |
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.")
Example #5
Source File: version.py From cc-utils with Apache License 2.0 | 5 votes |
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
Example #6
Source File: version.py From cc-utils with Apache License 2.0 | 5 votes |
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
Example #7
Source File: version.py From cc-utils with Apache License 2.0 | 5 votes |
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() ]
Example #8
Source File: test_version_utils.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
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')
Example #9
Source File: conftest.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def check(): c = PostgreSql('postgres', {}, [{'dbname': 'dbname', 'host': 'localhost', 'port': '5432', 'username': USER}]) c._version = VersionInfo(9, 2, 0) return c
Example #10
Source File: test_integration.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #11
Source File: test_unit.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #12
Source File: test_unit.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #13
Source File: test_unit.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #14
Source File: test_unit.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
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']
Example #15
Source File: version.py From cc-utils with Apache License 2.0 | 4 votes |
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, )