• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python semver.parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: version

def version():
    """
    Returns the version of BTW. This value is computed once and then
    cached.
    """
    global _cached_version  # pylint: disable-msg=global-statement
    if _cached_version is not None:
        return _cached_version

    # We have to be running from a git tree.
    unclean = subprocess.check_output(["git", "status", "--porcelain"])

    if not (settings.DEBUG or settings.BTW_TESTING) and unclean:
        raise Exception("running with unclean tree while DEBUG is false")

    describe = subprocess.check_output(["git", "describe", "--match",
                                        "v*"]).strip()

    if unclean:
        describe += "-unclean"

    sep = describe.find("-")
    semver.parse(describe[1:len(describe) if sep == -1 else sep])

    _cached_version = describe

    return describe
开发者ID:mangalam-research,项目名称:btw,代码行数:27,代码来源:util.py


示例2: get_version_number

def get_version_number():
    """
    Prompts the user to enter the version number being released. 
    Outputs the current version number.
    """
    context = {}
    context['current_version'] = apptemplate.VERSION
  
    puts('Current version: %(current_version)s' % context)
    new_version = None
    input = None
    while not new_version:
        if input is not None:
            puts('Invalid version number')
            
        input = raw_input('Enter the new version number: ')
        print input
        try:
            semver.parse(input)
        except ValueError:
            pass
        else:
            new_version = input
            
    return new_version
开发者ID:jakul,项目名称:apptemplate,代码行数:25,代码来源:fabfile.py


示例3: main

def main():
    p = argparse.ArgumentParser()
    p.add_argument("input_file")
    p.add_argument("output_file")

    args = p.parse_args()

    actual_data = []
    sim_data = []
    ult_data = []

    pat = re.compile("^A(?P<actual>.*),S(?P<sim>.*),S(?P<ult>.*)$", re.M)
    with open(args.input_file, 'r') as fin:
        for line in fin:
            m = re.match(pat, line)
            actual = m.group("actual")
            sim = m.group("sim")
            ult = m.group("ult")

            # Parse into decimal
            m_actual = semver.parse(actual)
            m_sim = semver.parse(sim)
            m_ult = semver.parse(ult)

            actual_data.append(m_actual)
            sim_data.append(m_sim)
            ult_data.append(m_ult)

    max_minor = {}
    for v in (sim_data + actual_data + ult_data):
        old_max = max_minor.get(v[0], 0)
        max_minor[v[0]] = max(v[1],old_max)
            
    with open(args.output_file, 'w') as fo:
        for i in range(len(sim_data)):
            simV = sim_data[i]
            ultV = ult_data[i]
            actV = actual_data[i]

            simMinor = int(100 * float(simV[1])/(max_minor[simV[0]] + 1))
            ultMinor = int(100 * float(ultV[1])/(max_minor[ultV[0]] + 1))
            actMinor = int(100 * float(actV[1])/(max_minor[actV[0]] + 1))

            f_actual = float("%02d.%02d" % (actV[0], actMinor))
            f_sim = float("%02d.%02d" % (simV[0], simMinor))
            f_ult = float("%02d.%02d" % (ultV[0], ultMinor))

            print "SimVersion = %s, f_sim = %s, ActVersion = %s, f_actual = %s" % (simV, f_sim, actV, f_actual)
            
            fo.write("{} {} {}\n".format(f_actual, f_sim, f_ult))
开发者ID:joecox,项目名称:checkable-semver,代码行数:50,代码来源:analyse-sim.py


示例4: test_should_parse_version

    def test_should_parse_version(self):
        self.assertEqual(
            parse("1.2.3-alpha.1.2+build.11.e0f985a"),
            {'major': 1,
             'minor': 2,
             'patch': 3,
             'prerelease': 'alpha.1.2',
             'build': 'build.11.e0f985a'})

        self.assertEqual(
            parse("1.2.3-alpha-1+build.11.e0f985a"),
            {'major': 1,
             'minor': 2,
             'patch': 3,
             'prerelease': 'alpha-1',
             'build': 'build.11.e0f985a'})
开发者ID:chinakids,项目名称:python-semver,代码行数:16,代码来源:semver_test.py


示例5: _parse_str

 def _parse_str(self, version):
     """
     Parse version as string and initialize self with data from version
     :param version:
     :return:
     """
     version = semver.parse(version)
     self._parse_dict(version)
开发者ID:pombredanne,项目名称:versionner,代码行数:8,代码来源:version.py


