File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3838
3939import itertools
4040import os
41+ import sys
4142import warnings
4243
4344def bootstrap_env ():
@@ -63,6 +64,22 @@ def bootstrap_env():
6364
6465bootstrap_env ()
6566
67+ # In some build/test setups the compiled extension can be imported under the
68+ # top-level name `_mapnik` (e.g. due to sys.path/build output layout) and then
69+ # again as `mapnik._mapnik`. Loading the same pybind11 extension twice in one
70+ # interpreter can raise errors like:
71+ # pybind11::native_enum<...>("CompositeOp") is already registered!
72+ # If a compatible `_mapnik` is already loaded, alias it to the canonical
73+ # `mapnik._mapnik` name before importing symbols.
74+ _canonical_ext_name = f"{ __name__ } ._mapnik"
75+ if _canonical_ext_name in sys .modules :
76+ pass
77+ elif "_mapnik" in sys .modules :
78+ _candidate = sys .modules ["_mapnik" ]
79+ # Heuristic guard: only alias if it looks like our Mapnik extension.
80+ if hasattr (_candidate , "Map" ) and hasattr (_candidate , "version_string" ):
81+ sys .modules [_canonical_ext_name ] = _candidate
82+
6683from ._mapnik import *
6784
6885def Shapefile (** keywords ):
You can’t perform that action at this time.
0 commit comments