Files
TheRock/rocm-systems/projects/rocprof-trace-decoder/python/_code_object_paths.py
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

54 lines
1.5 KiB
Python

from __future__ import annotations
import re
from collections.abc import Iterable
from pathlib import Path
from rocprof_trace_decoder.codegen import CodeObject
CODE_OBJECT_ID_RE = re.compile(r"(?:^|_)code_object_id_(\d+)(?:_|$)", re.IGNORECASE)
def code_objects_from_paths(paths: Iterable[str | Path]) -> list[CodeObject]:
parsed: list[tuple[Path, int | None]] = []
for raw_path in paths:
path = Path(raw_path)
parsed.append((path.expanduser().resolve(), _code_object_id_from_path(path)))
untagged = [str(path) for path, code_object_id in parsed if code_object_id is None]
parsed_ids = {
code_object_id for _path, code_object_id in parsed if code_object_id is not None
}
if len(untagged) > 1:
raise ValueError(
"Cannot infer code object IDs for multiple unnamed inputs: " + ", ".join(untagged)
)
if untagged and 0 in parsed_ids:
raise ValueError(
f"Cannot assign code object id 0 to {untagged[0]}: another input already uses id 0."
)
return [
CodeObject(
path=path,
code_object_id=code_object_id if code_object_id is not None else 0,
)
for path, code_object_id in parsed
]
def _code_object_id_from_path(path: Path) -> int | None:
stem = path.stem
match = CODE_OBJECT_ID_RE.search(stem)
if match:
return int(match.group(1))
pos = stem.rfind("_")
if pos == -1:
return None
try:
return int(stem[pos + 1 :])
except ValueError:
return None