summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pbr/hooks/commands.py2
-rw-r--r--pbr/packaging.py31
-rw-r--r--pbr/tests/test_packaging.py20
3 files changed, 45 insertions, 8 deletions
diff --git a/pbr/hooks/commands.py b/pbr/hooks/commands.py
index 8e651e6..216c9a1 100644
--- a/pbr/hooks/commands.py
+++ b/pbr/hooks/commands.py
@@ -61,3 +61,5 @@ class CommandsConfig(base.BaseConfig):
# We always want non-egg install unless explicitly requested
if 'manpages' in self.pbr_config or not use_egg:
self.add_command('pbr.packaging.LocalInstall')
+ else:
+ self.add_command('pbr.packaging.InstallWithGit')
diff --git a/pbr/packaging.py b/pbr/packaging.py
index be5eb74..e444165 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -163,6 +163,20 @@ def parse_dependency_links(requirements_files=None):
return dependency_links
+class InstallWithGit(install.install):
+ """Extracts ChangeLog and AUTHORS from git then installs.
+
+ This is useful for e.g. readthedocs where the package is
+ installed and then docs built.
+ """
+
+ command_name = 'install'
+
+ def run(self):
+ _from_git(self.distribution)
+ return install.install.run(self)
+
+
class LocalInstall(install.install):
"""Runs python setup.py install in a sensible manner.
@@ -174,6 +188,7 @@ class LocalInstall(install.install):
command_name = 'install'
def run(self):
+ _from_git(self.distribution)
return du_install.install.run(self)
@@ -397,18 +412,22 @@ class LocalEggInfo(egg_info.egg_info):
self.filelist.append(entry)
+def _from_git(distribution):
+ option_dict = distribution.get_option_dict('pbr')
+ changelog = git._iter_log_oneline(option_dict=option_dict)
+ if changelog:
+ changelog = git._iter_changelog(changelog)
+ git.write_git_changelog(option_dict=option_dict, changelog=changelog)
+ git.generate_authors(option_dict=option_dict)
+
+
class LocalSDist(sdist.sdist):
"""Builds the ChangeLog and Authors files from VC first."""
command_name = 'sdist'
def run(self):
- option_dict = self.distribution.get_option_dict('pbr')
- changelog = git._iter_log_oneline(option_dict=option_dict)
- if changelog:
- changelog = git._iter_changelog(changelog)
- git.write_git_changelog(option_dict=option_dict, changelog=changelog)
- git.generate_authors(option_dict=option_dict)
+ _from_git(self.distribution)
# sdist.sdist is an old style class, can't use super()
sdist.sdist.run(self)
diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py
index c6b2e7d..24373ab 100644
--- a/pbr/tests/test_packaging.py
+++ b/pbr/tests/test_packaging.py
@@ -156,21 +156,23 @@ class TestPackagingInGitRepoWithCommit(base.BaseTestCase):
super(TestPackagingInGitRepoWithCommit, self).setUp()
repo = self.useFixture(TestRepo(self.package_dir))
repo.commit()
- self.run_setup('sdist', allow_fail=False)
def test_authors(self):
+ self.run_setup('sdist', allow_fail=False)
# One commit, something should be in the authors list
with open(os.path.join(self.package_dir, 'AUTHORS'), 'r') as f:
body = f.read()
self.assertNotEqual(body, '')
def test_changelog(self):
+ self.run_setup('sdist', allow_fail=False)
with open(os.path.join(self.package_dir, 'ChangeLog'), 'r') as f:
body = f.read()
# One commit, something should be in the ChangeLog list
self.assertNotEqual(body, '')
def test_manifest_exclude_honoured(self):
+ self.run_setup('sdist', allow_fail=False)
with open(os.path.join(
self.package_dir,
'pbr_testpackage.egg-info/SOURCES.txt'), 'r') as f:
@@ -179,6 +181,12 @@ class TestPackagingInGitRepoWithCommit(base.BaseTestCase):
body, matchers.Not(matchers.Contains('pbr_testpackage/extra.py')))
self.assertThat(body, matchers.Contains('pbr_testpackage/__init__.py'))
+ def test_install_writes_changelog(self):
+ stdout, _, _ = self.run_setup(
+ 'install', '--root', self.temp_dir + 'installed',
+ allow_fail=False)
+ self.expectThat(stdout, matchers.Contains('Generating ChangeLog'))
+
class TestPackagingInGitRepoWithoutCommit(base.BaseTestCase):
@@ -204,18 +212,26 @@ class TestPackagingInPlainDirectory(base.BaseTestCase):
def setUp(self):
super(TestPackagingInPlainDirectory, self).setUp()
- self.run_setup('sdist', allow_fail=False)
def test_authors(self):
+ self.run_setup('sdist', allow_fail=False)
# Not a git repo, no AUTHORS file created
filename = os.path.join(self.package_dir, 'AUTHORS')
self.assertFalse(os.path.exists(filename))
def test_changelog(self):
+ self.run_setup('sdist', allow_fail=False)
# Not a git repo, no ChangeLog created
filename = os.path.join(self.package_dir, 'ChangeLog')
self.assertFalse(os.path.exists(filename))
+ def test_install_no_ChangeLog(self):
+ stdout, _, _ = self.run_setup(
+ 'install', '--root', self.temp_dir + 'installed',
+ allow_fail=False)
+ self.expectThat(
+ stdout, matchers.Not(matchers.Contains('Generating ChangeLog')))
+
class TestPresenceOfGit(base.BaseTestCase):