Skip to content

Commit b049040

Browse files
authored
Merge pull request #4286 from EinarArnason/master
Deprecate distutils
2 parents 83bc366 + 039aa60 commit b049040

File tree

12 files changed

+37
-40
lines changed

12 files changed

+37
-40
lines changed

analyzer/codechecker_analyzer/analyzer_context.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"""
1111

1212

13-
# pylint: disable=deprecated-module
14-
from distutils.spawn import find_executable
13+
from shutil import which
1514
from argparse import ArgumentTypeError
1615

1716
import os
@@ -104,7 +103,7 @@ def __parse_cc_analyzer_bin(self):
104103
had_error = True
105104
continue
106105

107-
resolved_path = find_executable(path)
106+
resolved_path = which(path)
108107

109108
if not os.path.isfile(resolved_path):
110109
LOG.error(f"'{path}' is not a path to an analyzer binary "
@@ -219,7 +218,7 @@ def __populate_analyzers(self):
219218
self._data_files_dir_path, value)
220219
else:
221220
env_path = analyzer_env['PATH'] if analyzer_env else None
222-
compiler_binary = find_executable(value, env_path)
221+
compiler_binary = which(cmd=value, path=env_path)
223222
if not compiler_binary:
224223
LOG.debug("'%s' binary can not be found in your PATH!",
225224
value)
@@ -242,7 +241,7 @@ def __populate_replacer(self):
242241
self.__replacer = os.path.join(self._data_files_dir_path,
243242
replacer_binary)
244243
else:
245-
self.__replacer = find_executable(replacer_binary)
244+
self.__replacer = which(replacer_binary)
246245

247246
@property
248247
def version(self):

analyzer/codechecker_analyzer/analyzers/cppcheck/analyzer.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
"""
1111

1212
from collections import defaultdict
13-
# TODO distutils will be removed in python3.12
14-
# pylint: disable=deprecated-module
15-
from distutils.version import StrictVersion
13+
from packaging.version import Version
1614
from pathlib import Path
1715
import os
1816
import pickle
@@ -347,7 +345,7 @@ def is_binary_version_incompatible(cls, environ):
347345

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

353351
return "CppCheck binary found is too old at " \

analyzer/codechecker_analyzer/analyzers/gcc/analyzer.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#
77
# -------------------------------------------------------------------------
88
from collections import defaultdict
9-
# TODO distutils will be removed in python3.12
10-
# pylint: disable=deprecated-module
11-
from distutils.version import StrictVersion
9+
from packaging.version import Version
1210
import os
1311
import pickle
1412
import shlex
@@ -201,7 +199,7 @@ def is_binary_version_incompatible(cls, environ):
201199
# The analyzer version should be above 13.0.0 because the
202200
# '-fdiagnostics-format=sarif-file' argument was introduced in this
203201
# release.
204-
if analyzer_version >= StrictVersion("13.0.0"):
202+
if Version(analyzer_version) >= Version("13.0.0"):
205203
return None
206204

207205
return f"GCC binary found is too old at v{analyzer_version.strip()}; "\

analyzer/codechecker_analyzer/buildlog/log_parser.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99

1010
from collections import namedtuple
11-
# pylint: disable=deprecated-module
12-
from distutils.spawn import find_executable
11+
from shutil import which
1312
from enum import Enum
1413
from pathlib import Path
1514

@@ -342,7 +341,7 @@ def cpp():
342341
def is_executable_compiler(compiler):
343342
if compiler not in ImplicitCompilerInfo.compiler_isexecutable:
344343
ImplicitCompilerInfo.compiler_isexecutable[compiler] = \
345-
find_executable(compiler) is not None
344+
which(compiler) is not None
346345

347346
return ImplicitCompilerInfo.compiler_isexecutable[compiler]
348347

analyzer/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ PyYAML==6.0.1
55
types-PyYAML==6.0.12.12
66
sarif-tools==1.0.0
77
multiprocess==0.70.15
8+
setuptools==70.2.0

analyzer/tests/functional/fixit/test_fixit.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import time
2222
import unittest
2323

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

2726
from libtest import env
2827

@@ -71,7 +70,7 @@ def teardown_method(self, _):
7170
if os.path.isdir(self.report_dir):
7271
shutil.rmtree(self.report_dir)
7372

