1616"""
1717
1818import json
19+ import os
1920import sys
2021import subprocess
2122from pathlib import Path
2425def install_dependencies ():
2526 """Ensure jq is installed (for reference, though we use Python's json)."""
2627 try :
27- subprocess .run (
28- ["sudo" , "apt-get" , "update" ],
29- check = True ,
30- capture_output = True
31- )
32- subprocess .run (
33- ["sudo" , "apt-get" , "install" , "-y" , "jq" ],
34- check = True ,
35- capture_output = True
36- )
28+ subprocess .run (["sudo" , "apt-get" , "update" ], check = True , capture_output = True )
29+ subprocess .run (["sudo" , "apt-get" , "install" , "-y" , "jq" ], check = True , capture_output = True )
3730 except subprocess .CalledProcessError as e :
3831 print (f"Warning: Failed to install jq: { e } " , file = sys .stderr )
3932
@@ -56,44 +49,39 @@ def parse_known_good(json_file="./known_good.json"):
5649 sys .exit (1 )
5750
5851 try :
59- with open (json_path , 'r' ) as f :
52+ with open (json_path , "r" ) as f :
6053 data = json .load (f )
6154 except json .JSONDecodeError as e :
6255 print (f"Error: Failed to parse JSON: { e } " , file = sys .stderr )
6356 sys .exit (1 )
6457
6558 # Extract target_sw modules
66- modules = data .get (' modules' , {}).get (' target_sw' , {})
59+ modules = data .get (" modules" , {}).get (" target_sw" , {})
6760
6861 # Transform modules into repository objects
6962 repos = []
7063 module_outputs = {}
7164
7265 for name , config in modules .items ():
73- repo_url = config .get (' repo' , '' )
74- version = config .get (' version' , '' )
75- branch = config .get (' branch' , '' )
76- hash_val = config .get (' hash' , '' )
66+ repo_url = config .get (" repo" , "" )
67+ version = config .get (" version" , "" )
68+ branch = config .get (" branch" , "" )
69+ hash_val = config .get (" hash" , "" )
7770
7871 # Use version, branch, or hash (in that order of preference)
7972 ref = version or branch or hash_val
8073
81- repo_obj = {
82- 'name' : name ,
83- 'url' : repo_url ,
84- 'version' : ref ,
85- 'path' : f'repos/{ name } '
86- }
74+ repo_obj = {"name" : name , "url" : repo_url , "version" : ref , "path" : f"repos/{ name } " }
8775 repos .append (repo_obj )
8876
8977 # Store module outputs for GITHUB_OUTPUT compatibility
90- module_outputs [f' { name } _url' ] = repo_url
78+ module_outputs [f" { name } _url" ] = repo_url
9179 if version :
92- module_outputs [f' { name } _version' ] = version
80+ module_outputs [f" { name } _version" ] = version
9381 if branch :
94- module_outputs [f' { name } _branch' ] = branch
82+ module_outputs [f" { name } _branch" ] = branch
9583 if hash_val :
96- module_outputs [f' { name } _hash' ] = hash_val
84+ module_outputs [f" { name } _hash" ] = hash_val
9785
9886 return repos , len (modules ), module_outputs
9987
@@ -103,7 +91,7 @@ def write_repos_json(repos, output_file="./repos.json"):
10391 output_path = Path (output_file )
10492
10593 try :
106- with open (output_path , 'w' ) as f :
94+ with open (output_path , "w" ) as f :
10795 json .dump (repos , f , indent = 2 )
10896 print (f"Generated { output_file } :" )
10997 print (json .dumps (repos , indent = 2 ))
@@ -120,11 +108,11 @@ def write_github_output(outputs):
120108 Args:
121109 outputs: Dictionary of key-value pairs to output
122110 """
123- github_output = Path (os .environ .get (' GITHUB_OUTPUT' , ' /dev/null' ))
111+ github_output = Path (os .environ .get (" GITHUB_OUTPUT" , " /dev/null" ))
124112
125113 if github_output .exists () or github_output .parent .exists ():
126114 try :
127- with open (github_output , 'a' ) as f :
115+ with open (github_output , "a" ) as f :
128116 for key , value in outputs .items ():
129117 f .write (f"{ key } ={ value } \n " )
130118 except IOError as e :
@@ -139,18 +127,18 @@ def main():
139127 # install_dependencies()
140128
141129 # Parse known_good.json
142- repos , module_count , module_outputs = parse_known_good (' ./known_good.json' )
130+ repos , module_count , module_outputs = parse_known_good (" ./known_good.json" )
143131
144132 # Write repos.json
145133 write_repos_json (repos )
146134
147135 # Write GitHub Actions outputs
148- github_outputs = {' MODULE_COUNT' : str (module_count )}
136+ github_outputs = {" MODULE_COUNT" : str (module_count )}
149137 github_outputs .update (module_outputs )
150138 write_github_output (github_outputs )
151139
152140 print ("Parse complete!" )
153141
154142
155- if __name__ == ' __main__' :
143+ if __name__ == " __main__" :
156144 main ()
0 commit comments