From 3cdbbb70eb17adbd84806a672df6170e6108314d Mon Sep 17 00:00:00 2001 From: Athos Ribeiro Date: Feb 26 2018 03:35:36 +0000 Subject: Change default rpmlint configuration file Current rpmlint configuration file (.rpmlint) is hidden. Making the file visible may encourage packagers looking at other repositories to properly configure rpmlint runs and omit false positives. This commit makes .rpmlintrc the default configuration file and triggers a deprecation message whenever a .rpmlint file is implicitly used. Signed-off-by: Athos Ribeiro --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 74cdbfc..c9bb52d 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2184,12 +2184,18 @@ class Commands(object): if not rpms: log.warning('No rpm found') cmd = ['rpmlint'] + default_rpmlintconf = '{0}.rpmlintrc'.format(self.module_name) if info: cmd.extend(['-i']) if rpmlintconf: cmd.extend(["-f", os.path.join(self.path, rpmlintconf)]) - elif os.path.exists(os.path.join(self.path, ".rpmlint")): + elif os.path.isfile(os.path.join(self.path, default_rpmlintconf)): + cmd.extend(["-f", os.path.join(self.path, default_rpmlintconf)]) + elif os.path.isfile(os.path.join(self.path, ".rpmlint")): cmd.extend(["-f", os.path.join(self.path, ".rpmlint")]) + self.log.warning('.rpmlint file usage as default rpmlint configuration is deprecated ' + 'and will be removed in future version. ' + 'Use {0} instead'.format(default_rpmlintconf)) cmd.append(os.path.join(self.path, self.spec)) if os.path.exists(os.path.join(self.path, srpm)): cmd.append(os.path.join(self.path, srpm)) diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index b165e64..fb80b79 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -625,8 +625,8 @@ defined, packages will be built sequentially.""" % {'name': self.name}) 'lint', help='Run rpmlint against local spec and build output if ' 'present.', description='Rpmlint can be configured using the --rpmlintconf/-r' - ' option or by setting a .rpmlint file in the ' - 'working directory') + ' option or by setting a .rpmlintrc file in ' + 'the working directory') lint_parser.add_argument( '--info', '-i', default=False, action='store_true', help='Display explanations for reported messages') diff --git a/tests/test_cli.py b/tests/test_cli.py index 135b25e..f4e9ea7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -886,6 +886,60 @@ class TestLint(CliTestCase): rpmlint = ['rpmlint', '-i', os.path.join(cli.cmd.path, cli.cmd.spec)] _run_command.assert_called_once_with(rpmlint, shell=True) + @patch('pyrpkg.Commands._run_command') + def test_lint_with_default_config_file(self, _run_command): + self.checkout_branch(git.Repo(self.cloned_repo_path), 'eng-rhel-7') + + lint_config_path = os.path.join(self.cloned_repo_path, 'docpkg.rpmlintrc') + open(lint_config_path, 'a').close() + + cli_cmd = ['rpkg', '--module-name', 'docpkg', '--path', self.cloned_repo_path, 'lint'] + + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + cli.lint() + + rpmlint = ['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)] + _run_command.assert_called_once_with(rpmlint, shell=True) + + @patch('pyrpkg.Commands._run_command') + def test_lint_with_default_and_deprecated_config_files(self, _run_command): + self.checkout_branch(git.Repo(self.cloned_repo_path), 'eng-rhel-7') + + lint_config_path = os.path.join(self.cloned_repo_path, 'docpkg.rpmlintrc') + open(lint_config_path, 'a').close() + deprecated_lint_config_path = os.path.join(self.cloned_repo_path, '.rpmlint') + open(deprecated_lint_config_path, 'a').close() + + cli_cmd = ['rpkg', '--module-name', 'docpkg', '--path', self.cloned_repo_path, 'lint'] + + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + cli.lint() + + rpmlint = ['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)] + _run_command.assert_called_once_with(rpmlint, shell=True) + + @patch('pyrpkg.Commands._run_command') + def test_lint_with_custom_config_file(self, _run_command): + self.checkout_branch(git.Repo(self.cloned_repo_path), 'eng-rhel-7') + + lint_config_path = os.path.join(self.cloned_repo_path, 'docpkg.rpmlintrc') + open(lint_config_path, 'a').close() + custom_lint_config_path = os.path.join(self.cloned_repo_path, 'custom.rpmlint') + open(custom_lint_config_path, 'a').close() + + cli_cmd = ['rpkg', '--module-name', 'docpkg', '--path', self.cloned_repo_path, + 'lint', '--rpmlintconf', 'custom.rpmlint'] + + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + cli.lint() + + rpmlint = ['rpmlint', '-f', custom_lint_config_path, os.path.join(cli.cmd.path, + cli.cmd.spec)] + _run_command.assert_called_once_with(rpmlint, shell=True) + class TestGitUrl(CliTestCase):