summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pbr/packaging.py46
-rw-r--r--pbr/tests/test_setup.py13
2 files changed, 24 insertions, 35 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py
index 1c6d452..526b5c3 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -79,41 +79,29 @@ def _make_links_args(links):
return ["-f '%s'" % link for link in links]
-def _missing_requires(requires):
- """Return the list of requirements that are not already installed.
-
- Do this check explicitly, because it's very easy to see if a package
- is in the current working set, to avoid shelling out to pip and attempting
- an install. pip will do the right thing, but we don't need to do the
- excess work on everyone's machines all the time (especially since tox
- likes re-installing things a lot)
- """
- return [r for r in requires
- if not pkg_resources.working_set.find(
- pkg_resources.Requirement.parse(r))]
-
-
def _pip_install(links, requires, root=None):
if str(os.getenv('SKIP_PIP_INSTALL', '')).lower() in TRUE_VALUES:
return
root_cmd = ""
if root:
root_cmd = "--root=%s" % root
- missing_requires = _missing_requires(requires)
- if missing_requires:
- _run_shell_command(
- "%s -m pip.__init__ install %s %s %s" % (
- sys.executable,
- root_cmd,
- " ".join(links),
- " ".join(_wrap_in_quotes(missing_requires))),
- throw_on_error=True, buffer=False)
-
-
-def read_git_mailmap(git_dir, mailmap='.mailmap'):
- mailmap = os.path.join(git_dir, mailmap)
+ _run_shell_command(
+ "%s -m pip.__init__ install %s %s %s" % (
+ sys.executable,
+ root_cmd,
+ " ".join(links),
+ " ".join(_wrap_in_quotes(requires))),
+ throw_on_error=True, buffer=False)
+
+
+def read_git_mailmap(root_dir=None, mailmap='.mailmap'):
+ if not root_dir:
+ root_dir = _run_shell_command('git rev-parse --show-toplevel')
+
+ mailmap = os.path.join(root_dir, mailmap)
if os.path.exists(mailmap):
return _parse_mailmap(open(mailmap, 'r').readlines())
+
return dict()
@@ -257,7 +245,7 @@ def write_git_changelog(git_dir=None, dest_dir=os.path.curdir,
if git_dir:
git_log_cmd = 'git --git-dir=%s log' % git_dir
changelog = _run_shell_command(git_log_cmd)
- mailmap = read_git_mailmap(git_dir)
+ mailmap = read_git_mailmap()
with open(new_changelog, "wb") as changelog_file:
changelog_file.write(canonicalize_emails(
changelog, mailmap).encode('utf-8'))
@@ -293,7 +281,7 @@ def generate_authors(git_dir=None, dest_dir='.', option_dict=dict()):
for signed in signed_entries.split("\n") if signed])
changelog = "\n".join((changelog, new_entries))
- mailmap = read_git_mailmap(git_dir)
+ mailmap = read_git_mailmap()
with open(new_authors, 'wb') as new_authors_fh:
if os.path.exists(old_authors):
with open(old_authors, "rb") as old_authors_fh:
diff --git a/pbr/tests/test_setup.py b/pbr/tests/test_setup.py
index 398c503..11f9a04 100644
--- a/pbr/tests/test_setup.py
+++ b/pbr/tests/test_setup.py
@@ -49,27 +49,26 @@ class MailmapTestCase(tests.BaseTestCase):
def setUp(self):
super(MailmapTestCase, self).setUp()
- self.git_dir = self.useFixture(fixtures.TempDir()).path
- self.mailmap = os.path.join(self.git_dir, '.mailmap')
+ self.root_dir = self.useFixture(fixtures.TempDir()).path
+ self.mailmap = os.path.join(self.root_dir, '.mailmap')
def test_mailmap_with_fullname(self):
- print(self.mailmap, self.git_dir)
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>'},
- packaging.read_git_mailmap(self.git_dir))
+ packaging.read_git_mailmap(self.root_dir))
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>'},
- packaging.read_git_mailmap(self.git_dir))
+ packaging.read_git_mailmap(self.root_dir))
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>'},
- packaging.read_git_mailmap(self.git_dir))
+ packaging.read_git_mailmap(self.root_dir))
class SkipFileWrites(tests.BaseTestCase):
@@ -185,9 +184,11 @@ class GitLogsTest(tests.BaseTestCase):
git_log_cmd = ("git --git-dir=%s log --format" % self.git_dir)
git_co_log_cmd = ("git log --git-dir=%s" % self.git_dir)
+ git_top_level = "git rev-parse --show-toplevel"
cmd_map = {
git_log_cmd: author_new,
git_co_log_cmd: co_author_by,
+ git_top_level: self.root_dir,
}
exist_files = [self.git_dir,