Skip to content

Commit c6eea90

Browse files
Avoid reliance of VIRTUAL_ENV environment variable
Use check suggested in PEP-0405 and pointed out by @ndgrigorian to compare sys.base_exec_prefix and sys.exec_prefix which would be different under virtual environment. The check that pyvenv.cfg exists is retained.
1 parent eab51fd commit c6eea90

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

dpctl/_init_helper.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616

1717
import os
1818
import os.path
19+
import sys
1920

20-
if hasattr(os, "add_dll_directory"):
21+
is_venv_win32 = (
22+
sys.platform == "win32"
23+
and sys.base_exec_prefix != sys.exec_prefix
24+
and os.path.isfile(os.path.join(sys.exec_prefix, "pyvenv.cfg"))
25+
)
26+
27+
if is_venv_win32:
2128
# For virtual environments on Windows, add folder
2229
# with DPC++ libraries to the DLL search path gh-1745
23-
if "VIRTUAL_ENV" in os.environ:
24-
venv_dir = os.environ["VIRTUAL_ENV"]
25-
# Expect to find file per PEP-0405
26-
expected_file = os.path.join(venv_dir, "pyvenv.cfg")
27-
dll_dir = os.path.join(venv_dir, "Library", "bin")
28-
if os.path.isdir(dll_dir) and os.path.isfile(expected_file):
29-
os.add_dll_directory(dll_dir)
30+
dll_dir = os.path.join(sys.exec_prefix, "Library", "bin")
31+
if os.path.isdir(dll_dir):
32+
os.add_dll_directory(dll_dir)
33+
34+
del is_venv_win32

0 commit comments

Comments
 (0)