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


Python semver.parse函数代码示例

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


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


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