Skip to content

Commit da210dc

Browse files
committed
Refactor tox config for loongsuite instrumentations (#59)
Change-Id: Ia82d00d526714a7ff1fddcb4bdd7d3809ff81543 Co-developed-by: Cursor <noreply@cursor.com>
1 parent 4d3fe1e commit da210dc

File tree

18 files changed

+624
-16
lines changed

18 files changed

+624
-16
lines changed

.github/component_owners.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ components:
5151

5252
instrumentation-genai/opentelemetry-instrumentation-openai-agents-v2:
5353
- nagkumar91
54+
55+
# LoongSuite Extension
56+
instrumentation-loongsuite:
57+
- cirilla-zmh
58+
- ralf0131
59+
- 123liuziming

.github/workflows/generate_workflows_lib/src/generate_workflows_lib/__init__.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pathlib import Path
2+
3+
from generate_workflows_lib import (
4+
generate_extension_lint_workflow,
5+
generate_extension_misc_workflow,
6+
generate_extension_test_workflow,
7+
)
8+
9+
tox_ini_path = Path(__file__).parent.parent.parent.joinpath("tox.ini")
10+
# loongsuite instrumentation modules
11+
tox_loongsuite_ini_path = Path(__file__).parent.parent.parent.joinpath("tox-loongsuite.ini")
12+
workflows_directory_path = Path(__file__).parent
13+
14+
generate_extension_test_workflow(tox_ini_path, workflows_directory_path, tox_loongsuite_ini_path, "ubuntu-latest")
15+
generate_extension_lint_workflow(tox_ini_path, workflows_directory_path, tox_loongsuite_ini_path)
16+
generate_extension_misc_workflow(tox_ini_path, workflows_directory_path, tox_loongsuite_ini_path)
File renamed without changes.

0 commit comments

Comments
 (0)