Skip to content

Commit

Permalink
[cfg] Upgrade to pylint 3.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bruntib committed Jul 5, 2024
1 parent 3d1a1ab commit 3abb0e9
Show file tree
Hide file tree
Showing 252 changed files with 2,659 additions and 2,238 deletions.
805 changes: 553 additions & 252 deletions .pylintrc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ PYLINT_CMD = $(MAKE) -C $(CC_ANALYZER) pylint && \
$(MAKE) -C $(CC_WEB) pylint && \
pylint -j0 ./bin/** ./codechecker_common \
./scripts/** ./scripts/build/** ./scripts/debug_tools/** \
./scripts/gerrit_jenkins/** ./scripts/resources/** \
./scripts/resources/** \
./scripts/test/** ./scripts/thrift/** \
--rcfile=$(ROOT)/.pylintrc

Expand Down
41 changes: 18 additions & 23 deletions analyzer/codechecker_analyzer/analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
"""
"""


import glob
Expand Down Expand Up @@ -116,14 +114,14 @@ def worker_result_handler(results, metadata_tool, output_path):


# Progress reporting.
progress_checked_num = None
progress_actions = None
PROGRESS_CHECKED_NUM = None
PROGRESS_ACTIONS = None


def init_worker(checked_num, action_num):
global progress_checked_num, progress_actions
progress_checked_num = checked_num
progress_actions = action_num
global PROGRESS_CHECKED_NUM, PROGRESS_ACTIONS
PROGRESS_CHECKED_NUM = checked_num
PROGRESS_ACTIONS = action_num


def save_output(base_file_name, out, err):
Expand Down Expand Up @@ -172,8 +170,7 @@ def prepare_check(action, analyzer_config, output_dir,
""" Construct the source analyzer and result handler. """
# Create a source analyzer.
source_analyzer = \
analyzer_types.construct_analyzer(action,
analyzer_config)
analyzer_types.construct_analyzer(action, analyzer_config)

if disable_ctu:
# WARNING! can be called only on ClangSA
Expand Down Expand Up @@ -334,8 +331,8 @@ def handle_failure(
# from the standard output by this postprocess phase so we can present them
# as CodeChecker reports.
checks = source_analyzer.config_handler.checks()
state = checks.get('clang-diagnostic-error', (CheckerState.enabled, ''))[0]
if state == CheckerState.enabled:
state = checks.get('clang-diagnostic-error', (CheckerState.ENABLED, ''))[0]
if state == CheckerState.ENABLED:
rh.postprocess_result(skip_handlers, rs_handler)

# Remove files that successfully analyzed earlier on.
Expand Down Expand Up @@ -507,7 +504,7 @@ def check(check_data):
result_file = ''

if analyzer_config is None:
raise Exception("Analyzer configuration is missing.")
raise ValueError("Analyzer configuration is missing.")

source_analyzer, rh = prepare_check(action, analyzer_config,
output_dir,
Expand Down Expand Up @@ -539,7 +536,7 @@ def __create_timeout(analyzer_process):
timeout_cleanup[0] = setup_process_timeout(
analyzer_process, analysis_timeout)
else:
def __create_timeout(analyzer_process):
def __create_timeout(_):
# If no timeout is given by the client, this callback
# shouldn't do anything.
pass
Expand All @@ -555,9 +552,9 @@ def __create_timeout(analyzer_process):
"of %d seconds.", analysis_timeout)
LOG.warning("Considering this analysis as failed...")
rh.analyzer_returncode = -1
rh.analyzer_stderr = (">>> CodeChecker: Analysis timed out "
"after {0} seconds. <<<\n{1}") \
.format(analysis_timeout, rh.analyzer_stderr)
rh.analyzer_stderr = \
">>> CodeChecker: Analysis timed out after " \
f"{analysis_timeout} seconds. <<<\n{rh.analyzer_stderr}"

source_analyzer.post_analyze(rh)

Expand Down Expand Up @@ -619,7 +616,7 @@ def handle_analysis_result(success, zip_file=zip_file):
if rh.analyzer_returncode == 0:
handle_analysis_result(success=True)
LOG.info("[%d/%d] %s analyzed %s successfully.",
progress_checked_num.value, progress_actions.value,
PROGRESS_CHECKED_NUM.value, PROGRESS_ACTIONS.value,
action.analyzer_type, source_file_name)

if result_file_exists:
Expand Down Expand Up @@ -660,8 +657,8 @@ def handle_analysis_result(success, zip_file=zip_file):

LOG.info("[%d/%d] %s analyzed %s without"
" CTU successfully.",
progress_checked_num.value,
progress_actions.value,
PROGRESS_CHECKED_NUM.value,
PROGRESS_ACTIONS.value,
action.analyzer_type,
source_file_name)

Expand All @@ -688,7 +685,7 @@ def handle_analysis_result(success, zip_file=zip_file):
LOG.debug_analyzer('\n%s', rh.analyzer_stdout)
LOG.debug_analyzer('\n%s', rh.analyzer_stderr)

progress_checked_num.value += 1
PROGRESS_CHECKED_NUM.value += 1

return return_codes, False, reanalyzed, action.analyzer_type, \
result_file, action.source
Expand Down Expand Up @@ -731,10 +728,8 @@ def start_workers(actions_map, actions, analyzer_config_map,
Start the workers in the process pool.
For every build action there is worker which makes the analysis.
"""
# pylint: disable=no-member multiprocess module members.

# Handle SIGINT to stop this script running.
def signal_handler(signum, frame):
def signal_handler(signum, _):
try:
pool.terminate()
pool.join()
Expand Down
8 changes: 3 additions & 5 deletions analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __has_enabled_checker(ch: AnalyzerConfigHandler):
Returns True if at least one checker is enabled in the given config
handler.
"""
return any(state == CheckerState.enabled
return any(state == CheckerState.ENABLED
for _, (state, _) in ch.checks().items())


Expand All @@ -137,8 +137,6 @@ def perform_analysis(args, skip_handlers, rs_handler: ReviewStatusHandler,
in the given analysis context for the supplied build actions.
Additionally, insert statistical information into the metadata dict.
"""
# pylint: disable=no-member multiprocess module members.

context = analyzer_context.get_context()

ctu_reanalyze_on_failure = 'ctu_reanalyze_on_failure' in args and \
Expand Down Expand Up @@ -246,8 +244,8 @@ def perform_analysis(args, skip_handlers, rs_handler: ReviewStatusHandler,
for check, data in config_map[analyzer].checks().items():
state, _ = data
metadata_info['checkers'].update({
check: state == CheckerState.enabled})
if state == CheckerState.enabled:
check: state == CheckerState.ENABLED})
if state == CheckerState.ENABLED:
enabled_checkers[analyzer].append(check)

# TODO: cppcheck may require a different environment than clang.
Expand Down
8 changes: 4 additions & 4 deletions analyzer/codechecker_analyzer/analyzer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""


# pylint: disable=no-name-in-module
# pylint: disable=deprecated-module
from distutils.spawn import find_executable
from argparse import ArgumentTypeError

Expand All @@ -20,8 +20,8 @@

from pathlib import Path

from codechecker_common import logger
from codechecker_analyzer.arg import analyzer_binary
from codechecker_common import logger
from codechecker_common.checker_labels import CheckerLabels
from codechecker_common.singleton import Singleton
from codechecker_common.util import load_json
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(self):
self.__populate_analyzers()
self.__populate_replacer()

def __parse_CC_ANALYZER_BIN(self):
def __parse_cc_analyzer_bin(self):
env_var_bins = {}
if 'CC_ANALYZER_BIN' in self.analyzer_env:
had_error = False
Expand Down Expand Up @@ -202,7 +202,7 @@ def __populate_analyzers(self):
if not analyzer_from_path:
analyzer_env = self.analyzer_env

env_var_bin = self.__parse_CC_ANALYZER_BIN()
env_var_bin = self.__parse_cc_analyzer_bin()

compiler_binaries = self.pckg_layout.get('analyzers')
for name, value in compiler_binaries.items():
Expand Down
6 changes: 3 additions & 3 deletions analyzer/codechecker_analyzer/analyzers/analyzer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def resolve_missing_binary(cls, configured_binary, environ):
"""
raise NotImplementedError("Subclasses should implement this!")

@classmethod
@abstractmethod
def get_binary_version(self, environ, details=False) -> str:
def get_binary_version(cls, environ, details=False) -> str:
"""
Return the version number of the binary that CodeChecker found, even
if its incompatible. If details is true, additional version information
Expand Down Expand Up @@ -138,7 +139,6 @@ def post_analyze(self, result_handler):
"""
Run immediately after the analyze function.
"""
pass

@staticmethod
def run_proc(command, cwd=None, proc_callback=None, env=None):
Expand All @@ -147,7 +147,7 @@ def run_proc(command, cwd=None, proc_callback=None, env=None):
and the stdout and stderr outputs of the process.
"""

def signal_handler(signum, frame):
def signal_handler(signum, _):
# Clang does not kill its child processes, so I have to.
try:
g_pid = proc.pid
Expand Down
29 changes: 11 additions & 18 deletions analyzer/codechecker_analyzer/analyzers/analyzer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,24 +209,17 @@ def check_supported_analyzers(analyzers):
return enabled_analyzers, failed_analyzers


def construct_analyzer(buildaction,
analyzer_config):
try:
analyzer_type = buildaction.analyzer_type

LOG.debug_analyzer('Constructing %s analyzer.', analyzer_type)
if analyzer_type in supported_analyzers:
analyzer = supported_analyzers[analyzer_type](analyzer_config,
buildaction)
else:
analyzer = None
LOG.error('Unsupported analyzer type: %s', analyzer_type)
return analyzer

except Exception:
# We should've detected well before this point that something is off
# with the analyzer. We can't recover here.
raise
def construct_analyzer(buildaction, analyzer_config):
analyzer_type = buildaction.analyzer_type

LOG.debug_analyzer('Constructing %s analyzer.', analyzer_type)
if analyzer_type in supported_analyzers:
analyzer = \
supported_analyzers[analyzer_type](analyzer_config, buildaction)
else:
analyzer = None
LOG.error('Unsupported analyzer type: %s', analyzer_type)
return analyzer


def build_config_handlers(args, enabled_analyzers):
Expand Down
18 changes: 9 additions & 9 deletions analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ClangSA(analyzer_base.SourceAnalyzer):
__ctu_autodetection = None

def __init__(self, cfg_handler, buildaction):
super(ClangSA, self).__init__(cfg_handler, buildaction)
super().__init__(cfg_handler, buildaction)
self.__disable_ctu = False
self.__checker_configs = []
self.__disabled_checkers = []
Expand Down Expand Up @@ -171,25 +171,25 @@ def __add_plugin_load_flags(cls, analyzer_cmd: List[str]):
analyzer_cmd.extend(["-load", plugin])

@classmethod
def get_binary_version(self, environ, details=False) -> str:
def get_binary_version(cls, environ, details=False) -> str:
# No need to LOG here, we will emit a warning later anyway.
if not self.analyzer_binary():
if not cls.analyzer_binary():
return None

if details:
version = [self.analyzer_binary(), '--version']
ver = [cls.analyzer_binary(), '--version']
else:
version = [self.analyzer_binary(), '-dumpversion']
ver = [cls.analyzer_binary(), '-dumpversion']
try:
output = subprocess.check_output(version,
output = subprocess.check_output(ver,
env=environ,
universal_newlines=True,
encoding="utf-8",
errors="ignore")
return output.strip()
except (subprocess.CalledProcessError, OSError) as oerr:
LOG.warning("Failed to get analyzer version: %s",
' '.join(version))
' '.join(ver))
LOG.warning(oerr)

return None
Expand Down Expand Up @@ -405,9 +405,9 @@ def construct_analyzer_cmd(self, result_handler):
enabled_checkers = []
for checker_name, value in config.checks().items():
state, _ = value
if state == CheckerState.enabled:
if state == CheckerState.ENABLED:
enabled_checkers.append(checker_name)
elif state == CheckerState.disabled:
elif state == CheckerState.DISABLED:
self.__disabled_checkers.append(checker_name)

if enabled_checkers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ClangSAConfigHandler(config_handler.AnalyzerConfigHandler):
"""

def __init__(self, environ):
super(ClangSAConfigHandler, self).__init__()
super().__init__()
self.ctu_dir = ''
self.ctu_on_demand = False
self.enable_z3 = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ def __init__(self, analyzer_binary, environ):
LOG.debug(
'Trying to detect CTU capability, but analyzer binary is not '
'set!')
return None
return

analyzer_version = invoke_binary_checked(
self.__analyzer_binary, ['--version'], self.environ)

if analyzer_version is False:
LOG.debug('Failed to invoke command to get Clang version!')
return None
return

version_parser = version.ClangVersionInfoParser(self.__analyzer_binary)
version_info = version_parser.parse(analyzer_version)

if not version_info:
LOG.debug('Failed to parse Clang version information!')
return None
return

self.__analyzer_version_info = version_info

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
LOG = get_logger('analyzer')


# The inheritence comes from the YAML parser, we can't solve it with less
# ancestors.
# pylint: disable=too-many-ancestors
class LLVMComatibleYamlDumper(Dumper):
def check_simple_key(self):
""" Mark every keys as simple keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def _find_arch_in_command(output):
except ValueError:
pass

return None


def get_triple_arch(action, source, config):
"""Returns the architecture part of the target triple for the given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class ClangSAResultHandler(ResultHandler):

def __init__(self, *args, **kwargs):
self.analyzer_info = AnalyzerInfo(name='clangsa')

super(ClangSAResultHandler, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def postprocess_result(
self,
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/analyzers/clangsa/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def parse(self, version_string):
"""Try to parse the version string using the predefined patterns."""
version_match = re.search(self.clang_version_pattern, version_string)
if not version_match:
return
return None

installed_dir_match = re.search(
self.clang_installed_dir_pattern, version_string)
Expand Down
Loading

0 comments on commit 3abb0e9

Please sign in to comment.