Fixes setup compatibility issue on Windows

Fixes Bug #1052161

"python setup.py build" fails on Windows due to a hardcoded shell path:
/bin/sh

setup.py updated using openstack-common/update.py

Change-Id: Iafae444a43c76560020a84e3a1c5c8cb4b6860da
This commit is contained in:
Alessandro Pilotti
2012-11-06 19:38:28 +02:00
parent dcbebd7b78
commit 1abc0b4edf
2 changed files with 85 additions and 42 deletions

View File

@@ -31,13 +31,13 @@ from setuptools.command import sdist
def parse_mailmap(mailmap='.mailmap'): def parse_mailmap(mailmap='.mailmap'):
mapping = {} mapping = {}
if os.path.exists(mailmap): if os.path.exists(mailmap):
fp = open(mailmap, 'r') with open(mailmap, 'r') as fp:
for l in fp: for l in fp:
l = l.strip() l = l.strip()
if not l.startswith('#') and ' ' in l: if not l.startswith('#') and ' ' in l:
canonical_email, alias = [x for x in l.split(' ') canonical_email, alias = [x for x in l.split(' ')
if x.startswith('<')] if x.startswith('<')]
mapping[alias] = canonical_email mapping[alias] = canonical_email
return mapping return mapping
@@ -52,10 +52,10 @@ def canonicalize_emails(changelog, mapping):
# Get requirements from the first file that exists # Get requirements from the first file that exists
def get_reqs_from_files(requirements_files): def get_reqs_from_files(requirements_files):
reqs_in = []
for requirements_file in requirements_files: for requirements_file in requirements_files:
if os.path.exists(requirements_file): if os.path.exists(requirements_file):
return open(requirements_file, 'r').read().split('\n') with open(requirements_file, 'r') as fil:
return fil.read().split('\n')
return [] return []
@@ -117,8 +117,12 @@ def write_requirements():
def _run_shell_command(cmd): def _run_shell_command(cmd):
output = subprocess.Popen(["/bin/sh", "-c", cmd], if os.name == 'nt':
stdout=subprocess.PIPE) output = subprocess.Popen(["cmd.exe", "/C", cmd],
stdout=subprocess.PIPE)
else:
output = subprocess.Popen(["/bin/sh", "-c", cmd],
stdout=subprocess.PIPE)
out = output.communicate() out = output.communicate()
if len(out) == 0: if len(out) == 0:
return None return None
@@ -136,11 +140,19 @@ def _get_git_next_version_suffix(branch_name):
_run_shell_command("git fetch origin +refs/meta/*:refs/remotes/meta/*") _run_shell_command("git fetch origin +refs/meta/*:refs/remotes/meta/*")
milestone_cmd = "git show meta/openstack/release:%s" % branch_name milestone_cmd = "git show meta/openstack/release:%s" % branch_name
milestonever = _run_shell_command(milestone_cmd) milestonever = _run_shell_command(milestone_cmd)
if not milestonever: if milestonever:
milestonever = "" first_half = "%s~%s" % (milestonever, datestamp)
else:
first_half = datestamp
post_version = _get_git_post_version() post_version = _get_git_post_version()
revno = post_version.split(".")[-1] # post version should look like:
return "%s~%s.%s%s" % (milestonever, datestamp, revno_prefix, revno) # 0.1.1.4.gcc9e28a
# where the bit after the last . is the short sha, and the bit between
# the last and second to last is the revno count
(revno, sha) = post_version.split(".")[-2:]
second_half = "%s%s.%s" % (revno_prefix, revno, sha)
return ".".join((first_half, second_half))
def _get_git_current_tag(): def _get_git_current_tag():
@@ -162,39 +174,48 @@ def _get_git_post_version():
cmd = "git --no-pager log --oneline" cmd = "git --no-pager log --oneline"
out = _run_shell_command(cmd) out = _run_shell_command(cmd)
revno = len(out.split("\n")) revno = len(out.split("\n"))
sha = _run_shell_command("git describe --always")
else: else:
tag_infos = tag_info.split("-") tag_infos = tag_info.split("-")
base_version = "-".join(tag_infos[:-2]) base_version = "-".join(tag_infos[:-2])
revno = tag_infos[-2] (revno, sha) = tag_infos[-2:]
return "%s.%s" % (base_version, revno) return "%s.%s.%s" % (base_version, revno, sha)
def write_git_changelog(): def write_git_changelog():
"""Write a changelog based on the git changelog.""" """Write a changelog based on the git changelog."""
if os.path.isdir('.git'): new_changelog = 'ChangeLog'
git_log_cmd = 'git log --stat' if not os.getenv('SKIP_WRITE_GIT_CHANGELOG'):
changelog = _run_shell_command(git_log_cmd) if os.path.isdir('.git'):
mailmap = parse_mailmap() git_log_cmd = 'git log --stat'
with open("ChangeLog", "w") as changelog_file: changelog = _run_shell_command(git_log_cmd)
changelog_file.write(canonicalize_emails(changelog, mailmap)) mailmap = parse_mailmap()
with open(new_changelog, "w") as changelog_file:
changelog_file.write(canonicalize_emails(changelog, mailmap))
else:
open(new_changelog, 'w').close()
def generate_authors(): def generate_authors():
"""Create AUTHORS file using git commits.""" """Create AUTHORS file using git commits."""
jenkins_email = 'jenkins@review.openstack.org' jenkins_email = 'jenkins@review.(openstack|stackforge).org'
old_authors = 'AUTHORS.in' old_authors = 'AUTHORS.in'
new_authors = 'AUTHORS' new_authors = 'AUTHORS'
if os.path.isdir('.git'): if not os.getenv('SKIP_GENERATE_AUTHORS'):
# don't include jenkins email address in AUTHORS file if os.path.isdir('.git'):
git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | " # don't include jenkins email address in AUTHORS file
"grep -v " + jenkins_email) git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
changelog = _run_shell_command(git_log_cmd) "egrep -v '" + jenkins_email + "'")
mailmap = parse_mailmap() changelog = _run_shell_command(git_log_cmd)
with open(new_authors, 'w') as new_authors_fh: mailmap = parse_mailmap()
new_authors_fh.write(canonicalize_emails(changelog, mailmap)) with open(new_authors, 'w') as new_authors_fh:
if os.path.exists(old_authors): new_authors_fh.write(canonicalize_emails(changelog, mailmap))
with open(old_authors, "r") as old_authors_fh: if os.path.exists(old_authors):
new_authors_fh.write('\n' + old_authors_fh.read()) with open(old_authors, "r") as old_authors_fh:
new_authors_fh.write('\n' + old_authors_fh.read())
else:
open(new_authors, 'w').close()
_rst_template = """%(heading)s _rst_template = """%(heading)s
%(underline)s %(underline)s
@@ -206,9 +227,24 @@ _rst_template = """%(heading)s
""" """
def read_versioninfo(project):
"""Read the versioninfo file. If it doesn't exist, we're in a github
zipball, and there's really no way to know what version we really
are, but that should be ok, because the utility of that should be
just about nil if this code path is in use in the first place."""
versioninfo_path = os.path.join(project, 'versioninfo')
if os.path.exists(versioninfo_path):
with open(versioninfo_path, 'r') as vinfo:
version = vinfo.read().strip()
else:
version = "0.0.0"
return version
def write_versioninfo(project, version): def write_versioninfo(project, version):
"""Write a simple file containing the version of the package.""" """Write a simple file containing the version of the package."""
open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version) with open(os.path.join(project, 'versioninfo'), 'w') as fil:
fil.write("%s\n" % version)
def get_cmdclass(): def get_cmdclass():
@@ -299,7 +335,8 @@ def get_git_branchname():
def get_pre_version(projectname, base_version): def get_pre_version(projectname, base_version):
"""Return a version which is based""" """Return a version which is leading up to a version that will
be released in the future."""
if os.path.isdir('.git'): if os.path.isdir('.git'):
current_tag = _get_git_current_tag() current_tag = _get_git_current_tag()
if current_tag is not None: if current_tag is not None:
@@ -311,11 +348,10 @@ def get_pre_version(projectname, base_version):
version_suffix = _get_git_next_version_suffix(branch_name) version_suffix = _get_git_next_version_suffix(branch_name)
version = "%s~%s" % (base_version, version_suffix) version = "%s~%s" % (base_version, version_suffix)
write_versioninfo(projectname, version) write_versioninfo(projectname, version)
return version.split('~')[0] return version
else: else:
with open(os.path.join(projectname, 'versioninfo'), 'r') as vinfo: version = read_versioninfo(projectname)
full_version = vinfo.read().strip() return version
return full_version.split('~')[0]
def get_post_version(projectname): def get_post_version(projectname):
@@ -327,4 +363,4 @@ def get_post_version(projectname):
version = _get_git_post_version() version = _get_git_post_version()
write_versioninfo(projectname, version) write_versioninfo(projectname, version)
return version return version
return open(os.path.join(projectname, 'versioninfo'), 'r').read().strip() return read_versioninfo(projectname)

7
openstack-common.conf Normal file
View File

@@ -0,0 +1,7 @@
[DEFAULT]
# The list of modules to copy from openstack-common
modules=setup
# The base module to hold the copy of openstack.common
base=cinderclient