Another, possibly easier way, to do this using gitpython , as in dd/setup.py :
from pkg_resources import parse_version # part of `setuptools` def git_version(version): """Return version with local version identifier.""" import git repo = git.Repo('.git') repo.git.status() # assert versions are increasing latest_tag = repo.git.describe( match='v[0-9]*', tags=True, abbrev=0) assert parse_version(latest_tag) <= parse_version(version), ( latest_tag, version) sha = repo.head.commit.hexsha if repo.is_dirty(): return '{v}.dev0+{sha}.dirty'.format( v=version, sha=sha) # commit is clean # is it release of `version` ? try: tag = repo.git.describe( match='v[0-9]*', exact_match=True, tags=True, dirty=True) except git.GitCommandError: return '{v}.dev0+{sha}'.format( v=version, sha=sha) assert tag == 'v' + version, (tag, version) return version
cf also discussion at https://github.com/tulip-control/tulip-control/pull/145
source share