Skip to content

Commit 6bf421e

Browse files
committed
Better way of formatting warning messages.
1 parent 2ccdc21 commit 6bf421e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

cuda_core/cuda/core/experimental/_linker.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,30 @@ def _decide_nvjitlink_or_driver() -> bool:
4040
_driver_ver = handle_return(driver.cuDriverGetVersion())
4141
_driver_ver = (_driver_ver // 1000, (_driver_ver % 1000) // 10)
4242

43-
def libname():
44-
return "nvJitLink*.dll" if sys.platform == "win32" else "libnvJitLink.so*"
45-
46-
therefore_not_usable = ". Therefore cuda.bindings.nvjitlink is not usable and"
47-
4843
try:
4944
_nvjitlink = importlib.import_module("cuda.bindings.nvjitlink")
5045
except ModuleNotFoundError:
51-
problem = "cuda.bindings.nvjitlink is not available, therefore"
46+
warn_txt = "cuda.bindings.nvjitlink is not available, therefore"
5247
else:
5348
from cuda.bindings._internal import nvjitlink as inner_nvjitlink
5449

50+
def build_warn_txt(detail):
51+
return (
52+
f"{'nvJitLink*.dll' if sys.platform == 'win32' else 'libnvJitLink.so*'} is {detail}."
53+
" Therefore cuda.bindings.nvjitlink is not usable and"
54+
)
55+
5556
try:
5657
if inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion"):
5758
return False # Use nvjitlink
5859
except RuntimeError:
59-
problem = libname() + " is not available" + therefore_not_usable
60+
warn_txt = build_warn_txt("not available")
6061
else:
61-
problem = libname() + " is is too old (<12.3)" + therefore_not_usable
62+
warn_txt = build_warn_txt("too old (<12.3)")
6263
_nvjitlink = None
6364

6465
warn(
65-
problem + " the culink APIs will be used instead.",
66+
warn_txt + " the culink APIs will be used instead.",
6667
stacklevel=2,
6768
category=RuntimeWarning,
6869
)

0 commit comments

Comments
 (0)