Skip to content

Commit

Permalink
Merge pull request #4286 from EinarArnason/master
Browse files Browse the repository at this point in the history
Deprecate distutils
  • Loading branch information
bruntib authored Jul 15, 2024
2 parents 83bc366 + 039aa60 commit b049040
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 40 deletions.
9 changes: 4 additions & 5 deletions analyzer/codechecker_analyzer/analyzer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"""


# pylint: disable=deprecated-module
from distutils.spawn import find_executable
from shutil import which
from argparse import ArgumentTypeError

import os
Expand Down Expand Up @@ -104,7 +103,7 @@ def __parse_cc_analyzer_bin(self):
had_error = True
continue

resolved_path = find_executable(path)
resolved_path = which(path)

if not os.path.isfile(resolved_path):
LOG.error(f"'{path}' is not a path to an analyzer binary "
Expand Down Expand Up @@ -219,7 +218,7 @@ def __populate_analyzers(self):
self._data_files_dir_path, value)
else:
env_path = analyzer_env['PATH'] if analyzer_env else None
compiler_binary = find_executable(value, env_path)
compiler_binary = which(cmd=value, path=env_path)
if not compiler_binary:
LOG.debug("'%s' binary can not be found in your PATH!",
value)
Expand All @@ -242,7 +241,7 @@ def __populate_replacer(self):
self.__replacer = os.path.join(self._data_files_dir_path,
replacer_binary)
else:
self.__replacer = find_executable(replacer_binary)
self.__replacer = which(replacer_binary)

@property
def version(self):
Expand Down
6 changes: 2 additions & 4 deletions analyzer/codechecker_analyzer/analyzers/cppcheck/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"""

from collections import defaultdict
# TODO distutils will be removed in python3.12
# pylint: disable=deprecated-module
from distutils.version import StrictVersion
from packaging.version import Version
from pathlib import Path
import os
import pickle
Expand Down Expand Up @@ -347,7 +345,7 @@ def is_binary_version_incompatible(cls, environ):

# The analyzer version should be above 1.80 because '--plist-output'
# argument was introduced in this release.
if StrictVersion(analyzer_version) >= StrictVersion("1.80"):
if Version(analyzer_version) >= Version("1.80"):
return None

return "CppCheck binary found is too old at " \
Expand Down
6 changes: 2 additions & 4 deletions analyzer/codechecker_analyzer/analyzers/gcc/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#
# -------------------------------------------------------------------------
from collections import defaultdict
# TODO distutils will be removed in python3.12
# pylint: disable=deprecated-module
from distutils.version import StrictVersion
from packaging.version import Version
import os
import pickle
import shlex
Expand Down Expand Up @@ -201,7 +199,7 @@ def is_binary_version_incompatible(cls, environ):
# The analyzer version should be above 13.0.0 because the
# '-fdiagnostics-format=sarif-file' argument was introduced in this
# release.
if analyzer_version >= StrictVersion("13.0.0"):
if Version(analyzer_version) >= Version("13.0.0"):
return None

return f"GCC binary found is too old at v{analyzer_version.strip()}; "\
Expand Down
5 changes: 2 additions & 3 deletions analyzer/codechecker_analyzer/buildlog/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


from collections import namedtuple
# pylint: disable=deprecated-module
from distutils.spawn import find_executable
from shutil import which
from enum import Enum
from pathlib import Path

Expand Down Expand Up @@ -342,7 +341,7 @@ def cpp():
def is_executable_compiler(compiler):
if compiler not in ImplicitCompilerInfo.compiler_isexecutable:
ImplicitCompilerInfo.compiler_isexecutable[compiler] = \
find_executable(compiler) is not None
which(compiler) is not None

return ImplicitCompilerInfo.compiler_isexecutable[compiler]

Expand Down
1 change: 1 addition & 0 deletions analyzer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ PyYAML==6.0.1
types-PyYAML==6.0.12.12
sarif-tools==1.0.0
multiprocess==0.70.15
setuptools==70.2.0
11 changes: 5 additions & 6 deletions analyzer/tests/functional/fixit/test_fixit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import time
import unittest

# pylint: disable=deprecated-module
from distutils.spawn import find_executable
from shutil import which

from libtest import env

Expand Down Expand Up @@ -71,7 +70,7 @@ def teardown_method(self, _):
if os.path.isdir(self.report_dir):
shutil.rmtree(self.report_dir)

