本文整理汇总了Python中semver.match方法的典型用法代码示例。如果您正苦于以下问题:Python semver.match方法的具体用法?Python semver.match怎么用?Python semver.match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类semver
的用法示例。
在下文中一共展示了semver.match方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_deps
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def check_deps(dependencies, parent=""):
if isinstance(dependencies, dict):
for pkg_name, exp_ver in dependencies.items():
if parent:
full_name = "{} ({})".format(pkg_name, parent)
else:
full_name = pkg_name
meta = getPackageMeta(pkg_name)
ver = meta.__version__
if MAJOR_MINOR_REGEX.fullmatch(ver):
ver += ".0" # Add a fictive patch number to fit semver format
if not semver.match(ver, exp_ver):
raise RuntimeError("Incompatible '{}' package version. "
"Expected: {} "
"Found: {}".
format(pkg_name, exp_ver, ver))
if hasattr(meta, "__dependencies__"):
deps = meta.__dependencies__
check_deps(deps, full_name)
else:
pkg = dependencies if isinstance(dependencies, str) else \
dependencies.__name__
meta = getPackageMeta(pkg)
deps = meta.__dependencies__
check_deps(deps)
示例2: is_server_valid
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def is_server_valid(server_list, network):
# Check requested server is on list
available_servers = [s['name'] for s in server_list]
if network not in available_servers:
raise NetworkUnavailableError('Requested network not present on network: {}'.format(network))
# Check network version
server_details = next(s for s in server_list if s['name'] == network)
if server_details['versions'] != '*':
version_constraints = server_details['versions'].split(',')
# Build required version (e.g.: 0.9.1-alpha2 -> 0.9.0)
network_version_required = _parse_python_version(__version__)
network_version_required['prerelease'] = None
network_version_required['build'] = None
network_version_required['patch'] = 0
network_version_required = semver.format_version(**network_version_required)
if not all(semver.match(network_version_required, c) for c in version_constraints):
raise IncompatibleLedgerVersion("Requested network does not support required version\n" +
"Required version: {}\nNetwork supports: {}".format(
network_version_required, ', '.join(version_constraints)
))
# Return true if server valid
return True
示例3: main_create
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def main_create():
"""Main function for GPG identity creation."""
p = argparse.ArgumentParser()
p.add_argument('user_id')
p.add_argument('-e', '--ecdsa-curve', default='nist256p1')
p.add_argument('-t', '--time', type=int, default=int(time.time()))
p.add_argument('-v', '--verbose', default=0, action='count')
p.add_argument('-s', '--subkey', default=False, action='store_true')
args = p.parse_args()
util.setup_logging(verbosity=args.verbose)
log.warning('This GPG tool is still in EXPERIMENTAL mode, '
'so please note that the API and features may '
'change without backwards compatibility!')
existing_gpg = keyring.gpg_version().decode('ascii')
required_gpg = '>=2.1.11'
if semver.match(existing_gpg, required_gpg):
run_create(args)
else:
log.error('Existing gpg2 has version "%s" (%s required)',
existing_gpg, required_gpg)
示例4: for_platform
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def for_platform(cls, platform: Platform, min_os_version: str, queries: Set[Queries] = None) -> 'DeviceInformation':
"""Generate a command that is compatible with the specified platform and OS version.
Args:
platform (Platform): Desired target platform
min_os_version (str): Desired OS version
queries (Set[Queries]): Desired Queries, or default to ALL queries.
Returns:
DeviceInformation instance with supported queries.
"""
def supported(query) -> bool:
if query not in cls.Requirements:
return True
platforms = cls.Requirements[query]
for req_platform, req_min_version in platforms:
if req_platform != platform:
continue
# TODO: version checking
return True # semver only takes maj.min.patch
#return semver.match(min_os_version, req_min_version)
return False
if queries is None:
supported_queries = filter(supported, [q.value for q in cls.Queries])
else:
supported_queries = filter(supported, queries)
return cls(Queries=list(supported_queries))
示例5: verify_gpg_version
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def verify_gpg_version():
"""Make sure that the installed GnuPG is not too old."""
existing_gpg = keyring.gpg_version().decode('ascii')
required_gpg = '>=2.1.11'
msg = 'Existing GnuPG has version "{}" ({} required)'.format(existing_gpg,
required_gpg)
if not semver.match(existing_gpg, required_gpg):
log.error(msg)
示例6: _verify_version
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def _verify_version(self, connection):
f = connection.features
log.debug('connected to %s %s', self, f.device_id)
log.debug('label : %s', f.label)
log.debug('vendor : %s', f.vendor)
current_version = '{}.{}.{}'.format(f.major_version,
f.minor_version,
f.patch_version)
log.debug('version : %s', current_version)
log.debug('revision : %s', binascii.hexlify(f.revision))
if not semver.match(current_version, self.required_version):
fmt = ('Please upgrade your {} firmware to {} version'
' (current: {})')
raise ValueError(fmt.format(self, self.required_version,
current_version))
示例7: _pre_process_version
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def _pre_process_version(reported_version):
server_version = reported_version.lstrip('v')
# remove trailing git version if present
match = re.match(r'^(\d+\.\d+\.\d+)-(alpha|beta|rc)(\d+)-\d+-(g[a-f0-9]+)$', str(server_version))
if match is not None:
server_version = '{}-{}.{}+{}'.format(match.group(1), match.group(2), match.group(3), match.group(4))
match = re.match(r'^(\d+\.\d+\.\d+)-(alpha|beta|rc)(\d+)$', str(server_version))
if match is not None:
server_version = '{}-{}.{}'.format(match.group(1), match.group(2), match.group(3))
return server_version
示例8: check_version_compatibility
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def check_version_compatibility(reported_version, compatible_versions):
server_version = _pre_process_version(reported_version)
if server_version.startswith('Unknown version with hash'):
logging.warning('Using development version')
elif not all(semver.match(server_version, c) for c in compatible_versions):
raise IncompatibleLedgerVersion("Ledger version running on server is not compatible with this API" +
"\nServer version: {} \nExpected version: {}".format(
server_version, ', '.join(compatible_versions)))
示例9: _parse_python_version
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def _parse_python_version(text):
match = re.match(r'^(\d+)\.(\d+)\.\d+(?:[abd]\d+)?$', text.strip())
if match is None:
raise RuntimeError('Unable to parse python version')
ver = {
'major': int(match.group(1)),
'minor': int(match.group(2)),
}
return ver
示例10: validate_extensions
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def validate_extensions(extensions):
"""Process the extension dependencies."""
ext_map = dict(
(ext.name, ext) for ext in extensions
)
for ext in extensions:
for dependency, versions in ext.requirements.items():
ext_dependency = ext_map.get(dependency, None)
if not ext_dependency:
raise MissingDependency(
'{0} is required by {1} but is not loaded.'.format(
ext.name,
dependency,
)
)
for version in versions:
if not semver.match(ext.version, version):
raise InvalidDependency(
'{0}-{1} required by {2} but found {0}-{3}.'.format(
dependency,
version,
ext.name,
ext.version,
)
)
return extensions
示例11: version_match
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def version_match(value, pattern):
return semver.match(value, pattern)
示例12: complex_semver_match
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def complex_semver_match(version, version_specifier):
"""
Custom semver match function which also supports complex semver specifiers
such as >=1.6, <2.0, etc.
NOTE: This function also supports special "all" version specifier. When "all"
is specified, any version provided will be considered valid.
:rtype: ``bool``
"""
if version_specifier == 'all':
return True
split_version_specifier = version_specifier.split(',')
if len(split_version_specifier) == 1:
# No comma, we can do a simple comparision
return semver.match(version, version_specifier)
else:
# Compare part by part
for version_specifier_part in split_version_specifier:
version_specifier_part = version_specifier_part.strip()
if not version_specifier_part:
continue
if not semver.match(version, version_specifier_part):
return False
return True
示例13: connect
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def connect(self):
"""Enumerate and connect to the first USB HID interface."""
def passphrase_handler(_):
log.debug('using %s passphrase for %s',
'non-empty' if self.passphrase else 'empty', self)
return self._defs.PassphraseAck(passphrase=self.passphrase)
for d in self._defs.HidTransport.enumerate():
log.debug('endpoint: %s', d)
transport = self._defs.HidTransport(d)
connection = self._defs.Client(transport)
connection.callback_PassphraseRequest = passphrase_handler
f = connection.features
log.debug('connected to %s %s', self, f.device_id)
log.debug('label : %s', f.label)
log.debug('vendor : %s', f.vendor)
current_version = '{}.{}.{}'.format(f.major_version,
f.minor_version,
f.patch_version)
log.debug('version : %s', current_version)
log.debug('revision : %s', binascii.hexlify(f.revision))
if not semver.match(current_version, self.required_version):
fmt = ('Please upgrade your {} firmware to {} version'
' (current: {})')
raise ValueError(fmt.format(self, self.required_version,
current_version))
connection.ping(msg='', pin_protection=True) # unlock PIN
return connection
raise interface.NotFoundError('{} not connected'.format(self))
示例14: find_semver_match
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def find_semver_match(constraint, versions_list):
matcher = create_semver_matcher(constraint)
for vstr in reversed(versions_list):
if matcher.match(str_to_version(vstr)):
return vstr
return None
示例15: match
# 需要导入模块: import semver [as 别名]
# 或者: from semver import match [as 别名]
def match(self, v):
"""Check if `v` matches the constraint"""
while len(v) < 3:
v = v + (0,)
v_str = ".".join(map(str, v))
return semver.match(v_str, self.constraint_str)