@@ -234,3 +234,105 @@ def generate_misc_workflow(
234234 "misc" ,
235235 workflow_directory_path ,
236236 )
237+
238+ # LoongSuite Extension
239+ def get_loongsuite_tox_envs (additional_config_path : Path ) -> list :
240+ if not additional_config_path or not additional_config_path .exists ():
241+ return []
242+
243+ additional_tox_ini = ToxIni (additional_config_path )
244+ additional_conf = State (get_options (), []).conf
245+ additional_section = next (additional_tox_ini .sections ())
246+ additional_config_set = CoreConfigSet (
247+ additional_conf , additional_section , additional_config_path .parent , additional_config_path
248+ )
249+ (
250+ additional_config_set .loaders .extend (
251+ additional_tox_ini .get_loaders (
252+ additional_section ,
253+ base = [],
254+ override_map = defaultdict (list , {}),
255+ conf = additional_config_set ,
256+ )
257+ )
258+ )
259+ additional_env_list = additional_config_set .load ("env_list" )
260+ # Convert EnvList to list if needed
261+ return list (additional_env_list ) if additional_env_list else []
262+
263+
264+ def generate_extension_test_workflow (
265+ tox_ini_path : Path ,
266+ workflow_directory_path : Path ,
267+ additional_config_path : Path ,
268+ * operating_systems
269+ ) -> None :
270+ loongsuite_envs = get_loongsuite_tox_envs (additional_config_path )
271+ if not loongsuite_envs :
272+ return
273+
274+ _generate_workflow_with_template (
275+ get_test_job_datas (
276+ loongsuite_envs ,
277+ list (operating_systems )
278+ ),
279+ "loongsuite_test" ,
280+ "test" ,
281+ workflow_directory_path ,
282+ )
283+
284+
285+ def generate_extension_lint_workflow (
286+ tox_ini_path : Path ,
287+ workflow_directory_path : Path ,
288+ additional_config_path : Path ,
289+ ) -> None :
290+ loongsuite_envs = get_loongsuite_tox_envs (additional_config_path )
291+ if not loongsuite_envs :
292+ return
293+
294+ _generate_workflow_with_template (
295+ get_lint_job_datas (loongsuite_envs ),
296+ "loongsuite_lint" ,
297+ "lint" ,
298+ workflow_directory_path ,
299+ )
300+
301+
302+ def generate_extension_misc_workflow (
303+ tox_ini_path : Path ,
304+ workflow_directory_path : Path ,
305+ additional_config_path : Path ,
306+ ) -> None :
307+ loongsuite_envs = get_loongsuite_tox_envs (additional_config_path )
308+ if not loongsuite_envs :
309+ return
310+
311+ _generate_workflow_with_template (
312+ get_misc_job_datas (loongsuite_envs ),
313+ "loongsuite_misc" ,
314+ "misc" ,
315+ workflow_directory_path ,
316+ )
317+
318+
319+ def _generate_workflow_with_template (
320+ job_datas : list , name : str , template_name : str , workflow_directory_path : Path , max_jobs = 250
321+ ):
322+ # Github seems to limit the amount of jobs in a workflow file, that is why
323+ # they are split in groups of 250 per workflow file.
324+ for file_number , job_datas in enumerate (
325+ [
326+ job_datas [index : index + max_jobs ]
327+ for index in range (0 , len (job_datas ), max_jobs )
328+ ]
329+ ):
330+ with open (
331+ workflow_directory_path .joinpath (f"{ name } _{ file_number } .yml" ), "w"
332+ ) as test_yml_file :
333+ test_yml_file .write (
334+ Environment (loader = FileSystemLoader (Path (__file__ ).parent ))
335+ .get_template (f"{ template_name } .yml.j2" )
336+ .render (job_datas = job_datas , file_number = file_number )
337+ )
338+ test_yml_file .write ("\n " )
0 commit comments