From f8c67e415b29635267edbd1c12ef4d107dd186b1 Mon Sep 17 00:00:00 2001 From: Ondřej Nosek Date: Feb 17 2026 23:23:27 +0000 Subject: Various code linter issues fixed Claude code suggested some minor improvements; some of them were accepted. Regarding not using '%' operator in the log call - it happens before checking the log level, thus wasting CPU cycles even when debug logging is disabled. Signed-off-by: Ondřej Nosek --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 6f4d63b..359c09b 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -860,13 +860,13 @@ class Commands(object): try: # 'copyin' copies specfile into mock's root directory to be accessible for the rpm cmd - self.log.debug('Running "copyin" command: %s' % ' '.join(copyin_cmd)) + self.log.debug('Running "copyin" command: %s', ' '.join(copyin_cmd)) self._run_command(copyin_cmd) # the main command runs 'rpm' and its output redirects into the file - self.log.debug('Running "rpm" command: %s' % ' '.join(main_cmd)) + self.log.debug('Running "rpm" command: %s', ' '.join(main_cmd)) self._run_command(main_cmd) # 'copyout' copies result outside of mock's root directory to be parsed later - self.log.debug('Running "copyout" command: %s' % ' '.join(copyout_cmd)) + self.log.debug('Running "copyout" command: %s', ' '.join(copyout_cmd)) self._run_command(copyout_cmd) with open(os.path.join(tmp_resultdir, 'output'), 'r') as f: output = f.read() @@ -1820,7 +1820,7 @@ class Commands(object): # prepare ".git/info" directory if it is missing os.makedirs(os.path.dirname(git_excludes_path)) git_excludes.write() - self.log.debug('Git-excludes patterns were added into %s' % git_excludes_path) + self.log.debug('Git-excludes patterns were added into %s', git_excludes_path) def _add_git_pre_push_hook(self, repo_dir, config_path=None): """ @@ -1877,7 +1877,7 @@ class Commands(object): # set script's permissions as executable file_stat = os.stat(git_pre_push_hook_path) os.chmod(git_pre_push_hook_path, file_stat.st_mode | stat.S_IEXEC) - self.log.debug('Pre-push hook script was added into %s' % git_pre_push_hook_path) + self.log.debug('Pre-push hook script was added into %s', git_pre_push_hook_path) def commit(self, message=None, file=None, files=[], signoff=False): """Commit changes to a repository (optionally found at path) @@ -2326,7 +2326,7 @@ class Commands(object): # message in the common failure case of custom branch name. self.rpmdefines except Exception as err: - self.log.warning("Parsing specfile for used sources failed: %s" % err) + self.log.warning("Parsing specfile for used sources failed: %s", err) self.log.warning("Falling back to downloading all sources.") spec_parsed = False else: @@ -2357,7 +2357,7 @@ class Commands(object): "Either remove the corresponding line from 'sources' file to keep the git " "tracked one or 'git rm' the file to allow the download.".format(outfile)) if not force and spec_parsed and entry.file not in specf.sources: - self.log.info("Not downloading unused %s" % entry.file) + self.log.info("Not downloading unused %s", entry.file) continue self.lookasidecache.download( self.ns_repo_name if self.lookaside_namespaced else self.repo_name, @@ -4573,7 +4573,7 @@ class Commands(object): def pre_push_check(self, ref): show_hint = ('Hint: this check (.git/hooks/pre-push script) can be bypassed by adding ' - 'the argument \'--no-verify\' argument to the push command.') + 'the argument \'--no-verify\' to the push command.') try: commit = self.repo.commit(ref) except Exception: @@ -4654,7 +4654,7 @@ class Commands(object): # file path could rarely be in format './0001-my-fix.patch' - normalize it source_files.append(os.path.normpath(file_location)) - if not len(source_files): + if not source_files: self.log.warning('No source files found in the specfile \'{0}\'. ' 'Push operation continues.'.format(specfile_path)) diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 160baff..6e071d3 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -2245,7 +2245,7 @@ class cliClient(object): try: skip_hooks = self.config.getboolean(self.name, "skip_hooks") except ValueError: - self.log.error("Error: config file option 'skip_hooks'") + self.log.error("Error: config file option 'skip_hooks' must be a boolean value.") raise if self.args.branches: self.cmd.clone_with_dirs(self.args.repo[0], @@ -3189,7 +3189,7 @@ class cliClient(object): val = self.config.get(self.name, 'lookaside_attempts') try: val = int(val) - except Exception: + except ValueError: self.log.error("Error: The config value 'lookaside_attempts' " "should be an integer.") val = None @@ -3204,13 +3204,13 @@ class cliClient(object): val = self.config.get(self.name, 'lookaside_delay') try: val = int(val) - except Exception: + except ValueError: self.log.error("Error: The config value 'lookaside_delay' " "should be an integer.") val = None return val - # this method have to be specified in a derived class + # this method has to be specified in a derived class def _check_token(self, token, token_type): raise rpkgError('Undefined method for checking the token.')