Skip to content

Commit

Permalink
Add compatibility for Python before 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Meister committed Apr 16, 2024
1 parent 67753ca commit 13d4613
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions libconcord/bindings/python/libconcord.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,30 @@
# Load the DLL

if platform.system() == 'Windows':
with os.add_dll_directory(os.path.dirname(__file__)):
_dll = cdll.LoadLibrary('libconcord-%i.dll' % ABI_VERSION)
# Python 3.8+ does not use PATH to find DLLs, you can add a search path by
# using os.add_dll_directory as shown below. If you are locating the DLLs
# outside of the package directory, simply call os.add_dll_directory as
# shown before importing this file.
#
# Here we are adding the path to search for DLL files bundled with the
# package.
try:
with os.add_dll_directory(os.path.dirname(__file__)):
_dll = cdll.LoadLibrary('libconcord-%i.dll' % ABI_VERSION)
except:
# If we're on an old version of Python, os.add_dll_directory is not
# available, but PATH is, so let's use it, and restore it after loading
# the DLL and dependencies. (It's not enough to specify the path in the
# call to LoadLibrary.) Changes are temporary and only for this process.
syspath = os.environ['PATH']
os.environ['PATH'] = syspath + ";" + os.path.dirname(__file__)
try:
_dll = cdll.LoadLibrary('libconcord-%i.dll' % ABI_VERSION)
except:
os.environ['PATH'] = syspath
raise
os.environ['PATH'] = syspath

elif platform.system() == 'Darwin':
_dll = cdll.LoadLibrary('libconcord.%i.dylib' % ABI_VERSION)
else:
Expand Down

0 comments on commit 13d4613

Please sign in to comment.