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: If0ae835aeada8769e46dddf4f3c2f2edfdfbc5fe
This commit is contained in:
@@ -31,7 +31,7 @@ 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:
|
||||||
@@ -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,6 +117,10 @@ def write_requirements():
|
|||||||
|
|
||||||
|
|
||||||
def _run_shell_command(cmd):
|
def _run_shell_command(cmd):
|
||||||
|
if os.name == 'nt':
|
||||||
|
output = subprocess.Popen(["cmd.exe", "/C", cmd],
|
||||||
|
stdout=subprocess.PIPE)
|
||||||
|
else:
|
||||||
output = subprocess.Popen(["/bin/sh", "-c", cmd],
|
output = subprocess.Popen(["/bin/sh", "-c", cmd],
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
out = output.communicate()
|
out = output.communicate()
|
||||||
@@ -127,13 +131,6 @@ def _run_shell_command(cmd):
|
|||||||
return out[0].strip()
|
return out[0].strip()
|
||||||
|
|
||||||
|
|
||||||
def _get_git_branch_name():
|
|
||||||
branch_ref = _run_shell_command("git symbolic-ref -q HEAD")
|
|
||||||
if branch_ref is None:
|
|
||||||
return "HEAD"
|
|
||||||
return branch_ref[len("refs/heads/"):]
|
|
||||||
|
|
||||||
|
|
||||||
def _get_git_next_version_suffix(branch_name):
|
def _get_git_next_version_suffix(branch_name):
|
||||||
datestamp = datetime.datetime.now().strftime('%Y%m%d')
|
datestamp = datetime.datetime.now().strftime('%Y%m%d')
|
||||||
if branch_name == 'milestone-proposed':
|
if branch_name == 'milestone-proposed':
|
||||||
@@ -143,16 +140,18 @@ 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 = branch_name
|
first_half = "%s~%s" % (milestonever, datestamp)
|
||||||
|
else:
|
||||||
|
first_half = datestamp
|
||||||
|
|
||||||
post_version = _get_git_post_version()
|
post_version = _get_git_post_version()
|
||||||
# post version should look like:
|
# post version should look like:
|
||||||
# 0.1.1.4.cc9e28a
|
# 0.1.1.4.gcc9e28a
|
||||||
# where the bit after the last . is the short sha, and the bit between
|
# where the bit after the last . is the short sha, and the bit between
|
||||||
# the last and second to last is the revno count
|
# the last and second to last is the revno count
|
||||||
(revno, sha) = post_version.split(".")[-2:]
|
(revno, sha) = post_version.split(".")[-2:]
|
||||||
first_half = "%(milestonever)s~%(datestamp)s" % locals()
|
second_half = "%s%s.%s" % (revno_prefix, revno, sha)
|
||||||
second_half = "%(revno_prefix)s%(revno)s.%(sha)s" % locals()
|
|
||||||
return ".".join((first_half, second_half))
|
return ".".join((first_half, second_half))
|
||||||
|
|
||||||
|
|
||||||
@@ -180,30 +179,33 @@ def _get_git_post_version():
|
|||||||
tag_infos = tag_info.split("-")
|
tag_infos = tag_info.split("-")
|
||||||
base_version = "-".join(tag_infos[:-2])
|
base_version = "-".join(tag_infos[:-2])
|
||||||
(revno, sha) = tag_infos[-2:]
|
(revno, sha) = tag_infos[-2:]
|
||||||
# git describe prefixes the sha with a g
|
|
||||||
sha = sha[1:]
|
|
||||||
return "%s.%s.%s" % (base_version, revno, sha)
|
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."""
|
||||||
|
new_changelog = 'ChangeLog'
|
||||||
|
if not os.getenv('SKIP_WRITE_GIT_CHANGELOG'):
|
||||||
if os.path.isdir('.git'):
|
if os.path.isdir('.git'):
|
||||||
git_log_cmd = 'git log --stat'
|
git_log_cmd = 'git log --stat'
|
||||||
changelog = _run_shell_command(git_log_cmd)
|
changelog = _run_shell_command(git_log_cmd)
|
||||||
mailmap = parse_mailmap()
|
mailmap = parse_mailmap()
|
||||||
with open("ChangeLog", "w") as changelog_file:
|
with open(new_changelog, "w") as changelog_file:
|
||||||
changelog_file.write(canonicalize_emails(changelog, mailmap))
|
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 not os.getenv('SKIP_GENERATE_AUTHORS'):
|
||||||
if os.path.isdir('.git'):
|
if os.path.isdir('.git'):
|
||||||
# don't include jenkins email address in AUTHORS file
|
# don't include jenkins email address in AUTHORS file
|
||||||
git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
|
git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
|
||||||
"grep -v " + jenkins_email)
|
"egrep -v '" + jenkins_email + "'")
|
||||||
changelog = _run_shell_command(git_log_cmd)
|
changelog = _run_shell_command(git_log_cmd)
|
||||||
mailmap = parse_mailmap()
|
mailmap = parse_mailmap()
|
||||||
with open(new_authors, 'w') as new_authors_fh:
|
with open(new_authors, 'w') as new_authors_fh:
|
||||||
@@ -211,6 +213,9 @@ def generate_authors():
|
|||||||
if os.path.exists(old_authors):
|
if os.path.exists(old_authors):
|
||||||
with open(old_authors, "r") as old_authors_fh:
|
with open(old_authors, "r") as old_authors_fh:
|
||||||
new_authors_fh.write('\n' + old_authors_fh.read())
|
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
|
||||||
@@ -238,7 +243,8 @@ def read_versioninfo(project):
|
|||||||
|
|
||||||
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():
|
||||||
@@ -319,6 +325,15 @@ def get_cmdclass():
|
|||||||
return cmdclass
|
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):
|
def get_pre_version(projectname, base_version):
|
||||||
"""Return a version which is leading up to a version that will
|
"""Return a version which is leading up to a version that will
|
||||||
be released in the future."""
|
be released in the future."""
|
||||||
@@ -329,7 +344,7 @@ def get_pre_version(projectname, base_version):
|
|||||||
else:
|
else:
|
||||||
branch_name = os.getenv('BRANCHNAME',
|
branch_name = os.getenv('BRANCHNAME',
|
||||||
os.getenv('GERRIT_REFNAME',
|
os.getenv('GERRIT_REFNAME',
|
||||||
_get_git_branch_name()))
|
get_git_branchname()))
|
||||||
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)
|
||||||
|
@@ -20,7 +20,6 @@ Utilities for consuming the auto-generated versioninfo files.
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import os
|
|
||||||
|
|
||||||
import setup
|
import setup
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user