diff options
author | Monty Taylor <mordred@inaugust.com> | 2013-04-25 15:25:38 -0400 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2013-05-03 17:28:40 -0400 |
commit | 295ca572e59850b2549a35c4ef30298f97a6b729 (patch) | |
tree | a2c59a223fbf7063af7f25fb7a34d4abf02cfec0 | |
parent | 91cd062ceefb36e8da76d9a270fa814db16a7b92 (diff) | |
download | pbr-295ca572e59850b2549a35c4ef30298f97a6b729.tar.gz |
Add config for skipping authors and changelog.
Swift does not want to autogenerate these - so allow them to configure
them off.
Change-Id: I815fcbf9ec8d20f4a1c6cb4e2fe68a2ba8d1e305
-rw-r--r-- | pbr/hooks.py | 7 | ||||
-rw-r--r-- | pbr/packaging.py | 42 | ||||
-rw-r--r-- | pbr/tests/test_setup.py | 63 |
3 files changed, 91 insertions, 21 deletions
diff --git a/pbr/hooks.py b/pbr/hooks.py index 0cc7c9c..d3d691c 100644 --- a/pbr/hooks.py +++ b/pbr/hooks.py @@ -51,9 +51,10 @@ pbr.packaging.LocalBuildLatex """ pbr_config = config.get('pbr', dict()) - if (('single-version-externally-mananged' in pbr_config and - pbr_config['single-version-externally-mananged'] in - packaging.TRUE_VALUES) or 'manpages' in pbr_config): + if (packaging.get_boolean_option(pbr_config, + 'single-version-externally-mananged', + 'SINGLE_VERSION_EXTERNALLY_MANANGED') + or 'manpages' in pbr_config): config['global']['commands'] = config['global']['commands'] + """ pbr.packaging.DistutilsInstall """ diff --git a/pbr/packaging.py b/pbr/packaging.py index 7a2cd76..bcdd9b3 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -150,11 +150,20 @@ def _get_git_directory(): return None -def write_git_changelog(git_dir=None, dest_dir=os.path.curdir): +def get_boolean_option(option_dict, option_name, env_name): + return ((option_name in option_dict + and option_dict[option_name].lower() in TRUE_VALUES) or + str(os.getenv(env_name)).lower() in TRUE_VALUES) + + +def write_git_changelog(git_dir=None, dest_dir=os.path.curdir, + option_dict=dict()): """Write a changelog based on the git changelog.""" - log.info('[pbr] Writing ChangeLog') - new_changelog = os.path.join(dest_dir, 'ChangeLog') - if not os.getenv('SKIP_WRITE_GIT_CHANGELOG'): + should_skip = get_boolean_option(option_dict, 'skip_changelog', + 'SKIP_WRITE_GIT_CHANGELOG') + if not should_skip: + log.info('[pbr] Writing ChangeLog') + new_changelog = os.path.join(dest_dir, 'ChangeLog') if git_dir is None: git_dir = _get_git_directory() if git_dir: @@ -163,18 +172,17 @@ def write_git_changelog(git_dir=None, dest_dir=os.path.curdir): mailmap = read_git_mailmap(git_dir) with open(new_changelog, "w") as changelog_file: changelog_file.write(canonicalize_emails(changelog, mailmap)) - else: - if not os.path.exists(new_changelog): - open(new_changelog, 'w').close() -def generate_authors(git_dir=None, dest_dir='.'): +def generate_authors(git_dir=None, dest_dir='.', option_dict=dict()): """Create AUTHORS file using git commits.""" - log.info('[pbr] Generating AUTHORS') - jenkins_email = 'jenkins@review' - old_authors = os.path.join(dest_dir, 'AUTHORS.in') - new_authors = os.path.join(dest_dir, 'AUTHORS') - if not os.getenv('SKIP_GENERATE_AUTHORS'): + should_skip = get_boolean_option(option_dict, 'skip_authors', + 'SKIP_GENERATE_AUTHORS') + if not should_skip: + log.info('[pbr] Generating AUTHORS') + jenkins_email = 'jenkins@review' + old_authors = os.path.join(dest_dir, 'AUTHORS.in') + new_authors = os.path.join(dest_dir, 'AUTHORS') if git_dir is None: git_dir = _get_git_directory() if git_dir: @@ -198,9 +206,6 @@ def generate_authors(git_dir=None, dest_dir='.'): if os.path.exists(old_authors): with open(old_authors, "r") as old_authors_fh: new_authors_fh.write('\n' + old_authors_fh.read()) - else: - if not os.path.exists(new_authors): - open(new_authors, 'w').close() _rst_template = """%(heading)s @@ -235,8 +240,9 @@ class LocalSDist(sdist.sdist): command_name = 'sdist' def run(self): - write_git_changelog() - generate_authors() + option_dict = self.distribution.get_option_dict('pbr') + write_git_changelog(option_dict=option_dict) + generate_authors(option_dict=option_dict) # sdist.sdist is an old style class, can't use super() sdist.sdist.run(self) diff --git a/pbr/tests/test_setup.py b/pbr/tests/test_setup.py index f2778c7..dd797ab 100644 --- a/pbr/tests/test_setup.py +++ b/pbr/tests/test_setup.py @@ -80,6 +80,65 @@ class MailmapTestCase(tests.BaseTestCase): packaging.read_git_mailmap(self.git_dir)) +class SkipFileWrites(tests.BaseTestCase): + + scenarios = [ + ('changelog_option_true', + dict(option_key='skip_changelog', option_value='True', + env_key='SKIP_WRITE_GIT_CHANGELOG', env_value=None, + pkg_func=packaging.write_git_changelog, filename='ChangeLog')), + ('changelog_option_false', + dict(option_key='skip_changelog', option_value='False', + env_key='SKIP_WRITE_GIT_CHANGELOG', env_value=None, + pkg_func=packaging.write_git_changelog, filename='ChangeLog')), + ('changelog_env_true', + dict(option_key='skip_changelog', option_value='False', + env_key='SKIP_WRITE_GIT_CHANGELOG', env_value='True', + pkg_func=packaging.write_git_changelog, filename='ChangeLog')), + ('changelog_both_true', + dict(option_key='skip_changelog', option_value='True', + env_key='SKIP_WRITE_GIT_CHANGELOG', env_value='True', + pkg_func=packaging.write_git_changelog, filename='ChangeLog')), + ('authors_option_true', + dict(option_key='skip_authors', option_value='True', + env_key='SKIP_GENERATE_AUTHORS', env_value=None, + pkg_func=packaging.generate_authors, filename='AUTHORS')), + ('authors_option_false', + dict(option_key='skip_authors', option_value='False', + env_key='SKIP_GENERATE_AUTHORS', env_value=None, + pkg_func=packaging.generate_authors, filename='AUTHORS')), + ('authors_env_true', + dict(option_key='skip_authors', option_value='False', + env_key='SKIP_GENERATE_AUTHORS', env_value='True', + pkg_func=packaging.generate_authors, filename='AUTHORS')), + ('authors_both_true', + dict(option_key='skip_authors', option_value='True', + env_key='SKIP_GENERATE_AUTHORS', env_value='True', + pkg_func=packaging.generate_authors, filename='AUTHORS')), + ] + + def setUp(self): + super(SkipFileWrites, self).setUp() + self.temp_path = self.useFixture(fixtures.TempDir()).path + self.root_dir = os.path.abspath(os.path.curdir) + self.git_dir = os.path.join(self.root_dir, ".git") + self.filename = os.path.join(self.temp_path, self.filename) + self.option_dict = dict() + if self.option_key is not None: + self.option_dict[self.option_key] = self.option_value + self.useFixture( + fixtures.EnvironmentVariable(self.env_key, self.env_value)) + + def test_skip(self): + self.pkg_func(git_dir=self.git_dir, + dest_dir=self.temp_path, + option_dict=self.option_dict) + self.assertEqual( + not os.path.exists(self.filename), + (self.option_value.lower() in packaging.TRUE_VALUES + or self.env_value is not None)) + + class GitLogsTest(tests.BaseTestCase): def setUp(self): @@ -87,6 +146,10 @@ class GitLogsTest(tests.BaseTestCase): self.temp_path = self.useFixture(fixtures.TempDir()).path self.root_dir = os.path.abspath(os.path.curdir) self.git_dir = os.path.join(self.root_dir, ".git") + self.useFixture( + fixtures.EnvironmentVariable('SKIP_GENERATE_AUTHORS')) + self.useFixture( + fixtures.EnvironmentVariable('SKIP_WRITE_GIT_CHANGELOG')) def test_write_git_changelog(self): exist_files = [os.path.join(self.root_dir, f) |