From 50c02660b2ce5fd48798e68ec41fc9962c741537 Mon Sep 17 00:00:00 2001 From: Bhuvan Arumugam Date: Sun, 6 May 2012 20:27:26 -0700 Subject: [PATCH] Include AUTHORS in release package. Fixes Bug #976267. Include AUTHORS file in release package. The file is generated automatically from git. Handle different combination for mailmap records. Include test case to verify this fix. * MANIFEST.in Include AUTHORS file in release package. * .gitignore Add AUTHORS file. * quantum/openstack/common/setup.py generate_authors(): New method to create AUTHORS file. If AUTHORS.in file exists, append it's content to AUTHORS file. parse_mailmap(): Handle all mailmap combination while parsing. * setup.py Import the new method. Generate AUTHORS file before creating the package. * quantum/tests/unit/test_setup.py New test script to verify different combination of records in mailmap file. Change-Id: I220e8a20c96d37df3fa2ba0424e8372496e67895 --- .gitignore | 1 + MANIFEST.in | 2 +- quantum/openstack/common/setup.py | 29 +++++++++++++--- quantum/tests/unit/test_setup.py | 57 +++++++++++++++++++++++++++++++ setup.py | 2 ++ 5 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 quantum/tests/unit/test_setup.py diff --git a/.gitignore b/.gitignore index 7e715b7b6..5c7c84b0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.pyc *.DS_Store +AUTHORS build/* build-stamp quantum.egg-info/ diff --git a/MANIFEST.in b/MANIFEST.in index 771d8ccde..ca45b325d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include README LICENSE TESTING +include README LICENSE TESTING AUTHORS include run_tests.py run_tests.sh include .pylintrc include openstack-common.conf diff --git a/quantum/openstack/common/setup.py b/quantum/openstack/common/setup.py index 9eabfcca3..2c16b5b35 100644 --- a/quantum/openstack/common/setup.py +++ b/quantum/openstack/common/setup.py @@ -31,14 +31,15 @@ def parse_mailmap(mailmap='.mailmap'): for l in fp: l = l.strip() if not l.startswith('#') and ' ' in l: - canonical_email, alias = l.split(' ') + canonical_email, alias = [x for x in l.split(' ') \ + if x.startswith('<')] mapping[alias] = canonical_email return mapping def canonicalize_emails(changelog, mapping): - """ Takes in a string and an email alias mapping and replaces all - instances of the aliases in the string with their real email + """Takes in a string and an email alias mapping and replaces all + instances of the aliases in the string with their real email. """ for alias, email in mapping.iteritems(): changelog = changelog.replace(alias, email) @@ -97,7 +98,7 @@ def _run_shell_command(cmd): def write_vcsversion(location): - """ Produce a vcsversion dict that mimics the old one produced by bzr + """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" "' @@ -118,10 +119,28 @@ version_info = { 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'): git_log_cmd = 'git log --stat' changelog = _run_shell_command(git_log_cmd) mailmap = parse_mailmap() with open("ChangeLog", "w") as changelog_file: changelog_file.write(canonicalize_emails(changelog, mailmap)) + + +def generate_authors(): + """Create AUTHORS file using git commits.""" + jenkins_email = 'jenkins@review.openstack.org' + old_authors = 'AUTHORS.in' + new_authors = 'AUTHORS' + if os.path.isdir('.git'): + # don't include jenkins email address in AUTHORS file + git_log_cmd = "git log --format='%aN <%aE>' | sort -u | " \ + "grep -v " + jenkins_email + changelog = _run_shell_command(git_log_cmd) + mailmap = parse_mailmap() + with open(new_authors, 'w') as new_authors_fh: + new_authors_fh.write(canonicalize_emails(changelog, mailmap)) + if os.path.exists(old_authors): + with open(old_authors, "r") as old_authors_fh: + new_authors_fh.write('\n' + old_authors_fh.read()) diff --git a/quantum/tests/unit/test_setup.py b/quantum/tests/unit/test_setup.py new file mode 100644 index 000000000..1c8773891 --- /dev/null +++ b/quantum/tests/unit/test_setup.py @@ -0,0 +1,57 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +from tempfile import mkstemp +import unittest + +from quantum.openstack.common.setup import canonicalize_emails +from quantum.openstack.common.setup import parse_mailmap + + +class SetupTest(unittest.TestCase): + + def setUp(self): + (fd, self.mailmap) = mkstemp(prefix='openstack', suffix='.mailmap') + + def test_str_dict_replace(self): + string = 'Johnnie T. Hozer' + mapping = {'T.': 'The'} + self.assertEqual('Johnnie The Hozer', + canonicalize_emails(string, mapping)) + + def test_mailmap_with_fullname(self): + with open(self.mailmap, 'w') as mm_fh: + mm_fh.write("Foo Bar Foo Bar \n") + self.assertEqual({'': ''}, + parse_mailmap(self.mailmap)) + + def test_mailmap_with_firstname(self): + with open(self.mailmap, 'w') as mm_fh: + mm_fh.write("Foo Foo \n") + self.assertEqual({'': ''}, + parse_mailmap(self.mailmap)) + + def test_mailmap_with_noname(self): + with open(self.mailmap, 'w') as mm_fh: + mm_fh.write(" \n") + self.assertEqual({'': ''}, + parse_mailmap(self.mailmap)) + + def tearDown(self): + if os.path.exists(self.mailmap): + os.remove(self.mailmap) diff --git a/setup.py b/setup.py index d44e791f3..409a33851 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ from setuptools import setup, find_packages +from quantum.openstack.common.setup import generate_authors from quantum.openstack.common.setup import parse_requirements from quantum.openstack.common.setup import parse_dependency_links from quantum.openstack.common.setup import write_requirements @@ -29,6 +30,7 @@ depend_links = parse_dependency_links() write_requirements() write_git_changelog() write_vcsversion('quantum/vcsversion.py') +generate_authors() from quantum import version -- 2.45.2