summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2012-06-19 16:02:34 -0700
committerMonty Taylor <mordred@inaugust.com>2012-06-24 16:49:41 -0500
commit65efad1deca35e383b63cad795f6cff43cbae305 (patch)
treeb63d037084b003cd62b49246288a93a89375e030 /setup.py
parent83daa0490e8d271d03731726f9c71af4c5f13ac2 (diff)
downloadpbr-65efad1deca35e383b63cad795f6cff43cbae305.tar.gz
Add support for tag based versioning.
Versions driven by git. If the current revision is tagged, then that's the version cut. If not, for post-versioning, the current version is the tag plus an count of the revs since the tag. For pre-versioning, it's the logic that's in create-tarball.sh. Additionally, a versioninfo file is added to the tree so that pkg-resources can find out what the version is. Change-Id: I5991345735fa14666305538c556b519160b02b4b
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py120
1 files changed, 96 insertions, 24 deletions
diff --git a/setup.py b/setup.py
index 6b34417..e9cd340 100644
--- a/setup.py
+++ b/setup.py
@@ -19,6 +19,7 @@
Utilities with minimum-depends for use in setup.py
"""
+import datetime
import os
import re
import subprocess
@@ -34,8 +35,7 @@ def parse_mailmap(mailmap='.mailmap'):
for l in fp:
l = l.strip()
if not l.startswith('#') and ' ' in l:
- canonical_email, alias = [x for x in l.split(' ')
- if x.startswith('<')]
+ canonical_email, alias = l.split(' ')
mapping[alias] = canonical_email
return mapping
@@ -118,28 +118,54 @@ def write_requirements():
def _run_shell_command(cmd):
output = subprocess.Popen(["/bin/sh", "-c", cmd],
stdout=subprocess.PIPE)
- return output.communicate()[0].strip()
-
-
-def write_vcsversion(location):
- """Produce a vcsversion dict that mimics the old one produced by bzr.
- """
- if os.path.isdir('.git'):
- branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "'
- branch_nick = _run_shell_command(branch_nick_cmd)
- revid_cmd = "git rev-parse HEAD"
- revid = _run_shell_command(revid_cmd).split()[0]
- revno_cmd = "git log --oneline | wc -l"
- revno = _run_shell_command(revno_cmd)
- with open(location, 'w') as version_file:
- version_file.write("""
-# This file is automatically generated by setup.py, So don't edit it. :)
-version_info = {
- 'branch_nick': '%s',
- 'revision_id': '%s',
- 'revno': %s
-}
-""" % (branch_nick, revid, revno))
+ out = output.communicate()
+ if len(out) == 0:
+ return None
+ if len(out[0].strip()) == 0:
+ return None
+ return out[0].strip()
+
+
+def _get_git_next_version_suffix(branch_name):
+ datestamp = datetime.datetime.now().strftime('%Y%m%d')
+ if branch_name == 'milestone-proposed':
+ revno_prefix = "r"
+ else:
+ revno_prefix = ""
+ _run_shell_command("git fetch origin +refs/meta/*:refs/remotes/meta/*")
+ milestone_cmd = "git show meta/openstack/release:%s" % branch_name
+ milestonever = _run_shell_command(milestone_cmd)
+ if not milestonever:
+ milestonever = ""
+ post_version = _get_git_post_version()
+ revno = post_version.split(".")[-1]
+ return "%s~%s.%s%s" % (milestonever, datestamp, revno_prefix, revno)
+
+
+def _get_git_current_tag():
+ return _run_shell_command("git tag --contains HEAD")
+
+
+def _get_git_tag_info():
+ return _run_shell_command("git describe --tags")
+
+
+def _get_git_post_version():
+ current_tag = _get_git_current_tag()
+ if current_tag is not None:
+ return current_tag
+ else:
+ tag_info = _get_git_tag_info()
+ if tag_info is None:
+ base_version = "0.0"
+ cmd = "git --no-pager log --oneline"
+ out = _run_shell_command(cmd)
+ revno = len(out.split("\n"))
+ else:
+ tag_infos = tag_info.split("-")
+ base_version = "-".join(tag_infos[:-2])
+ revno = tag_infos[-2]
+ return "%s.%s" % (base_version, revno)
def write_git_changelog():
@@ -179,6 +205,11 @@ _rst_template = """%(heading)s
"""
+def write_versioninfo(project, version):
+ """Write a simple file containing the version of the package."""
+ open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version)
+
+
def get_cmdclass():
"""Return dict of commands to run from setup.py."""
@@ -255,3 +286,44 @@ def get_cmdclass():
pass
return cmdclass
+
+
+def get_git_branchname():
+ for branch in _run_shell_command("git branch --color=never").split("\n"):
+ if branch.startswith('*'):
+ _branch_name = branch.split()[1].strip()
+ if _branch_name == "(no":
+ _branch_name = "no-branch"
+ return _branch_name
+
+
+def get_pre_version(projectname, base_version):
+ """Return a version which is based"""
+ if os.path.isdir('.git'):
+ current_tag = _get_git_current_tag()
+ if current_tag is not None:
+ version = current_tag
+ else:
+ branch_name = os.getenv('BRANCHNAME',
+ os.getenv('GERRIT_REFNAME',
+ get_git_branchname()))
+ version_suffix = _get_git_next_version_suffix(branch_name)
+ version = "%s~%s" % (base_version, version_suffix)
+ write_versioninfo(projectname, version)
+ return version.split('~')[0]
+ else:
+ with open(os.path.join(projectname, 'versioninfo'), 'r') as vinfo:
+ full_version = vinfo.read().strip()
+ return full_version.split('~')[0]
+
+
+def get_post_version(projectname):
+ """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."""
+
+ if os.path.isdir('.git'):
+ version = _get_git_post_version()
+ write_versioninfo(projectname, version)
+ return version
+ return open(os.path.join(projectname, 'versioninfo'), 'r').read().strip()