As of mapnik commit 14700dba16146902ca98fdcacb72b2fba4fa596a, using 'import mapnik2' raises a DeprecationWarning. See https://github.com/mapnik/mapnik/issues/941 for details.
Update imports of the mapnik module to use 'import mapnik' and assert that the installed version is new enough. We need mapnik 2.1.0 (or at least a version newer than 2.0.0 that supports placement-type="simple") for the Printable Stylesheet, as per David's suggestion. Thomas pointed out that the note and assert won't be needed in all places that import mapnik, this patch takes that into account. CC: [email protected] CC: [email protected] Tested-by: Jeroen van Rijn <[email protected]> Signed-off-by: Jeroen van Rijn <[email protected]> --- INSTALL | 17 ++++++++++------- ocitysmap2/coords.py | 13 +++++++++---- ocitysmap2/layoutlib/abstract_renderer.py | 5 +---- ocitysmap2/layoutlib/multi_page_renderer.py | 5 +---- ocitysmap2/layoutlib/single_page_renderers.py | 5 +---- ocitysmap2/maplib/map_canvas.py | 14 ++++++++++---- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/INSTALL b/INSTALL index c82157e..8c73d93 100644 --- a/INSTALL +++ b/INSTALL @@ -166,16 +166,19 @@ are using. They have been tested on several x86_64 hosts. libboost-regex1.46-dev libboost-serialization1.46-dev \ libboost-system1.46-dev libboost-thread1.46-dev - b. Download Mapnik + b. Download the latest Mapnik from its Git repository - wget http://download.berlios.de/mapnik/mapnik-2.0.0.tar.bz2 + git clone git://github.com/mapnik/mapnik.git - c. Compile and install Mapnik 2 + This implicitly runs 'git checkout HEAD', giving you the latest version. + Should you run into trouble either installing or running this latest version, + you can use the version we know to work: - tar xvjf mapnik-2.0.0.tar.bz2 - cd mapnik-2.0.0 + git checkout c88fcc8f046138fb9fb73bdb42dfed1e9c4b86cd # dated Tue Apr 3 - (any version >= 2.0.0 should follow the same scheme) + c. Compile and install Mapnik + + cd mapnik python scons/scons.py configure INPUT_PLUGINS=all \ OPTIMIZATION=3 SYSTEM_FONTS=/usr/share/fonts/ @@ -189,7 +192,7 @@ are using. They have been tested on several x86_64 hosts. d. Check the installation - Run a Python interpreter, and run "import mapnik2". If it doesn't + Run a Python interpreter, and run "import mapnik". If it doesn't work and you didn't do a system-wide installation of Mapnik, don't forget to set the PYTHONPATH and LD_LIBRARY_PATH environment variables. diff --git a/ocitysmap2/coords.py b/ocitysmap2/coords.py index 3050c71..5d023a7 100644 --- a/ocitysmap2/coords.py +++ b/ocitysmap2/coords.py @@ -25,10 +25,15 @@ import math import shapely.wkt -try: - import mapnik2 as mapnik -except ImportError: - import mapnik + +# Importing mapnik2 raises a DeprecationWarning as of mapnik +# commit 14700dba16146902ca98fdcacb72b2fba4fa596a +# As mapnik 2.1 (or git version with support for placement-type="simple") +# is required for OCitySMap (see INSTALL), instead of importing mapnik2, +# we import mapnik and assert it isn't an old version. +import mapnik +assert mapnik.mapnik_version >= 200000, "Mapnik module version %s too old, see ocitysmap's INSTALL for more details." \ + % mapnik.mapnik_version_string() _MAPNIK_PROJECTION = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 " \ "+lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m " \ diff --git a/ocitysmap2/layoutlib/abstract_renderer.py b/ocitysmap2/layoutlib/abstract_renderer.py index 5517ab9..1e6e5f8 100644 --- a/ocitysmap2/layoutlib/abstract_renderer.py +++ b/ocitysmap2/layoutlib/abstract_renderer.py @@ -27,10 +27,7 @@ import math import os import sys import cairo -try: - import mapnik2 as mapnik -except ImportError: - import mapnik +import mapnik import pango import re diff --git a/ocitysmap2/layoutlib/multi_page_renderer.py b/ocitysmap2/layoutlib/multi_page_renderer.py index e41af24..71d3b75 100644 --- a/ocitysmap2/layoutlib/multi_page_renderer.py +++ b/ocitysmap2/layoutlib/multi_page_renderer.py @@ -25,10 +25,7 @@ import tempfile import math import sys import cairo -try: - import mapnik2 as mapnik -except ImportError: - import mapnik +import mapnik import coords import locale import pangocairo diff --git a/ocitysmap2/layoutlib/single_page_renderers.py b/ocitysmap2/layoutlib/single_page_renderers.py index 172f8bf..c775d16 100644 --- a/ocitysmap2/layoutlib/single_page_renderers.py +++ b/ocitysmap2/layoutlib/single_page_renderers.py @@ -26,10 +26,7 @@ import math import datetime import cairo import locale -try: - import mapnik2 as mapnik -except ImportError: - import mapnik +import mapnik import pango import pangocairo diff --git a/ocitysmap2/maplib/map_canvas.py b/ocitysmap2/maplib/map_canvas.py index 444a5ff..9e440cd 100644 --- a/ocitysmap2/maplib/map_canvas.py +++ b/ocitysmap2/maplib/map_canvas.py @@ -23,10 +23,16 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import logging -try: - import mapnik2 as mapnik -except ImportError: - import mapnik + +# Importing mapnik2 raises a DeprecationWarning as of mapnik +# commit 14700dba16146902ca98fdcacb72b2fba4fa596a +# As mapnik 2.1 (or git version with support for placement-type="simple") +# is required for OCitySMap (see INSTALL), instead of importing mapnik2, +# we import mapnik and assert it isn't an old version. +import mapnik +assert mapnik.mapnik_version >= 200000, "Mapnik module version %s too old, see ocitysmap's INSTALL for more details." \ + % mapnik.mapnik_version_string() + import os from ocitysmap2 import coords -- 1.7.10.rc1.22.gf5241