示例6: _list_source_contents_from_multidir

 def _list_source_contents_from_multidir(cls, source):
     for pth in os.listdir(source):
         single_path = os.path.join(source, pth)
         if pth.endswith('.yaml'):
             pth = pth[:-5]
             yield RES_TYPE.Composer, pth, single_path
         elif os.path.exists(os.path.join(single_path, 'meta.yaml')):
             try:
                 semver.parse(pth)
             except ValueError:
                 name = pth
             else:
                 # if it was semver then single_path may look like
                 # /a/b/name/version
                 # and source may look like /a/b/name
                 # we can extract name from this path then
                 name = os.path.split(source)[-1]
             yield RES_TYPE.Normal, name, single_path
         else:
             maybe_cr = os.path.join(single_path,
                                     "{}.yaml".format(
                                         os.path.split(source)[-1]))
             if os.path.exists(maybe_cr):
                 name = os.path.split(source)[-1]
                 yield RES_TYPE.Composer, name, maybe_cr
                 continue
             if not os.path.isdir(single_path):
                 continue
             for single in os.listdir(single_path):
                 try:
                     semver.parse(single)
                 except ValueError:
                     fp = os.path.join(single_path, single)
                     raise RepositoryException(
                         "Unexpected repository content "
                         "structure: {} ""Expected directory "
                         "with version number".format(single_path))
                 else:
                     fp = os.path.join(single_path, single)
                     if os.path.exists(os.path.join(fp, 'meta.yaml')):
                         yield RES_TYPE.Normal, pth, fp
                     elif os.path.exists(
                             os.path.join(fp, '{}.yaml'.format(pth))):
                         cr = os.path.join(fp, '{}.yaml'.format(pth))
                         yield RES_TYPE.Composer, pth, cr
开发者ID:pigmej,项目名称:solar,代码行数:45,代码来源:repository.py


示例7: test_should_parse_version

def test_should_parse_version():
    result = parse("1.2.3-alpha.1.2+build.11.e0f985a")
    assert result == {
        'major': 1,
        'minor': 2,
        'patch': 3,
        'prerelease': 'alpha.1.2',
        'build': 'build.11.e0f985a',
    }

    result = parse("1.2.3-alpha-1+build.11.e0f985a")
    assert result == {
        'major': 1,
        'minor': 2,
        'patch': 3,
        'prerelease': 'alpha-1',
        'build': 'build.11.e0f985a',
    }
开发者ID:jeloagnasin,项目名称:python-semver,代码行数:18,代码来源:tests.py


示例8: semver_bumper

def semver_bumper(old_version, part="patch"):
    """Bump the version with ``semver`` module.
    
    :arg str part: Specify which part should be bumped. Possible values are
        ``"patch"``, ``"minor"``, or ``"major"``.
        
        If ``part`` is a valid version number, it would bump the version
        number to ``part``.
    :rtype: str
    :return: new version number.
    """
    import semver
    bump = getattr(semver, "bump_" + part, None)
    if callable(bump):
        new_version = bump(old_version)
    else:
        new_version = part
        semver.parse(new_version)
    return new_version
开发者ID:eight04,项目名称:pyXcute,代码行数:19,代码来源:__init__.py


示例9: set

    def set(self, field, value):
        """
        Set any field of semver to `value`

        :rtype : Version
        :param field:type of field (one of Version.VALID_FIELDS)
        :param value:
        :return: :raise ValueError:
        """

        if field not in self.VALID_FIELDS:
            raise ValueError("Incorrect value of \"type\"")

        version = Version(self)
        setattr(version, field, value)

        semver.parse(str(version))

        return version
开发者ID:janusnic,项目名称:versionner,代码行数:19,代码来源:version.py


示例10: 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


示例11: read

    def read(self):
        """
        Read version from version file

        :rtype : Version
        :return:
        """
        with self._path.open(mode='r') as fh:
            version = fh.read().strip()
            version = semver.parse(version)
            return Version(version)
开发者ID:janusnic,项目名称:versionner,代码行数:11,代码来源:version.py


示例12: tag_semver

    def tag_semver(self):
        """
        Job tag, parsed as semver (or None if no match). Allows a 'v' prefix
        """
        if self.tag is None:
            return None

        try:
            return semver.parse(self._tag_without_v)
        except ValueError:
            pass
开发者ID:sprucedev,项目名称:DockCI-Agent,代码行数:11,代码来源:job.py


示例13: test_get_decision_trees_bulk_specific_version

  def test_get_decision_trees_bulk_specific_version(self):
    """get_decision_trees_bulk should succeed when given a specific version.

    It should give a proper JSON response with a list containing a dict
    with `id` field being string and 'tree' field being a dict with the
    field 'version''major' being the version given as a parameter.
    """
    payload = [{"id": self.agent_id1, "timestamp": valid_data.VALID_LAST_TIMESTAMP},
               {"id": self.agent_id2, "timestamp": valid_data.VALID_LAST_TIMESTAMP}]
    version = 1
    decision_trees = self.client.get_decision_trees_bulk(payload, version)

    self.assertNotEqual(decision_trees[0].get("tree").get("_version"), None)
    tree_version = semver.parse(decision_trees[0].get("tree").get("_version"))
    self.assertEqual(tree_version["major"], version)
    self.assertNotEqual(decision_trees[1].get("tree").get("_version"), None)
    tree_version = semver.parse(decision_trees[1].get("tree").get("_version"))
    self.assertEqual(tree_version["major"], version)

    self.addCleanup(self.clean_up_agents,
                    [self.agent_id1, self.agent_id2])
开发者ID:craft-ai,项目名称:craft-ai-client-python,代码行数:21,代码来源:test_get_decision_trees_bulk.py


