]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Include AUTHORS in release package.
authorBhuvan Arumugam <bhuvan@apache.org>
Mon, 7 May 2012 03:27:26 +0000 (20:27 -0700)
committerBhuvan Arumugam <bhuvan@apache.org>
Mon, 14 May 2012 21:45:56 +0000 (14:45 -0700)
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
MANIFEST.in
quantum/openstack/common/setup.py
quantum/tests/unit/test_setup.py [new file with mode: 0644]
setup.py

index 7e715b7b6bd6417973fdebefb1c4b133496f8b8a..5c7c84b0ea07f7e3f6614c6d520e4d23d182aab9 100644 (file)
@@ -1,5 +1,6 @@
 *.pyc
 *.DS_Store
+AUTHORS
 build/*
 build-stamp
 quantum.egg-info/
index 771d8ccded0ececa2f2a8b04cd710aad8427cbfa..ca45b325d79c6ec5704af81923826883f28289c3 100644 (file)
@@ -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
index 9eabfcca3f51aadcc9920ebec1820b45edb156cc..2c16b5b3525540ec8e23471bc560aea42276f990 100644 (file)
@@ -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 (file)
index 0000000..1c87738
--- /dev/null
@@ -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 <email@foo.com> Foo Bar <email@bar.com>\n")
+        self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
+                        parse_mailmap(self.mailmap))
+
+    def test_mailmap_with_firstname(self):
+        with open(self.mailmap, 'w') as mm_fh:
+            mm_fh.write("Foo <email@foo.com> Foo <email@bar.com>\n")
+        self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
+                        parse_mailmap(self.mailmap))
+
+    def test_mailmap_with_noname(self):
+        with open(self.mailmap, 'w') as mm_fh:
+            mm_fh.write("<email@foo.com> <email@bar.com>\n")
+        self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
+                        parse_mailmap(self.mailmap))
+
+    def tearDown(self):
+        if os.path.exists(self.mailmap):
+            os.remove(self.mailmap)
index d44e791f30580f03e9622b61497a79694f6c0208..409a3385167024dc07b5587252570cf23ef68735 100644 (file)
--- 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