@@ -16,18 +16,20 @@ def check_go_fips_compliance(melange_cfg: dict[str, Any]) -> tuple[bool, list[st
1616 Returns (is_compliant, list_of_missing_tests).
1717 """
1818 issues = []
19-
19+
2020 # Check if main package uses go-fips
2121 main_uses_fips = False
2222 main_has_test = False
23-
23+
2424 # Check environment packages for any go-fips variant
25- env_packages = melange_cfg .get ("environment" , {}).get ("contents" , {}).get ("packages" , [])
25+ env_packages = (
26+ melange_cfg .get ("environment" , {}).get ("contents" , {}).get ("packages" , [])
27+ )
2628 for pkg in env_packages :
2729 if pkg .startswith ("go-fips" ):
2830 main_uses_fips = True
2931 break
30-
32+
3133 # Check main pipeline steps for go/build with go-package: go-fips*
3234 pipelines = melange_cfg .get ("pipeline" , [])
3335 for step in pipelines :
@@ -36,24 +38,24 @@ def check_go_fips_compliance(melange_cfg: dict[str, Any]) -> tuple[bool, list[st
3638 if go_package .startswith ("go-fips" ):
3739 main_uses_fips = True
3840 break
39-
41+
4042 # Check main test section
4143 test_section = melange_cfg .get ("test" , {})
4244 test_pipelines = test_section .get ("pipeline" , [])
4345 for step in test_pipelines :
4446 if step .get ("uses" ) == "test/go-fips-check" :
4547 main_has_test = True
4648 break
47-
49+
4850 if main_uses_fips and not main_has_test :
4951 issues .append ("main package uses go-fips but lacks test/go-fips-check" )
50-
52+
5153 # Check each subpackage
5254 for i , subpkg in enumerate (melange_cfg .get ("subpackages" , [])):
5355 subpkg_uses_fips = False
5456 subpkg_has_test = False
5557 subpkg_name = subpkg .get ("name" , f"subpackage-{ i } " )
56-
58+
5759 # Check subpackage pipelines for go-fips usage
5860 subpkg_pipelines = subpkg .get ("pipeline" , [])
5961 for step in subpkg_pipelines :
@@ -62,30 +64,32 @@ def check_go_fips_compliance(melange_cfg: dict[str, Any]) -> tuple[bool, list[st
6264 if go_package .startswith ("go-fips" ):
6365 subpkg_uses_fips = True
6466 break
65-
67+
6668 # Check subpackage test sections
6769 subpkg_test_section = subpkg .get ("test" , {})
6870 subpkg_test_pipelines = subpkg_test_section .get ("pipeline" , [])
6971 for step in subpkg_test_pipelines :
7072 if step .get ("uses" ) == "test/go-fips-check" :
7173 subpkg_has_test = True
7274 break
73-
75+
7476 if subpkg_uses_fips and not subpkg_has_test :
75- issues .append (f"subpackage '{ subpkg_name } ' uses go-fips but lacks test/go-fips-check" )
76-
77+ issues .append (
78+ f"subpackage '{ subpkg_name } ' uses go-fips but lacks test/go-fips-check" ,
79+ )
80+
7781 return len (issues ) == 0 , issues
7882
7983
8084def main (argv : Sequence [str ] | None = None ) -> int :
8185 parser = argparse .ArgumentParser (
82- description = "Check that packages using go-fips have corresponding go-fips tests"
86+ description = "Check that packages using go-fips have corresponding go-fips tests" ,
8387 )
8488 parser .add_argument ("filenames" , nargs = "*" , help = "Filenames to check" )
8589 args = parser .parse_args (argv )
86-
90+
8791 retval = 0
88-
92+
8993 for filename in args .filenames :
9094 try :
9195 with open (filename ) as f :
@@ -94,18 +98,18 @@ def main(argv: Sequence[str] | None = None) -> int:
9498 print (f"Error loading { filename } : { e } " )
9599 retval = 1
96100 continue
97-
101+
98102 if not melange_cfg :
99103 continue
100-
104+
101105 is_compliant , issues = check_go_fips_compliance (melange_cfg )
102106 if not is_compliant :
103107 for issue in issues :
104108 print (f"{ filename } : { issue } " )
105109 retval = 1
106-
110+
107111 return retval
108112
109113
110114if __name__ == "__main__" :
111- sys .exit (main ())
115+ sys .exit (main ())
0 commit comments