@unittest.skipIf(find_executable('clang-apply-replacements') is None,
@unittest.skipIf(which('clang-apply-replacements') is None,
"clang-apply-replacements clang tool must be available "
"in the environment.")
def test_fixit_list(self):
Expand Down Expand Up @@ -167,7 +166,7 @@ def test_fixit_list(self):
self.assertIn("v.empty()", new_source_file)
self.assertNotIn("v.size()", new_source_file)

@unittest.skipIf(find_executable('clang-apply-replacements') is None,
@unittest.skipIf(which('clang-apply-replacements') is None,
"clang-apply-replacements clang tool must be available "
"in the environment.")
def test_fixit_file_modification(self):
Expand Down Expand Up @@ -255,7 +254,7 @@ def test_fixit_file_modification(self):
self.assertIn('Skipped files due to modification since last analysis',
err)

@unittest.skipIf(find_executable('clang-apply-replacements') is None,
@unittest.skipIf(which('clang-apply-replacements') is None,
"clang-apply-replacements clang tool must be available "
"in the environment.")
def test_fixit_by_diff(self):
Expand Down Expand Up @@ -353,7 +352,7 @@ def test_fixit_by_diff(self):
print('\n' + out + '\n')
self.assertEqual(out.count("DiagnosticMessage"), 1)

@unittest.skipIf(find_executable('clang-apply-replacements') is None,
@unittest.skipIf(which('clang-apply-replacements') is None,
"clang-apply-replacements clang tool must be available "
"in the environment.")
def test_fixit_apply_failure(self):
Expand Down
8 changes: 4 additions & 4 deletions analyzer/tests/functional/z3/test_z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
""" Z3 feature test. """


# pylint: disable=deprecated-module
from distutils import util
from codechecker_common.util import strtobool
import os
import shutil
import unittest
Expand Down Expand Up @@ -117,8 +116,9 @@ def setup_method(self, _):

if not self.z3_capable:
try:
self.z3_capable = bool(util.strtobool(
os.environ['CC_TEST_FORCE_Z3_CAPABLE']))
self.z3_capable = strtobool(
os.environ['CC_TEST_FORCE_Z3_CAPABLE']
)
except (ValueError, KeyError):
pass

Expand Down
6 changes: 2 additions & 4 deletions analyzer/tests/libtest/codechecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import shlex
import subprocess

# pylint: disable=deprecated-module
from distutils import util
from codechecker_common.util import strtobool

from codechecker_analyzer import host_check

Expand Down Expand Up @@ -137,8 +136,7 @@ def check_force_ctu_capable(is_capable):
"""
if not is_capable:
try:
return bool(util.strtobool(
os.environ['CC_TEST_FORCE_CTU_CAPABLE']))
return strtobool(os.environ['CC_TEST_FORCE_CTU_CAPABLE'])
except (ValueError, KeyError):
pass

Expand Down
8 changes: 4 additions & 4 deletions analyzer/tests/unit/test_checker_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"""


# pylint: disable=deprecated-module
from distutils import util
from codechecker_common.util import strtobool
import os
import re
import tempfile
Expand Down Expand Up @@ -260,8 +259,9 @@ def f(checks, checkers):

# Test if statisticsbased checkers are enabled by --stats flag
# by default.
stats_capable = bool(util.strtobool(
os.environ.get('CC_TEST_FORCE_STATS_CAPABLE', 'False')))
stats_capable = strtobool(
os.environ.get('CC_TEST_FORCE_STATS_CAPABLE', 'False')
)

if stats_capable:
cfg_handler = ClangSA.construct_config_handler(
Expand Down
5 changes: 5 additions & 0 deletions codechecker_common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ def path_for_fake_root(full_path: str, root_path: str = '/') -> str:
relative_path = os.path.relpath(full_path, '/')
fake_root_path = os.path.join(root_path, relative_path)
return os.path.realpath(fake_root_path)


def strtobool(value: str) -> bool:
"""Parse a string value to a boolean."""
return value.lower() in ('y', 'yes', 't', 'true', 'on', '1')
4 changes: 2 additions & 2 deletions tools/tu_collector/tu_collector/tu_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import subprocess
import sys
import zipfile
from distutils.spawn import find_executable
from shutil import which

from pathlib import Path
from typing import Iterable, Iterator, List, Optional, Set, Tuple, Union
Expand Down Expand Up @@ -114,7 +114,7 @@ def __determine_compiler(gcc_command: List[str]) -> str:
files or environment variables.
"""
if gcc_command[0].endswith('ccache'):
if find_executable(gcc_command[1]) is not None:
if which(gcc_command[1]) is not None:
return gcc_command[1]

return gcc_command[0]
Expand Down
8 changes: 4 additions & 4 deletions web/tests/functional/statistics/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
""" statistics collector feature test. """


# pylint: disable=deprecated-module
from distutils import util
from codechecker_common.util import strtobool
import os
import shutil
import sys
Expand Down Expand Up @@ -120,8 +119,9 @@ def setup_method(self, _):

if not self.stats_capable:
try:
self.stats_capable = bool(util.strtobool(
os.environ['CC_TEST_FORCE_STATS_CAPABLE']))
self.stats_capable = strtobool(
os.environ['CC_TEST_FORCE_STATS_CAPABLE']
)
except (ValueError, KeyError):
pass

Expand Down

0 comments on commit b049040

Please sign in to comment.