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
This commit is contained in:
Bhuvan Arumugam 2012-05-06 20:27:26 -07:00
parent 75c7ee0ec3
commit b853a46f9e
5 changed files with 85 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
*.pyc *.pyc
*.DS_Store *.DS_Store
AUTHORS
build/* build/*
build-stamp build-stamp
quantum.egg-info/ quantum.egg-info/

View File

@ -1,4 +1,4 @@
include README LICENSE TESTING include README LICENSE TESTING AUTHORS
include run_tests.py run_tests.sh include run_tests.py run_tests.sh
include .pylintrc include .pylintrc
include openstack-common.conf include openstack-common.conf

View File

@ -31,14 +31,15 @@ def parse_mailmap(mailmap='.mailmap'):
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 = l.split(' ') canonical_email, alias = [x for x in l.split(' ') \
if x.startswith('<')]
mapping[alias] = canonical_email mapping[alias] = canonical_email
return mapping return mapping
def canonicalize_emails(changelog, mapping): def canonicalize_emails(changelog, mapping):
""" Takes in a string and an email alias mapping and replaces all """Takes in a string and an email alias mapping and replaces all
instances of the aliases in the string with their real email instances of the aliases in the string with their real email.
""" """
for alias, email in mapping.iteritems(): for alias, email in mapping.iteritems():
changelog = changelog.replace(alias, email) changelog = changelog.replace(alias, email)
@ -97,7 +98,7 @@ def _run_shell_command(cmd):
def write_vcsversion(location): 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'): if os.path.isdir('.git'):
branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "' branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "'
@ -118,10 +119,28 @@ version_info = {
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'): 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("ChangeLog", "w") as changelog_file:
changelog_file.write(canonicalize_emails(changelog, mailmap)) 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())

View File

@ -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)

View File

@ -14,6 +14,7 @@
from setuptools import setup, find_packages 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_requirements
from quantum.openstack.common.setup import parse_dependency_links from quantum.openstack.common.setup import parse_dependency_links
from quantum.openstack.common.setup import write_requirements from quantum.openstack.common.setup import write_requirements
@ -29,6 +30,7 @@ depend_links = parse_dependency_links()
write_requirements() write_requirements()
write_git_changelog() write_git_changelog()
write_vcsversion('quantum/vcsversion.py') write_vcsversion('quantum/vcsversion.py')
generate_authors()
from quantum import version from quantum import version