74-
@unittest.skipIf(find_executable('clang-apply-replacements') is None,
73+
@unittest.skipIf(which('clang-apply-replacements') is None,
7574
"clang-apply-replacements clang tool must be available "
7675
"in the environment.")
7776
def test_fixit_list(self):
@@ -167,7 +166,7 @@ def test_fixit_list(self):
167166
self.assertIn("v.empty()", new_source_file)
168167
self.assertNotIn("v.size()", new_source_file)
169168

170-
@unittest.skipIf(find_executable('clang-apply-replacements') is None,
169+
@unittest.skipIf(which('clang-apply-replacements') is None,
171170
"clang-apply-replacements clang tool must be available "
172171
"in the environment.")
173172
def test_fixit_file_modification(self):
@@ -255,7 +254,7 @@ def test_fixit_file_modification(self):
255254
self.assertIn('Skipped files due to modification since last analysis',
256255
err)
257256

258-
@unittest.skipIf(find_executable('clang-apply-replacements') is None,
257+
@unittest.skipIf(which('clang-apply-replacements') is None,
259258
"clang-apply-replacements clang tool must be available "
260259
"in the environment.")
261260
def test_fixit_by_diff(self):
@@ -353,7 +352,7 @@ def test_fixit_by_diff(self):
353352
print('\n' + out + '\n')
354353
self.assertEqual(out.count("DiagnosticMessage"), 1)
355354

356-
@unittest.skipIf(find_executable('clang-apply-replacements') is None,
355+
@unittest.skipIf(which('clang-apply-replacements') is None,
357356
"clang-apply-replacements clang tool must be available "
358357
"in the environment.")
359358
def test_fixit_apply_failure(self):

analyzer/tests/functional/z3/test_z3.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
""" Z3 feature test. """
1111

1212

13-
# pylint: disable=deprecated-module
14-
from distutils import util
13+
from codechecker_common.util import strtobool
1514
import os
1615
import shutil
1716
import unittest
@@ -117,8 +116,9 @@ def setup_method(self, _):
117116

118117
if not self.z3_capable:
119118
try:
120-
self.z3_capable = bool(util.strtobool(
121-
os.environ['CC_TEST_FORCE_Z3_CAPABLE']))
119+
self.z3_capable = strtobool(
120+
os.environ['CC_TEST_FORCE_Z3_CAPABLE']
121+
)
122122
except (ValueError, KeyError):
123123
pass
124124

analyzer/tests/libtest/codechecker.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import shlex
1515
import subprocess
1616

17-
# pylint: disable=deprecated-module
18-
from distutils import util
17+
from codechecker_common.util import strtobool
1918

2019
from codechecker_analyzer import host_check
2120

@@ -137,8 +136,7 @@ def check_force_ctu_capable(is_capable):
137136
"""
138137
if not is_capable:
139138
try:
140-
return bool(util.strtobool(
141-
os.environ['CC_TEST_FORCE_CTU_CAPABLE']))
139+
return strtobool(os.environ['CC_TEST_FORCE_CTU_CAPABLE'])
142140
except (ValueError, KeyError):
143141
pass
144142

analyzer/tests/unit/test_checker_handling.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"""
1212

1313

14-
# pylint: disable=deprecated-module
15-
from distutils import util
14+
from codechecker_common.util import strtobool
1615
import os
1716
import re
1817
import tempfile
@@ -260,8 +259,9 @@ def f(checks, checkers):
260259

261260
# Test if statisticsbased checkers are enabled by --stats flag
262261
# by default.
263-
stats_capable = bool(util.strtobool(
264-
os.environ.get('CC_TEST_FORCE_STATS_CAPABLE', 'False')))
262+
stats_capable = strtobool(
263+
os.environ.get('CC_TEST_FORCE_STATS_CAPABLE', 'False')
264+
)
265265

266266
if stats_capable:
267267
cfg_handler = ClangSA.construct_config_handler(

codechecker_common/util.py

+5
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,8 @@ def path_for_fake_root(full_path: str, root_path: str = '/') -> str:
107107
relative_path = os.path.relpath(full_path, '/')
108108
fake_root_path = os.path.join(root_path, relative_path)
109109
return os.path.realpath(fake_root_path)
110+
111+
112+
def strtobool(value: str) -> bool:
113+
"""Parse a string value to a boolean."""
114+
return value.lower() in ('y', 'yes', 't', 'true', 'on', '1')

tools/tu_collector/tu_collector/tu_collector.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import subprocess
2929
import sys
3030
import zipfile
31-
from distutils.spawn import find_executable
31+
from shutil import which
3232

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

120120
return gcc_command[0]

web/tests/functional/statistics/test_statistics.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
""" statistics collector feature test. """
1111

1212

13-
# pylint: disable=deprecated-module
14-
from distutils import util
13+
from codechecker_common.util import strtobool
1514
import os
1615
import shutil
1716
import sys
@@ -120,8 +119,9 @@ def setup_method(self, _):
120119

121120
if not self.stats_capable:
122121
try:
123-
self.stats_capable = bool(util.strtobool(
124-
os.environ['CC_TEST_FORCE_STATS_CAPABLE']))
122+
self.stats_capable = strtobool(
123+
os.environ['CC_TEST_FORCE_STATS_CAPABLE']
124+
)
125125
except (ValueError, KeyError):
126126
pass
127127

0 commit comments

Comments
 (0)