Coverage for cuda / pathfinder / _headers / header_descriptor.py: 59.09%

22 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-25 01:07 +0000

1# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 

2# SPDX-License-Identifier: Apache-2.0 

3 

4"""Per-header descriptor, registry, and platform-aware accessors. 

5 

6The canonical authored data lives in :mod:`header_descriptor_catalog`. This 

7module provides a name-keyed registry and platform-dispatch helpers consumed 

8by the runtime search path — keeping the search code itself platform-agnostic. 

9""" 

10 

11from __future__ import annotations 

12 

13import glob 

14import os 

15from typing import TypeAlias, cast 

16 

17from cuda.pathfinder._headers.header_descriptor_catalog import ( 

18 HEADER_DESCRIPTOR_CATALOG, 

19 HeaderDescriptorSpec, 

20) 

21from cuda.pathfinder._utils.platform_aware import IS_WINDOWS 

22 

23HeaderDescriptor: TypeAlias = HeaderDescriptorSpec 

24 

25#: Canonical registry of all known header libraries. 

26HEADER_DESCRIPTORS: dict[str, HeaderDescriptor] = {desc.name: desc for desc in HEADER_DESCRIPTOR_CATALOG} 

27 

28 

29def platform_include_subdirs(desc: HeaderDescriptor) -> tuple[str, ...]: 

30 """Return the effective include subdirectory search list for the current platform. 

31 

32 On Windows, Windows-specific subdirs are checked first, followed by the 

33 common subdirs. On Linux, only the common subdirs are returned. 

34 """ 

35 if IS_WINDOWS: 1bcdetfghijklmnopqrsu

36 return cast(tuple[str, ...], desc.include_subdirs_windows + desc.include_subdirs) 1bcdefghijklmnopqrs

37 return cast(tuple[str, ...], desc.include_subdirs) 1bcdetfghijklmnopqrsu

38 

39 

40def resolve_conda_anchor(desc: HeaderDescriptor, conda_prefix: str) -> str | None: 

41 """Resolve the conda anchor point for header search on the current platform. 

42 

43 Returns the directory that ``_locate_in_anchor_layout`` should use as 

44 *anchor_point*, or ``None`` if the conda layout is not usable. 

45 """ 

46 if IS_WINDOWS: 

47 anchor = os.path.join(conda_prefix, "Library") 

48 return anchor if os.path.isdir(anchor) else None 

49 if desc.conda_targets_layout: 

50 targets_include_path = glob.glob(os.path.join(conda_prefix, "targets", "*", "include")) 

51 if not targets_include_path or len(targets_include_path) != 1: 

52 return None 

53 return os.path.dirname(targets_include_path[0]) 

54 return conda_prefix