File: nsys_path.py

package info (click to toggle)
nvidia-cuda-toolkit 12.4.1-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 18,505,836 kB
  • sloc: ansic: 203,477; cpp: 64,769; python: 34,699; javascript: 22,006; xml: 13,410; makefile: 3,085; sh: 2,343; perl: 352
file content (55 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.

import os

from pathlib import Path

from nsys_recipe import nsys_constants
from nsys_recipe.lib import exceptions


def get_install_dir():
    """Return the Nsys install directory path.

    If the env var NSYS_DIR is set, return that.
    If not, deduce it from the current file path.
    """
    nsysdir = os.getenv("NSYS_DIR")
    if nsysdir is not None:
        return nsysdir

    parents = Path(__file__).parents
    if len(parents) >= 6:
        return str(parents[5].resolve())

    return None


def find_installed_file(relative_path):
    """Return the full path of the file located in the target or host
    directory."""
    install_dir = get_install_dir()

    if install_dir is not None:
        candidate_dirs = (
            nsys_constants.NSYS_TARGET_DIR,
            nsys_constants.NSYS_HOST_DIR,
            "",
        )
        for candidate_dir in candidate_dirs:
            candidate = Path(install_dir) / candidate_dir / relative_path
            if candidate.exists():
                return str(candidate)

    raise exceptions.ValueError(
        f"Cannot find '{relative_path}'."
        " Please set NSYS_DIR to a valid Nsys install directory that contains internal dependencies."
    )