Beispiel #1
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))
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))
Beispiel #3
0
    from pbr import git
    has_pbr = True
except ModuleNotFoundError:
    has_pbr = False

if not has_importlib_metadata and not has_pbr:
    # This can also happen with py>3.8 on conda editable install
    raise ModuleNotFoundError('Must have pbr for python < 3.8')

git_dir = Path(__file__).parent.parent / '.git'

if has_pbr:
    try:
        info = version.VersionInfo(package_name)
        __version__ = __version__ or info.version_string()
        __git_sha__ = git.get_git_short_sha(git_dir)

    except Exception:  # Pbr throws very broad Exception, for some reason DistributionNotFound does not want to be caught
        git_dir = Path(__file__).parent.parent / '.git'
        try:
            tagged = git._run_git_command(['describe', '--tags'],
                                          git_dir,
                                          throw_on_error=True).replace(
                                              '-', '.')
            semantic_version = version.SemanticVersion.from_pip_string(tagged)
            __version__ = __version__ or semantic_version._long_version(None)
            __git_sha__ = git.get_git_short_sha(git_dir)
        except FileNotFoundError:
            # Git not installed
            __git_sha__ = None
else: