From 6f0c200fe2f0766753a63605d58247f5688c47b1 Mon Sep 17 00:00:00 2001 From: Ondřej Nosek Date: Feb 04 2025 11:49:44 +0000 Subject: `prep`: added an argument to check dependencies By default, `prep` command doesn't check dependencies. This might lead to confusing output. When `prep` fails, a hint message is displayed with information about the new argument '--check-deps' which makes `prep` potentially show missing dependencies. JIRA: RHELCMP-14322 Fixes: https://pagure.io/fedpkg/issue/585 Signed-off-by: Ondřej Nosek --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 5b77453..20e567d 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -3271,7 +3271,7 @@ class Commands(object): raise AlreadyUploadedError('File already uploaded') def prep(self, arch=None, builddir=None, buildrootdir=None, define=None, - extra_args=None): + extra_args=None, check_deps=None): """Run ``rpmbuild -bp`` :param str arch: optional to run prep section for a specific arch. By @@ -3281,6 +3281,7 @@ class Commands(object): :param str buildrootdir: an alternative buildrootdir. :param list extra_args: additional arguments that are passed to the rpmbuild command. + :param bool check_deps: check dependencies. No, by default. .. versionadded: 1.56 Parameter buildrootdir. @@ -3324,9 +3325,17 @@ class Commands(object): if buildrootdir: cmd.extend(["--define", "_buildrootdir {0}".format( os.path.abspath(buildrootdir))]) - cmd.extend(['--nodeps', '-bp', os.path.join(self.layout.specdir, self.spec)]) + if not check_deps: + cmd.append('--nodeps') + cmd.extend(['-bp', os.path.join(self.layout.specdir, self.spec)]) # Run the command - self._run_command(cmd) + try: + self._run_command(cmd) + except rpkgError: + if not check_deps: + self.log.info("Hint: the previous command didn't check dependencies. " + "This can be enabled by adding argument '--check-deps'") + raise def srpm(self, hashtype=None, define=None, builddir=None, buildrootdir=None, arch=None, extra_args=None): diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 56857fc..3d5427e 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1369,6 +1369,9 @@ class cliClient(object): help='Local test rpmbuild prep', description='Use rpmbuild to "prep" the sources (unpack the ' 'source archive(s) and apply any patches.)') + prep_parser.add_argument( + '--check-deps', action='store_true', + help='Check dependencies. Not checked by default.') prep_parser.set_defaults(command=self.prep) def register_pull(self): @@ -2880,7 +2883,8 @@ class cliClient(object): arch=self.args.arch, define=self.args.define, extra_args=self.extra_args, - buildrootdir=self.args.buildrootdir,) + buildrootdir=self.args.buildrootdir, + check_deps=self.args.check_deps,) def pull(self): self.cmd.pull(rebase=self.args.rebase, diff --git a/tests/test_cli.py b/tests/test_cli.py index 75425d4..662a471 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -788,7 +788,7 @@ class TestPrep(CliTestCase): cli_cmd = [ 'rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', - '-q', 'compile', '--arch', 'i686', '--builddir', builddir, + '-q', 'prep', '--arch', 'i686', '--builddir', builddir, '--buildrootdir', buildrootdir, '--', '-v' ] @@ -805,6 +805,21 @@ class TestPrep(CliTestCase): _run_command.assert_called_once_with(rpmbuild) @patch('pyrpkg.Commands._run_command') + def test_prep_with_checking_dependencies(self, _run_command): + cli_cmd = [ + 'rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', + 'prep', '--check-deps' + ] + + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + cli.prep() + + spec = os.path.join(cli.cmd.path, cli.cmd.spec) + rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + ['-bp', spec] + _run_command.assert_called_once_with(rpmbuild) + + @patch('pyrpkg.Commands._run_command') def test_prep_extra_args_with_space(self, _run_command): first_arg_with_space = 'first with space' second_arg_with_space = 'second with space'