当前位置: 首页>>代码示例>>Python>>正文


Python semver.match函数代码示例

本文整理汇总了Python中semver.match函数的典型用法代码示例。如果您正苦于以下问题:Python match函数的具体用法?Python match怎么用?Python match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了match函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_version

 def _get_version(self, spec):
     spec = self._parse_spec(spec)
     version = spec['version']
     version_sign = spec['version_sign']
     resource_name = spec['resource_name']
     if version_sign == '==':
         return os.path.join(self.fpath, spec['resource_name'], version)
     found = self.iter_contents(resource_name)
     if version is None:
         sc = semver.compare
         sorted_vers = sorted(found,
                              cmp=lambda a, b: sc(a['version'],
                                                  b['version']),
                              reverse=True)
         if not sorted_vers:
             raise ResourceNotFound(spec)
         version = sorted_vers[0]['version']
     else:
         version = '{}{}'.format(version_sign, version)
         matched = filter(lambda x: semver.match(x['version'], version),
                          found)
         sorted_vers = sorted(matched,
                              cmp=lambda a, b: semver.compare(a['version'],
                                                              b['version']),
                              reverse=True)
         version = next((x['version'] for x in sorted_vers
                         if semver.match(x['version'], version)),
                        None)
     if version is None:
         raise ResourceNotFound(spec)
     return version
开发者ID:pigmej,项目名称:solar,代码行数:31,代码来源:repository.py

示例2: decide

  def decide(tree, args):
    bare_tree, configuration, tree_version = Interpreter._parse_tree(tree)
    if configuration != {}:
      time = None if len(args) == 1 else args[1]
      context_result = Interpreter._rebuild_context(configuration, args[0], time)
      context = context_result["context"]
    else:
      context = Interpreter.join_decide_args(args)

    # Convert timezones as integers into standard +/hh:mm format
    # This should only happen when no time generated value is required
    context = Interpreter._convert_timezones_to_standard_format(configuration, context)

    if semver.match(tree_version, ">=1.0.0") and semver.match(tree_version, "<2.0.0"):
      decision = InterpreterV1.decide(configuration, bare_tree, context)
    elif semver.match(tree_version, ">=2.0.0") and semver.match(tree_version, "<3.0.0"):
      decision = InterpreterV2.decide(configuration, bare_tree, context)
    else:
      raise CraftAiDecisionError(
        """Invalid decision tree format, "{}" is currently not a valid version.""".
        format(tree_version)
      )

    decision["context"] = context

    return decision
开发者ID:craft-ai,项目名称:craft-ai-client-python,代码行数:26,代码来源:interpreter.py

示例3: complex_semver_match

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
开发者ID:nzlosh,项目名称:st2,代码行数:30,代码来源:versioning.py

示例4: get_catalog_branch

def get_catalog_branch(version):
    if semver.match(version, "<=1.6.0"):
        return "master"
    elif semver.match(version, ">1.6.0") and semver.match(version, "<2.0.0"):
        return "v1.6-release"
    elif semver.match(version, ">=2.0.0"):
        return "v2.0-release"
    else:
        print "Unknown version"
        sys.exit(1)
开发者ID:cloudnautique,项目名称:rancher,代码行数:10,代码来源:print-catalog-images.py

示例5: exclude_update_from_latest

