77"""
88
99import os
10+ import shutil
1011import ctypes
1112
1213#: Path to normal KfW installed bin folder
1819KFW_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():
4142def 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