Skip to content

Commit b95c263

Browse files
aiudirogfrozencemetery
authored andcommitted
Use os.add_dll_directory when configuring Windows on >=3.8
1 parent 1eadb94 commit b95c263

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

gssapi/_win_config.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
import os
10+
import shutil
1011
import ctypes
1112

1213
#: Path to normal KfW installed bin folder
@@ -18,8 +19,8 @@
1819
KFW_DL = "https://web.mit.edu/KERBEROS/dist"
1920

2021

21-
def k4w_in_path():
22-
"""Return if the main GSSAPI DLL for KfW is available in the PATH"""
22+
def kfw_available():
23+
"""Return if the main GSSAPI DLL for KfW can be loaded"""
2324
try: # to load the main GSSAPI DLL
2425
ctypes.WinDLL('gssapi64.dll')
2526
except OSError: # DLL is not in PATH
@@ -41,14 +42,31 @@ def error_not_found():
4142
def configure_windows():
4243
"""
4344
Validate that KfW appears to be installed correctly and add it to the
44-
PATH if necessary. In the case that it can't be located, raise an error.
45+
DLL directories/PATH if necessary. In the case that it can't be located,
46+
raise an error.
4547
"""
46-
if k4w_in_path():
48+
if kfw_available():
4749
return # All set, necessary DLLs should be available
50+
4851
if os.path.exists(KFW_BIN): # In standard location
49-
os.environ['PATH'] += os.pathsep + KFW_BIN
50-
if k4w_in_path():
52+
try: # to use Python 3.8's DLL handling
53+
os.add_dll_directory(KFW_BIN)
54+
except AttributeError: # <3.8, use PATH
55+
os.environ['PATH'] += os.pathsep + KFW_BIN
56+
if kfw_available():
5157
return
58+
59+
# Check if kinit is in the PATH which should lead us to the bin folder
60+
kinit_path = shutil.which('kinit') # KfW provided binary
61+
if kinit_path: # Non-standard install location
62+
try: # Most likely >=3.8, otherwise it would have been found already
63+
os.add_dll_directory(os.path.dirname(kinit_path))
64+
except AttributeError: # <3.8, corrupted installation?
65+
pass
66+
else:
67+
if kfw_available():
68+
return
69+
5270
error_not_found()
5371

5472

0 commit comments

Comments
 (0)