Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Loading DLL on Windows Python >=3.8 #197

Merged
merged 3 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions .travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,17 @@ fi
python setup.py build_ext --inplace $EXTRA_BUILDEXT
BUILD_RES=$?

if [ x"$KRB5_VER" = "xheimdal" ]; then
# heimdal can't run the tests yet, so just exit
exit $BUILD_RES
fi

if [ "$TRAVIS_OS_NAME" == "windows" ]; then
# Windows can't run tests yet, so just exit
exit $BUILD_RES
fi

if [ $BUILD_RES -ne 0 ]; then
# if the build failed, don't run the tests
exit $BUILD_RES
fi

if [ x"$KRB5_VER" = "xheimdal" ] || [ "$TRAVIS_OS_NAME" = "windows" ]; then
# heimdal/Windows can't run the tests yet, so just make sure it imports and exit
python -c "import gssapi"
exit $?
fi

python setup.py nosetests --verbosity=3
TEST_RES=$?

Expand Down
30 changes: 24 additions & 6 deletions gssapi/_win_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import os
import shutil
import ctypes

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


def k4w_in_path():
"""Return if the main GSSAPI DLL for KfW is available in the PATH"""
def kfw_available():
"""Return if the main GSSAPI DLL for KfW can be loaded"""
try: # to load the main GSSAPI DLL
ctypes.WinDLL('gssapi64.dll')
except OSError: # DLL is not in PATH
Expand All @@ -41,14 +42,31 @@ def error_not_found():
def configure_windows():
"""
Validate that KfW appears to be installed correctly and add it to the
PATH if necessary. In the case that it can't be located, raise an error.
DLL directories/PATH if necessary. In the case that it can't be located,
raise an error.
"""
if k4w_in_path():
if kfw_available():
return # All set, necessary DLLs should be available

if os.path.exists(KFW_BIN): # In standard location
os.environ['PATH'] += os.pathsep + KFW_BIN
if k4w_in_path():
try: # to use Python 3.8's DLL handling
os.add_dll_directory(KFW_BIN)
except AttributeError: # <3.8, use PATH
os.environ['PATH'] += os.pathsep + KFW_BIN
if kfw_available():
return

# Check if kinit is in the PATH which should lead us to the bin folder
kinit_path = shutil.which('kinit') # KfW provided binary
if kinit_path: # Non-standard install location
try: # Most likely >=3.8, otherwise it would have been found already
os.add_dll_directory(os.path.dirname(kinit_path))
except AttributeError: # <3.8, corrupted installation?
pass
else:
if kfw_available():
frozencemetery marked this conversation as resolved.
Show resolved Hide resolved
return

error_not_found()


Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ shouldbe
six
Cython
k5test
decorator