def exclude_update_from_latest(feature):
    """
    Exclude 'update from latest' scenario if branch version is lower than latest
    """
    if feature.name in PKG_UPDATE_SUITES:
        branch = CONF.feature.branch
        if branch == 'latest':  # Excludes when trying to update from latest to latest
            match = True
        else:
            for br in [branch, 'latest']:
                last_version = get_scalaraizr_latest_version(br)
                if len(last_version.split('.')) == 3:
                    minor = int(last_version.split('.')[2][0])
                else:
                    minor = '0'
                if last_version.strip().endswith('-1'):
                    last_version = last_version.strip()[:-2]
                if br == branch:
                    to_version = last_version.split('.')[0] + '.' + last_version.split('.')[1] + '.' + str(minor)
                    LOG.debug("Testing branch version: %s" % to_version)
                else:
                    latest_version = last_version.split('.')[0] + '.' + last_version.split('.')[1] + '.' + str(minor)
                    LOG.debug("Latest version: %s" % latest_version)
            match = semver.match(latest_version, '>' + to_version)
        if match:
            scenario = [s for s in feature.scenarios if s.name == 'Update from latest to branch from ScalrUI'][0]
            feature.scenarios.remove(scenario)
            LOG.info("Removed scenario: %s" % scenario)
开发者ID:Scalr,项目名称:revizor-tests,代码行数:28,代码来源:hooks_terrain.py

示例6: connect

    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))
开发者ID:Harikrishnan-github,项目名称:deosorg,代码行数:29,代码来源:trezor.py

示例7: check_deps

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)
开发者ID:michaeldboyd,项目名称:indy-plenum,代码行数:25,代码来源:pkg_util.py

示例8: _load_client

def _load_client(name, client_type, hid_transport,
                 passphrase_ack, identity_type,
                 required_version, call_exception):

    def empty_passphrase_handler(_):
        return passphrase_ack(passphrase='')

    for d in hid_transport.enumerate():
        connection = client_type(hid_transport(d))
        connection.callback_PassphraseRequest = empty_passphrase_handler
        f = connection.features
        log.debug('connected to %s %s', name, 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, required_version):
            fmt = 'Please upgrade your {} firmware to {} version (current: {})'
            raise ValueError(fmt.format(name,
                                        required_version,
                                        current_version))
        yield ClientWrapper(connection=connection,
                            identity_type=identity_type,
                            device_name=name,
                            call_exception=call_exception)
开发者ID:WyseNynja,项目名称:trezor-agent,代码行数:28,代码来源:factory.py

示例9: getActualNodeVersion

def getActualNodeVersion(nodeVersionPackage, nodeVersionsHtml):
    nodeVersionsFile = open(nodeVersionsHtml)
    nodeVersionsContent = nodeVersionsFile.read()
    nodeVersionsFile.close()

    pattern = r"<a.*?>v(\d*)\.(\d*)\.(\d*)/</a>"
    regex   = re.compile(pattern)

    allVersions    = []
    stableVersions = []
    for match in regex.finditer(nodeVersionsContent):
        version = "%s.%s.%s" % (match.group(1), match.group(2), match.group(3))

        allVersions.append(version)

        minorVersion = int(match.group(2), 10)
        if minorVersion % 2 == 0:
            stableVersions.append(version)

    stableVersions.sort(semver.compare)
    stableVersions.reverse()

    allVersions.sort(semver.compare)
    allVersions.reverse()

    if nodeVersionPackage == "*": return stableVersions[0]

    for version in allVersions:
        if semver.match(version, nodeVersionPackage): return version

    return None
开发者ID:pmuellr,项目名称:cf-buildpack-nodejs,代码行数:31,代码来源:compile.py

示例10: validate_extensions

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
开发者ID:cakepietoast,项目名称:rpmvenv,代码行数:34,代码来源:loader.py

示例11: semverMatch

def semverMatch(have,want):
    try:
        if have.startswith('v'):
            have = have[1:]
        if want.startswith('~'):
            haveList = have.split('.')
            wantList = want[1:].split('.')
            return haveList[0] == wantList[0] and haveList[1] == wantList[1] and int(haveList[2]) >= int(wantList[2])
        elif want.startswith('^'):
            wantList = want[1:].split('.')
            greaterOrEqual = '>=%s.%s.%s' % (wantList[0], wantList[1], wantList[2])
            lessThan = '<%s.%s.%s' % (int(wantList[0]) + 1, 0, 0)
            return semver.match(have,greaterOrEqual) and semver.match(have, lessThan)
        else:
            return semver.match(have,want)
    except:
        return False
