Esempio n. 1
0
def _get_version_from_git(pre_version=None):
    """Calculate a version string from git.

    If the revision is tagged, return that. Otherwise calculate a semantic
    version description of the tree.

    The number of revisions since the last tag is included in the dev counter
    in the version for untagged versions.

    :param pre_version: If supplied use this as the target version rather than
        inferring one from the last tag + commit messages.
    """
    git_dir = git._run_git_functions()
    if git_dir:
        try:
            tagged = git._run_git_command(["describe", "--exact-match"], git_dir, throw_on_error=True).replace("-", ".")
            target_version = version.SemanticVersion.from_pip_string(tagged)
        except Exception:
            if pre_version:
                # not released yet - use pre_version as the target
                target_version = version.SemanticVersion.from_pip_string(pre_version)
            else:
                # not released yet - just calculate from git history
                target_version = None
        result = _get_version_from_git_target(git_dir, target_version)
        return result.release_string()
    # If we don't know the version, return an empty string so at least
    # the downstream users of the value always have the same type of
    # object to work with.
    try:
        return unicode()
    except NameError:
        return ""
Esempio n. 2
0
def write_pbr_json(cmd, basename, filename):
    git_dir = git._run_git_functions()
    if not git_dir:
        return
    values = dict()
    git_version = git.get_git_short_sha(git_dir)
    is_release = git.get_is_release(git_dir)
    if git_version is not None:
        values['git_version'] = git_version
        values['is_release'] = is_release
        cmd.write_file('pbr', filename, json.dumps(values))
Esempio n. 3
0
def write_pbr_json(cmd, basename, filename):
    if not hasattr(cmd.distribution, 'pbr') or not cmd.distribution.pbr:
        return
    git_dir = git._run_git_functions()
    if not git_dir:
        return
    values = dict()
    git_version = git.get_git_short_sha(git_dir)
    is_release = git.get_is_release(git_dir)
    if git_version is not None:
        values['git_version'] = git_version
        values['is_release'] = is_release
        cmd.write_file('pbr', filename, json.dumps(values, sort_keys=True))
Esempio n. 4
0
def _get_version_from_git(pre_version):
    """Return a version which is equal to the tag that's on the current
    revision if there is one, or tag plus number of additional revisions
    if the current revision has no tag.
    """

    git_dir = git._run_git_functions()
    if git_dir:
        if pre_version:
            try:
                return git._run_git_command(['describe', '--exact-match'],
                                            git_dir,
                                            throw_on_error=True).replace(
                                                '-', '.')
            except Exception:
                return "%s.dev%s" % (pre_version, _get_revno(git_dir))
        else:
            # git describe always is going to return one of three things
            # - a short-sha if there are no tags
            # - a tag, if there's one on the current revision
            # - a string of the form $last_tag-$revs_since_last_tag-g$short_sha
            raw_version = git._run_git_command(['describe', '--always'],
                                               git_dir)
            # First, if there are no -'s or .'s, then it's just a short sha.
            # Create a synthetic version for it.
            if '-' not in raw_version and '.' not in raw_version:
                return "0.0.0.post%s" % _get_revno(git_dir)
            # Now, we want to strip the short-sha prefix
            stripped_version = raw_version.split('-g')[0]
            # Finally, if we convert - to .post, which will turn the remaining
            # - which separates the version from the revcount into a PEP440
            # post string
            return stripped_version.replace('-', '.post')

    # If we don't know the version, return an empty string so at least
    # the downstream users of the value always have the same type of
    # object to work with.
    try:
        return unicode()
    except NameError:
        return ''
Esempio n. 5
0
def _get_version_from_git(pre_version):
    """Return a version which is equal to the tag that's on the current
    revision if there is one, or tag plus number of additional revisions
    if the current revision has no tag.
    """

    git_dir = git._run_git_functions()
    if git_dir:
        if pre_version:
            try:
                return git._run_git_command(
                    ['describe', '--exact-match'], git_dir,
                    throw_on_error=True).replace('-', '.')
            except Exception:
                return "%s.dev%s" % (pre_version, _get_revno(git_dir))
        else:
            # git describe always is going to return one of three things
            # - a short-sha if there are no tags
            # - a tag, if there's one on the current revision
            # - a string of the form $last_tag-$revs_since_last_tag-g$short_sha
            raw_version = git._run_git_command(['describe', '--always'],
                                               git_dir)
            # First, if there are no -'s or .'s, then it's just a short sha.
            # Create a synthetic version for it.
            if '-' not in raw_version and '.' not in raw_version:
                return "0.0.0.post%s" % _get_revno(git_dir)
            # Now, we want to strip the short-sha prefix
            stripped_version = raw_version.split('-g')[0]
            # Finally, if we convert - to .post, which will turn the remaining
            # - which separates the version from the revcount into a PEP440
            # post string
            return stripped_version.replace('-', '.post')

    # If we don't know the version, return an empty string so at least
    # the downstream users of the value always have the same type of
    # object to work with.
    try:
        return unicode()
    except NameError:
        return ''
Esempio n. 6
0
def _get_version_from_git(pre_version=None):
    """Calculate a version string from git.

    If the revision is tagged, return that. Otherwise calculate a semantic
    version description of the tree.

    The number of revisions since the last tag is included in the dev counter
    in the version for untagged versions.

    :param pre_version: If supplied use this as the target version rather than
        inferring one from the last tag + commit messages.
    """
    git_dir = git._run_git_functions()
    if git_dir:
        try:
            tagged = git._run_git_command(['describe', '--exact-match'],
                                          git_dir,
                                          throw_on_error=True).replace(
                                              '-', '.')
            target_version = version.SemanticVersion.from_pip_string(tagged)
        except Exception:
            if pre_version:
                # not released yet - use pre_version as the target
                target_version = version.SemanticVersion.from_pip_string(
                    pre_version)
            else:
                # not released yet - just calculate from git history
                target_version = None
        result = _get_version_from_git_target(git_dir, target_version)
        return result.release_string()
    # If we don't know the version, return an empty string so at least
    # the downstream users of the value always have the same type of
    # object to work with.
    try:
        return unicode()
    except NameError:
        return ''