@@ -75,7 +75,7 @@ def get_files(filter=None, paths=None):
75
75
out = git ('diff' , '--name-only' , * filter_arg , COMMIT_RANGE , * paths_arg )
76
76
files = out .splitlines ()
77
77
for file in list (files ):
78
- if not os . path . isfile ( os . path . join ( GIT_TOP , file )):
78
+ if not ( GIT_TOP / file ). exists ( ):
79
79
# Drop submodule directories from the list.
80
80
files .remove (file )
81
81
return files
@@ -207,8 +207,8 @@ class CheckPatch(ComplianceTest):
207
207
path_hint = "<git-top>"
208
208
209
209
def run (self ):
210
- checkpatch = os . path . join ( ZEPHYR_BASE , 'scripts' , 'checkpatch.pl' )
211
- if not os . path . exists (checkpatch ):
210
+ checkpatch = ZEPHYR_BASE / 'scripts' / 'checkpatch.pl'
211
+ if not checkpatch . exists ():
212
212
self .skip (f'{ checkpatch } not found' )
213
213
214
214
# check for Perl installation on Windows
@@ -411,8 +411,7 @@ def get_modules(self, modules_file, sysbuild_modules_file, settings_file):
411
411
"""
412
412
# Invoke the script directly using the Python executable since this is
413
413
# not a module nor a pip-installed Python utility
414
- zephyr_module_path = os .path .join (ZEPHYR_BASE , "scripts" ,
415
- "zephyr_module.py" )
414
+ zephyr_module_path = ZEPHYR_BASE / "scripts" / "zephyr_module.py"
416
415
cmd = [sys .executable , zephyr_module_path ,
417
416
'--kconfig-out' , modules_file ,
418
417
'--sysbuild-kconfig-out' , sysbuild_modules_file ,
@@ -423,9 +422,9 @@ def get_modules(self, modules_file, sysbuild_modules_file, settings_file):
423
422
except subprocess .CalledProcessError as ex :
424
423
self .error (ex .output .decode ("utf-8" ))
425
424
426
- modules_dir = ZEPHYR_BASE + '/ modules'
425
+ modules_dir = ZEPHYR_BASE / ' modules'
427
426
modules = [name for name in os .listdir (modules_dir ) if
428
- os . path . exists ( os . path . join ( modules_dir , name , 'Kconfig' )) ]
427
+ modules_dir / name / 'Kconfig' ]
429
428
430
429
with open (modules_file , 'r' ) as fp_module_file :
431
430
content = fp_module_file .read ()
@@ -434,7 +433,7 @@ def get_modules(self, modules_file, sysbuild_modules_file, settings_file):
434
433
for module in modules :
435
434
fp_module_file .write ("ZEPHYR_{}_KCONFIG = {}\n " .format (
436
435
re .sub ('[^a-zA-Z0-9]' , '_' , module ).upper (),
437
- modules_dir + '/' + module + '/ Kconfig'
436
+ modules_dir / module / ' Kconfig'
438
437
))
439
438
fp_module_file .write (content )
440
439
@@ -468,12 +467,11 @@ def get_kconfig_dts(self, kconfig_dts_file, settings_file):
468
467
"""
469
468
# Invoke the script directly using the Python executable since this is
470
469
# not a module nor a pip-installed Python utility
471
- zephyr_drv_kconfig_path = os .path .join (ZEPHYR_BASE , "scripts" , "dts" ,
472
- "gen_driver_kconfig_dts.py" )
470
+ zephyr_drv_kconfig_path = ZEPHYR_BASE / "scripts" / "dts" / "gen_driver_kconfig_dts.py"
473
471
binding_paths = []
474
- binding_paths .append (os . path . join ( ZEPHYR_BASE , "dts" , "bindings" ) )
472
+ binding_paths .append (ZEPHYR_BASE / "dts" / "bindings" )
475
473
476
- dts_root_paths = self . get_module_setting_root ('dts' , settings_file )
474
+ dts_root_paths = get_module_setting_root ('dts' , settings_file )
477
475
for p in dts_root_paths :
478
476
binding_paths .append (p / "dts" / "bindings" )
479
477
@@ -506,10 +504,10 @@ def get_v2_model(self, kconfig_dir, settings_file):
506
504
kconfig_sysbuild_file = os .path .join (kconfig_dir , 'boards' , 'Kconfig.sysbuild' )
507
505
kconfig_defconfig_file = os .path .join (kconfig_dir , 'boards' , 'Kconfig.defconfig' )
508
506
509
- board_roots = self . get_module_setting_root ('board' , settings_file )
510
- board_roots .insert (0 , Path ( ZEPHYR_BASE ) )
511
- soc_roots = self . get_module_setting_root ('soc' , settings_file )
512
- soc_roots .insert (0 , Path ( ZEPHYR_BASE ) )
507
+ board_roots = get_module_setting_root ('board' , settings_file )
508
+ board_roots .insert (0 , ZEPHYR_BASE )
509
+ soc_roots = get_module_setting_root ('soc' , settings_file )
510
+ soc_roots .insert (0 , ZEPHYR_BASE )
513
511
root_args = argparse .Namespace (** {'board_roots' : board_roots ,
514
512
'soc_roots' : soc_roots , 'board' : None ,
515
513
'board_dir' : []})
@@ -572,7 +570,7 @@ def get_v2_model(self, kconfig_dir, settings_file):
572
570
573
571
kconfig_file = os .path .join (kconfig_dir , 'arch' , 'Kconfig' )
574
572
575
- root_args = argparse .Namespace (** {'arch_roots' : [Path ( ZEPHYR_BASE ) ], 'arch' : None })
573
+ root_args = argparse .Namespace (** {'arch_roots' : [ZEPHYR_BASE ], 'arch' : None })
576
574
v2_archs = list_hardware .find_v2_archs (root_args )
577
575
578
576
with open (kconfig_file , 'w' ) as fp :
@@ -586,20 +584,20 @@ def parse_kconfig(self):
586
584
"""
587
585
# Put the Kconfiglib path first to make sure no local Kconfiglib version is
588
586
# used
589
- kconfig_path = os . path . join ( ZEPHYR_BASE , "scripts" , "kconfig" )
590
- if not os . path . exists (kconfig_path ):
587
+ kconfig_path = ZEPHYR_BASE / "scripts" / "kconfig"
588
+ if not kconfig_path . exists ():
591
589
self .error (kconfig_path + " not found" )
592
590
593
591
kconfiglib_dir = tempfile .mkdtemp (prefix = "kconfiglib_" )
594
592
595
- sys .path .insert (0 , kconfig_path )
593
+ sys .path .insert (0 , str ( kconfig_path ) )
596
594
# Import globally so that e.g. kconfiglib.Symbol can be referenced in
597
595
# tests
598
596
global kconfiglib
599
597
import kconfiglib
600
598
601
599
# Look up Kconfig files relative to ZEPHYR_BASE
602
- os .environ ["srctree" ] = ZEPHYR_BASE
600
+ os .environ ["srctree" ] = str ( ZEPHYR_BASE )
603
601
604
602
# Parse the entire Kconfig tree, to make sure we see all symbols
605
603
os .environ ["SOC_DIR" ] = "soc/"
@@ -881,7 +879,7 @@ def check_no_undef_within_kconfig(self, kconf):
881
879
self .failure (f"Undefined Kconfig symbols:\n \n { undef_ref_warnings } " )
882
880
883
881
def check_soc_name_sync (self , kconf ):
884
- root_args = argparse .Namespace (** {'soc_roots' : [Path ( ZEPHYR_BASE ) ]})
882
+ root_args = argparse .Namespace (** {'soc_roots' : [ZEPHYR_BASE ]})
885
883
v2_systems = list_hardware .find_v2_systems (root_args )
886
884
887
885
soc_names = {soc .name for soc in v2_systems .get_socs ()}
@@ -950,7 +948,7 @@ def check_no_undef_outside_kconfig(self, kconf):
950
948
grep_stdout = git ("grep" , "--line-number" , "-I" , "--null" ,
951
949
"--perl-regexp" , regex , "--" , ":!/doc/releases" ,
952
950
":!/doc/security/vulnerabilities.rst" ,
953
- cwd = Path ( GIT_TOP ) )
951
+ cwd = GIT_TOP )
954
952
955
953
# splitlines() supports various line terminators
956
954
for grep_line in grep_stdout .splitlines ():
@@ -1247,7 +1245,7 @@ def run(self):
1247
1245
def check_kconfig_header (self , fname ):
1248
1246
# Checks for a spammy copy-pasted header format
1249
1247
1250
- with open (os . path . join ( GIT_TOP , fname ) , encoding = "utf-8" ) as f :
1248
+ with open (GIT_TOP / fname , encoding = "utf-8" ) as f :
1251
1249
contents = f .read ()
1252
1250
1253
1251
# 'Kconfig - yada yada' has a copy-pasted redundant filename at the
@@ -1273,7 +1271,7 @@ def check_redundant_zephyr_source(self, fname):
1273
1271
# Checks for 'source "$(ZEPHYR_BASE)/Kconfig[.zephyr]"', which can be
1274
1272
# be simplified to 'source "Kconfig[.zephyr]"'
1275
1273
1276
- with open (os . path . join ( GIT_TOP , fname ) , encoding = "utf-8" ) as f :
1274
+ with open (GIT_TOP / fname , encoding = "utf-8" ) as f :
1277
1275
# Look for e.g. rsource as well, for completeness
1278
1276
match = re .search (
1279
1277
r'^\s*(?:o|r|or)?source\s*"\$\(?ZEPHYR_BASE\)?/(Kconfig(?:\.zephyr)?)"' ,
@@ -1288,7 +1286,7 @@ def check_redundant_zephyr_source(self, fname):
1288
1286
def check_redundant_document_separator (self , fname ):
1289
1287
# Looks for redundant '...' document separators in bindings
1290
1288
1291
- with open (os . path . join ( GIT_TOP , fname ) , encoding = "utf-8" ) as f :
1289
+ with open (GIT_TOP / fname , encoding = "utf-8" ) as f :
1292
1290
if re .search (r"^\.\.\." , f .read (), re .MULTILINE ):
1293
1291
self .failure (f"""\
1294
1292
Redundant '...' document separator in { fname } . Binding YAML files are never
@@ -1297,7 +1295,7 @@ def check_redundant_document_separator(self, fname):
1297
1295
def check_source_file (self , fname ):
1298
1296
# Generic nits related to various source files
1299
1297
1300
- with open (os . path . join ( GIT_TOP , fname ) , encoding = "utf-8" ) as f :
1298
+ with open (GIT_TOP / fname , encoding = "utf-8" ) as f :
1301
1299
contents = f .read ()
1302
1300
1303
1301
if not contents .endswith ("\n " ):
@@ -1516,7 +1514,7 @@ def run(self):
1516
1514
BOARD_SIZE_LIMIT = 100 << 10
1517
1515
1518
1516
for file in get_files (filter = "d" ):
1519
- full_path = os . path . join ( GIT_TOP , file )
1517
+ full_path = GIT_TOP / file
1520
1518
mime_type = magic .from_file (full_path , mime = True )
1521
1519
1522
1520
if not mime_type .startswith ("image/" ):
@@ -1597,7 +1595,7 @@ class YAMLLint(ComplianceTest):
1597
1595
path_hint = "<git-top>"
1598
1596
1599
1597
def run (self ):
1600
- config_file = os . path . join ( ZEPHYR_BASE , ".yamllint" )
1598
+ config_file = ZEPHYR_BASE / ".yamllint"
1601
1599
1602
1600
for file in get_files (filter = "d" ):
1603
1601
if Path (file ).suffix not in ['.yaml' , '.yml' ]:
@@ -1819,7 +1817,7 @@ def run(self):
1819
1817
m = magic .Magic (mime = True , mime_encoding = True )
1820
1818
1821
1819
for file in get_files (filter = "d" ):
1822
- full_path = os . path . join ( GIT_TOP , file )
1820
+ full_path = GIT_TOP / file
1823
1821
mime_type = m .from_file (full_path )
1824
1822
1825
1823
if not mime_type .startswith ("text/" ):
@@ -1929,11 +1927,12 @@ def _main(args):
1929
1927
1930
1928
# Propagate this decision to child processes.
1931
1929
os .environ ['ZEPHYR_BASE' ] = ZEPHYR_BASE
1930
+ ZEPHYR_BASE = Path (ZEPHYR_BASE )
1932
1931
1933
1932
# The absolute path of the top-level git directory. Initialize it here so
1934
1933
# that issues running Git can be reported to GitHub.
1935
1934
global GIT_TOP
1936
- GIT_TOP = git ("rev-parse" , "--show-toplevel" )
1935
+ GIT_TOP = Path ( git ("rev-parse" , "--show-toplevel" ) )
1937
1936
1938
1937
# The commit range passed in --commit, e.g. "HEAD~3"
1939
1938
global COMMIT_RANGE
0 commit comments