-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsetup.py
More file actions
48 lines (36 loc) · 1.3 KB
/
Copy pathsetup.py
File metadata and controls
48 lines (36 loc) · 1.3 KB
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
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import importlib.util
import os
import sys
from pathlib import Path
from setuptools import setup
ROOT = Path(__file__).resolve().parent
_TRUE_VALUES = {"1", "true", "yes", "on"}
_FALSE_VALUES = {"0", "false", "no", "off"}
def _load_xdr_build_helpers():
module_path = ROOT / "src" / "cuphoton" / "xdr" / "setup_package.py"
spec = importlib.util.spec_from_file_location(
"_cuphoton_xdr_setup_package", module_path
)
if spec is None or spec.loader is None:
raise RuntimeError(
f"Cannot load xDataReader build helpers: {module_path}"
)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
def _get_ext_modules():
mode = os.environ.get("CUPHOTON_XDR_BUILD_EXT", "0").strip().lower()
if mode in _FALSE_VALUES:
return []
if mode not in _TRUE_VALUES:
raise RuntimeError(
"CUPHOTON_XDR_BUILD_EXT must be one of: "
+ ", ".join(sorted(_FALSE_VALUES | _TRUE_VALUES))
)
return _load_xdr_build_helpers().get_extensions()
setup(ext_modules=_get_ext_modules())