示例14: test_should_raise_value_error_for_zero_prefixed_versions

def test_should_raise_value_error_for_zero_prefixed_versions():
    with pytest.raises(ValueError):
        parse("01.2.3")
    with pytest.raises(ValueError):
        parse("1.02.3")
    with pytest.raises(ValueError):
        parse("1.2.03")
开发者ID:jeloagnasin,项目名称:python-semver,代码行数:7,代码来源:tests.py


示例15: get_latest_release

    def get_latest_release(self):
        response = requests.get(self.releases_url)
        releases = response.json()

        latest_version = None
        for r in releases:
            if r["prerelease"] and not self.include_prereleases:
                continue
            version = r["tag_name"]
            # some tag was create with 'v' letter, we should remove it (ex. v0.0.3-alpha -> 0.0.3-alpha)
            if version[0] == "v":
                version = version[1:]

            # latest version of semver can't parse 0 per-release version (ex: 1.0.0-rc.0)
            try:
                semver.parse(version)
            except ValueError:
                continue

            if latest_version is None or semver.compare(version, latest_version) > 0:
                latest_version = version
        return latest_version
开发者ID:werwolfby,项目名称:monitorrent,代码行数:22,代码来源:new_version_checker.py


示例16: test_get_decision_tree_with_specific_version

def test_get_decision_tree_with_specific_version():
  version = 1
  decision_tree = CLIENT.get_decision_tree(
    AGENT_ID,
    valid_data.VALID_TIMESTAMP,
    version)

  assert_is_instance(decision_tree, dict)
  assert_not_equal(decision_tree.get("_version"), None)
  tree_version = semver.parse(decision_tree.get("_version"))
  assert_equal(tree_version["major"], version)
  assert_not_equal(decision_tree.get("configuration"), None)
  assert_not_equal(decision_tree.get("trees"), None)
开发者ID:craft-ai,项目名称:craft-ai-client-python,代码行数:13,代码来源:test_get_decision_tree.py


示例17: _list_source_contents

 def _list_source_contents(cls, source):
     if source.endswith('.yaml'):
         # single CR
         pth = os.path.split(source)[-1][:-5]
         return ((RES_TYPE.Composer, pth, source), )
     elif os.path.isdir(source):
         meta_path = os.path.join(source, 'meta.yaml')
         if os.path.exists(meta_path):
             # single normal
             pth = os.path.split(source)[-1]
             try:
                 semver.parse(pth)
             except ValueError:
                 name = pth
             else:
                 # if it was semver then single_path may look like
                 # /a/b/name/version
                 # and source may look like /a/b/name
                 # we can extract name from this path then
                 name = source.split(os.path.sep)[-2]
             return ((RES_TYPE.Normal, name, source), )
         return tuple(cls._list_source_contents_from_multidir(source))
开发者ID:pigmej,项目名称:solar,代码行数:22,代码来源:repository.py


示例18: get_tags

def get_tags(image):
    php_version = semver.parse(image[0])
    php_versions = []

    if php_version["major"] == 7:
        if php_version["minor"] == 0:
            php_versions.append("7")
    else:
        php_versions.append(str(php_version["major"]))

    php_versions.extend([minorize(image[0]), image[0]])

    for tag in php_versions:
        yield matrix_join((tag,) + image[1:], "-")
开发者ID:webplates,项目名称:docker-symfony-php,代码行数:14,代码来源:helper.py


示例19: set

    def set(self, field, value):
        """
        Set any field of semver to `value`

        :rtype : Version
        :param field:type of field (one of Version.VALID_FIELDS)
        :param value:
        :return: :raise ValueError:
        """

        if field not in self.VALID_FIELDS:
            raise ValueError("Invalid field type: %s" % field)

        version = Version(self)
        setattr(version, field, value)

        # validation
        try:
            semver.parse(str(version))
        except ValueError as exc:
            raise InvalidVersionError("Invalid value for field %s: %s" % (field, value)) from exc

        return version
开发者ID:pombredanne,项目名称:versionner,代码行数:23,代码来源:version.py


示例20: test_semantic_version

    def test_semantic_version(self):
        """ociVersion (string, required) MUST be in SemVer v2.0.0 format.

        The spec wording in the docstring summary is from [1,2].
        v0.5.0 used 'must' instead of 'MUST', but that was accidental
        [3].

        This test is not restricted to known versions, because we
        expect a semantic-versioned field to extend to all spec
        releases (otherwise what's the point of SemVer?).

        [1]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc1/config.md#specification-version
        [2]: https://github.com/opencontainers/runtime-spec/blob/v0.5.0/config.md#specification-version
        [3]: https://github.com/opencontainers/runtime-spec/pull/409
        """
        self.assertTrue(isinstance(util.VERSION, str), 'ociVersion is not a string')
        try:
            version = semver.parse(version=util.VERSION)
        except ValueError as error:
            raise self.failureException(str(error)) from error
开发者ID:wking,项目名称:oci-runtime-config-validator,代码行数:20,代码来源:test_version.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python send2trash.send2trash函数代码示例发布时间:2022-05-27
下一篇:
Python semver.match函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap