@@ -54,8 +54,7 @@ def load_manifest(manifest_path: Path) -> Dict[str, Any]:
5454 except jsonschema .exceptions .ValidationError :
5555 # If validation fails, we continue but log a warning
5656 # This allows the site to build even with some schema issues
57- print (
58- f"⚠️ Warning: { manifest_path } does not fully conform to the schema" )
57+ print (f"⚠️ Warning: { manifest_path } does not fully conform to the schema" )
5958
6059 return manifest
6160 except json .JSONDecodeError as e :
@@ -92,9 +91,12 @@ def extract_github_repos(server_manifests: List[Path]) -> Dict[str, str]:
9291 # Handle both string and dictionary repository formats
9392 if isinstance (repo_url , str ) and repo_url .startswith ("https://github.com/" ):
9493 github_repos [server_name ] = repo_url
95- elif (isinstance (repo_url , dict ) and "url" in repo_url and
96- isinstance (repo_url ["url" ], str ) and
97- repo_url ["url" ].startswith ("https://github.com/" )):
94+ elif (
95+ isinstance (repo_url , dict )
96+ and "url" in repo_url
97+ and isinstance (repo_url ["url" ], str )
98+ and repo_url ["url" ].startswith ("https://github.com/" )
99+ ):
98100 github_repos [server_name ] = repo_url ["url" ]
99101
100102 return github_repos
@@ -130,7 +132,7 @@ def fetch_github_stars_batch(repo_urls: List[str]) -> Dict[str, int]:
130132
131133 # Process repositories in batches
132134 for batch_start in range (0 , len (repos ), BATCH_SIZE ):
133- batch = repos [batch_start : batch_start + BATCH_SIZE ]
135+ batch = repos [batch_start : batch_start + BATCH_SIZE ]
134136
135137 # Construct GraphQL query
136138 query_parts = []
@@ -147,8 +149,7 @@ def fetch_github_stars_batch(repo_urls: List[str]) -> Dict[str, int]:
147149 variables [f"repo{ i } " ] = repo
148150
149151 # Join the query parts with proper line length
150- variable_defs = ", " .join (f"$owner{ i } : String!, $repo{ i } : String!"
151- for i in range (len (batch )))
152+ variable_defs = ", " .join (f"$owner{ i } : String!, $repo{ i } : String!" for i in range (len (batch )))
152153 query_body = " " .join (query_parts )
153154
154155 query = f"""query ({ variable_defs } ) {{
@@ -157,23 +158,16 @@ def fetch_github_stars_batch(repo_urls: List[str]) -> Dict[str, int]:
157158
158159 # Send GraphQL request
159160 try :
160- response = requests .post (
161- GITHUB_API_URL ,
162- headers = headers ,
163- json = {"query" : query , "variables" : variables }
164- )
161+ response = requests .post (GITHUB_API_URL , headers = headers , json = {"query" : query , "variables" : variables })
165162
166163 # Check for errors
167164 if response .status_code != 200 :
168165 if response .status_code == 401 :
169- print (
170- "⚠️ GitHub API authentication failed. Set GITHUB_TOKEN for higher rate limits." )
166+ print ("⚠️ GitHub API authentication failed. Set GITHUB_TOKEN for higher rate limits." )
171167 elif response .status_code == 403 :
172- print (
173- "⚠️ GitHub API rate limit exceeded. Set GITHUB_TOKEN for higher rate limits." )
168+ print ("⚠️ GitHub API rate limit exceeded. Set GITHUB_TOKEN for higher rate limits." )
174169 else :
175- print (
176- f"⚠️ GitHub API request failed: status { response .status_code } " )
170+ print (f"⚠️ GitHub API request failed: status { response .status_code } " )
177171 continue
178172
179173 data = response .json ()
@@ -191,16 +185,13 @@ def fetch_github_stars_batch(repo_urls: List[str]) -> Dict[str, int]:
191185 star_count = data ["data" ][repo_key ]["stargazerCount" ]
192186 stars [url ] = star_count
193187 if url .startswith ("https://github.com/" ):
194- returned_parts = url .replace (
195- "https://github.com/" , "" ).split ("/" )
188+ returned_parts = url .replace ("https://github.com/" , "" ).split ("/" )
196189 if len (returned_parts ) >= 2 :
197190 returned_owner , returned_repo = returned_parts [0 ], returned_parts [1 ]
198191 if owner != returned_owner :
199- print (
200- f"⚠️owner mismatch:: { owner } != { returned_owner } " )
192+ print (f"⚠️owner mismatch:: { owner } != { returned_owner } " )
201193 if repo != returned_repo :
202- print (
203- f"⚠️repo mismatch:: { repo } != { returned_repo } " )
194+ print (f"⚠️repo mismatch:: { repo } != { returned_repo } " )
204195
205196 except Exception as e :
206197 print (f"⚠️ Error fetching GitHub stars for batch: { e } " )
@@ -249,7 +240,7 @@ def generate_servers_json(server_manifests: List[Path], output_path: Path) -> Di
249240 servers_data [server_name ] = manifest
250241
251242 # Write servers.json
252- with open (output_path , "w" ) as f :
243+ with open (output_path , "w" , encoding = "utf-8" ) as f :
253244 json .dump (servers_data , f , indent = 2 )
254245
255246 return servers_data
@@ -267,8 +258,7 @@ def generate_stars_json(stars: Dict[str, int], output_path: Path) -> None:
267258def main () -> None :
268259 """Main function to prepare site data"""
269260 if len (sys .argv ) < 3 :
270- error_exit (
271- "Usage: prepare.py <source_dir> <target_dir> [--skip-stars]" )
261+ error_exit ("Usage: prepare.py <source_dir> <target_dir> [--skip-stars]" )
272262
273263 source_dir = Path (sys .argv [1 ])
274264 target_dir = Path (sys .argv [2 ])
0 commit comments