Skip to content

Commit ba3b086

Browse files
captain5050namhyung
authored andcommitted
perf python: Fix setup.py mypy errors
getenv may return None, so assert it isn't None for CC and srctree environmental variables required for the script. Disable an optional warning related to Popen. Reviewed-by: James Clark <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 2194446 commit ba3b086

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tools/perf/util/setup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from re import sub
44

55
cc = getenv("CC")
6+
assert cc, "Environment variable CC not set"
67

78
# Check if CC has options, as is the case in yocto, where it uses CC="cc --sysroot..."
89
cc_tokens = cc.split()
@@ -12,8 +13,13 @@
1213
else:
1314
cc_options = ""
1415

16+
# ignore optional stderr could be None as it is set to PIPE to avoid that.
17+
# mypy: disable-error-code="union-attr"
1518
cc_is_clang = b"clang version" in Popen([cc, "-v"], stderr=PIPE).stderr.readline()
16-
src_feature_tests = getenv('srctree') + '/tools/build/feature'
19+
20+
srctree = getenv('srctree')
21+
assert srctree, "Environment variable srctree, for the Linux sources, not set"
22+
src_feature_tests = f'{srctree}/tools/build/feature'
1723

1824
def clang_has_option(option):
1925
cc_output = Popen([cc, cc_options + option, path.join(src_feature_tests, "test-hello.c") ], stderr=PIPE).stderr.readlines()
@@ -71,7 +77,7 @@ def finalize_options(self):
7177
# The python headers have mixed code with declarations (decls after asserts, for instance)
7278
cflags += [ "-Wno-declaration-after-statement" ]
7379

74-
src_perf = getenv('srctree') + '/tools/perf'
80+
src_perf = f'{srctree}/tools/perf'
7581
build_lib = getenv('PYTHON_EXTBUILD_LIB')
7682
build_tmp = getenv('PYTHON_EXTBUILD_TMP')
7783

0 commit comments

Comments
 (0)