Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_multicore / diagnostics / dump / layout.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-15 05:03 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-15 05:03 +0800
1# Copyright 2026 Huawei Technologies Co., Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ============================================================================
15"""Dump-specific safe stage directories, independent of profiler names."""
17from collections.abc import Sequence
18import re
20from hyper_multicore.diagnostics.common.graph import operator_diagnostic_name
21from hyper_multicore.scheduler.graph import OperatorNode
24_SAFE_FILE_NAME = re.compile(r"[^A-Za-z0-9_.-]+")
27def _stage_names(operators: Sequence[OperatorNode]) -> dict[str, str]:
28 """Reject duplicate, colliding or reserved dump stage directories."""
29 names = {}
30 used_directories = set()
31 for operator in operators:
32 name = operator_diagnostic_name(operator)
33 directory = _SAFE_FILE_NAME.sub("_", name)
34 if directory in ("", ".", "..", "__kernel_boundary__") or directory in used_directories:
35 raise ValueError(f"duplicate, colliding or reserved MegaKernel dump stage directory: {name!r}")
36 used_directories.add(directory)
37 names[operator.name] = name
38 return names