开发者ID:prozacchiwawa,项目名称:purescript-dep-viewer,代码行数:17,代码来源:server.py

示例12: __init__

    def __init__(self, server="localhost:8983",
                 detect_live_nodes=False,
                 user=None,
                 password=None,
                 timeout=10,
                 webappdir='solr',
                 version='5.3.0',
                 request_retries=1,
                 use_https=False):
        self.user = user
        self.password = password
        self.timeout = timeout
        self.webappdir = webappdir
        self.version = version
        self.request_retries = request_retries

        if not semver.match(version, MIN_SUPPORTED_VERSION) and semver.match(version, MAX_SUPPORTED_VERSION):
            raise Exception("Unsupported version %s" % version)

        if semver.match(self.version, '<5.4.0'):
            self.zk_path = '/{webappdir}/zookeeper'.format(webappdir=self.webappdir)
        else:
            self.zk_path = '/{webappdir}/admin/zookeeper'.format(webappdir=self.webappdir)
        
        protocol = "https" if use_https else "http"
        
        self.url_template = '{protocol}://{{server}}/{webappdir}/'.format(protocol=protocol, webappdir=self.webappdir)

        if type(server) == str:
            self.url = self.url_template.format(server=server)
            servers = [self.url, self.url]
            if detect_live_nodes:
                url = servers[0]
                self.servers = self.detect_nodes(url)
            else:
                self.servers = servers
        if type(server) == list:
            servers = [self.url_template.format(server=a) for a in server]
            if detect_live_nodes:
                url = servers[0]
                self.servers = self.detect_nodes(url)
            else:
                self.servers = servers

        self.client = _Request(self)
开发者ID:solrcloudpy,项目名称:solrcloudpy,代码行数:45,代码来源:connection.py

示例13: __init__

    def __init__(self, package, versionspec):

        # if something deprecated '>=4.1.0' we want it to raise during the 4.1.0-dev, and 4.1.0-rc, 
        # not just when we release 4.1.0, so remove any extra-tags.
        versionspec = versionspec.split('-')[0]

        current_version = traitlets.import_item(package+'.__version__')
        self.match =  semver.match(current_version, versionspec)
        self.package = package
        self.spec = versionspec
开发者ID:Carreau,项目名称:reaper,代码行数:10,代码来源:__init__.py

示例14: match

def match(version, spec):
  if version[0] == 'v':
    version = version[1:]
  if spec[0] == '^':
    base = spec[1:]
    parsed_base = semver.parse(base)
    if parsed_base['major'] > 0:
      top = semver.bump_major(base)
    elif parsed_base['minor'] > 0:
      top = semver.bump_minor(base)
    else:
      top = semver.bump_patch(base)
    return semver.match(version, ">="+base) and semver.match(version, "<="+top)
  else:
    try:
      return semver.match(version, spec)
    except ValueError:
      # this happens when the spec isn't an expression, in which case we need an exact match
      return semver.parse(version) == semver.parse(spec)
开发者ID:keanulee,项目名称:v2,代码行数:19,代码来源:versiontag.py

示例15: find_semantic_version

def find_semantic_version(releases, versions):
    matching_releases = []
    for release in releases:
        if release.count('.') == 2:
            try:
                if semver.match(release, versions[0]) \
                        and semver.match(release, versions[1]):
                    matching_releases.append(release)
            except:
                pass
    if len(matching_releases) == 1:
        out = matching_releases[0]
    elif len(matching_releases) == 2:
        out = semver.max_ver(matching_releases[0], matching_releases[1])
    elif len(matching_releases) > 2:
        out = sorted(matching_releases)[-1]
    else:
        out = False
    return out
开发者ID:SarahJaine,项目名称:formulate,代码行数:19,代码来源:formulate.py


注:本文中的semver.match函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。