-
-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy path__init__.py
More file actions
42 lines (31 loc) · 1.25 KB
/
__init__.py
File metadata and controls
42 lines (31 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import inspect
import os
import platform
import sys
# 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):
"""
Allow Python to access the directory containing the MapServer DLL (for Python on Windows only)
"""
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 = list(filter(os.path.exists, 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 * # NOQA
# change all the class module names from mapscript.mapscript to mapscript
for key, value in globals().copy().items():
if inspect.isclass(value) and value.__module__.startswith("mapscript."):
value.__module__ = "mapscript"
# remove the submodule name
del mapscript # NOQA