76
77
# -f lines are for index locations, and don't get used here
77
78
elif re.match(r'\s*-f\s+', line):
80
# argparse is part of the standard library starting with 2.7
81
# adding it to the requirements list screws distro installs
82
elif line == 'argparse' and sys.version_info >= (2, 7):
80
85
requirements.append(line)
113
118
def _run_shell_command(cmd):
114
119
output = subprocess.Popen(["/bin/sh", "-c", cmd],
115
120
stdout=subprocess.PIPE)
116
return output.communicate()[0].strip()
119
def write_vcsversion(location):
120
"""Produce a vcsversion dict that mimics the old one produced by bzr.
122
if os.path.isdir('.git'):
123
branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "'
124
branch_nick = _run_shell_command(branch_nick_cmd)
125
revid_cmd = "git rev-parse HEAD"
126
revid = _run_shell_command(revid_cmd).split()[0]
127
revno_cmd = "git log --oneline | wc -l"
128
revno = _run_shell_command(revno_cmd)
129
with open(location, 'w') as version_file:
130
version_file.write("""
131
# This file is automatically generated by setup.py, So don't edit it. :)
137
""" % (branch_nick, revid, revno))
121
out = output.communicate()
124
if len(out[0].strip()) == 0:
126
return out[0].strip()
129
def _get_git_next_version_suffix(branch_name):
130
datestamp = datetime.datetime.now().strftime('%Y%m%d')
131
if branch_name == 'milestone-proposed':
135
_run_shell_command("git fetch origin +refs/meta/*:refs/remotes/meta/*")
136
milestone_cmd = "git show meta/openstack/release:%s" % branch_name
137
milestonever = _run_shell_command(milestone_cmd)
140
post_version = _get_git_post_version()
141
revno = post_version.split(".")[-1]
142
return "%s~%s.%s%s" % (milestonever, datestamp, revno_prefix, revno)
145
def _get_git_current_tag():
146
return _run_shell_command("git tag --contains HEAD")
149
def _get_git_tag_info():
150
return _run_shell_command("git describe --tags")
153
def _get_git_post_version():
154
current_tag = _get_git_current_tag()
155
if current_tag is not None:
158
tag_info = _get_git_tag_info()
161
cmd = "git --no-pager log --oneline"
162
out = _run_shell_command(cmd)
163
revno = len(out.split("\n"))
165
tag_infos = tag_info.split("-")
166
base_version = "-".join(tag_infos[:-2])
167
revno = tag_infos[-2]
168
return "%s.%s" % (base_version, revno)
140
171
def write_git_changelog():
208
def read_versioninfo(project):
209
"""Read the versioninfo file. If it doesn't exist, we're in a github
210
zipball, and there's really know way to know what version we really
211
are, but that should be ok, because the utility of that should be
212
just about nil if this code path is in use in the first place."""
213
versioninfo_path = os.path.join(project, 'versioninfo')
214
if os.path.exists(versioninfo_path):
215
with open(versioninfo_path, 'r') as vinfo:
216
version = vinfo.read().strip()
222
def write_versioninfo(project, version):
223
"""Write a simple file containing the version of the package."""
224
open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version)
177
227
def get_cmdclass():
178
228
"""Return dict of commands to run from setup.py."""
305
def get_git_branchname():
306
for branch in _run_shell_command("git branch --color=never").split("\n"):
307
if branch.startswith('*'):
308
_branch_name = branch.split()[1].strip()
309
if _branch_name == "(no":
310
_branch_name = "no-branch"
314
def get_pre_version(projectname, base_version):
315
"""Return a version which is based"""
316
if os.path.isdir('.git'):
317
current_tag = _get_git_current_tag()
318
if current_tag is not None:
319
version = current_tag
321
branch_name = os.getenv('BRANCHNAME',
322
os.getenv('GERRIT_REFNAME',
323
get_git_branchname()))
324
version_suffix = _get_git_next_version_suffix(branch_name)
325
version = "%s~%s" % (base_version, version_suffix)
326
write_versioninfo(projectname, version)
327
return version.split('~')[0]
329
version = read_versioninfo(projectname)
330
return version.split('~')[0]
333
def get_post_version(projectname):
334
"""Return a version which is equal to the tag that's on the current
335
revision if there is one, or tag plus number of additional revisions
336
if the current revision has no tag."""
338
if os.path.isdir('.git'):
339
version = _get_git_post_version()
340
write_versioninfo(projectname, version)
342
return read_versioninfo(projectname)