From 2680eb807bf223a31951594ec41db984463d43f3 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Tue, 5 Aug 2025 14:38:17 -0700 Subject: [PATCH] change logic managing adding dll directories to path on Windows --- dpctl/__init__.py | 4 ---- dpctl/_init_helper.py | 28 ++++++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/dpctl/__init__.py b/dpctl/__init__.py index dd7b8f9ac5..9e1b52432d 100644 --- a/dpctl/__init__.py +++ b/dpctl/__init__.py @@ -129,10 +129,6 @@ "utils", ] -if hasattr(os, "add_dll_directory"): - # Include folder containing DPCTLSyclInterface.dll to search path - os.add_dll_directory(os.path.dirname(__file__)) - def get_include(): r""" diff --git a/dpctl/_init_helper.py b/dpctl/_init_helper.py index f07b84171b..9e20f9f982 100644 --- a/dpctl/_init_helper.py +++ b/dpctl/_init_helper.py @@ -18,20 +18,24 @@ import os.path import sys -is_venv_win32 = ( - sys.platform == "win32" - and sys.base_exec_prefix != sys.exec_prefix - and os.path.isfile(os.path.join(sys.exec_prefix, "pyvenv.cfg")) +is_venv = sys.base_exec_prefix != sys.exec_prefix and os.path.isfile( + os.path.join(sys.exec_prefix, "pyvenv.cfg") ) -if is_venv_win32: # pragma: no cover - # For virtual environments on Windows, add folder - # with DPC++ libraries to the DLL search path gh-1745 - dll_dir = os.path.join(sys.exec_prefix, "Library", "bin") - if os.path.isdir(dll_dir): - os.add_dll_directory(dll_dir) - -del is_venv_win32 +if sys.platform == "win32": # pragma: no cover + # Include folder containing DPCTLSyclInterface.dll to search path + os.add_dll_directory(os.path.dirname(__file__)) + if is_venv: + # For virtual environments on Windows, add folder + # with DPC++ libraries to the DLL search path gh-1745 + dll_dir = os.path.join(sys.exec_prefix, "Library", "bin") + if os.path.isdir(dll_dir): + os.add_dll_directory(dll_dir) + os.environ["PATH"] = os.pathsep.join( + [os.getenv("PATH", ""), dll_dir] + ) + +del is_venv is_linux = sys.platform.startswith("linux")