Skip to content

Commit

Permalink
Add os.add_dll_directory path loading for Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
geographika committed Jan 29, 2021
1 parent 348f306 commit a49cfbd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions mapscript/python/mapscript/__init__.py
@@ -1,6 +1,34 @@
import sys
import platform
import os
import inspect

# As of Python 3.8 PATH can no longer be used to resolve the MapServer
# DLLs on Windows. Instead users will be required to set a new MAPSERVER_DLL_PATH
# environment variable.
# See https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-python-api


def add_dll_path(pth):
if (3, 8) <= sys.version_info:
os.add_dll_directory(pth)
else:
# add the directory to the Windows path for earlier Python version
os.environ['PATH'] = pth + ';' + os.environ['PATH']


if platform.system() == 'Windows':
mapserver_dll_path = os.getenv('MAPSERVER_DLL_PATH', '')
dll_paths = mapserver_dll_path.split(';')
# add paths in the order listed in the string
dll_paths.reverse()
for pth in dll_paths:
add_dll_path(pth)


from .mapscript import *


# change all the class module names from mapscript.mapscript to mapscript

for key, value in globals().copy().items():
Expand Down

0 comments on commit a49cfbd

Please sign in to comment.