From fda0df9cb4d6bf6c2c703234eeab1ebeb4ac6260 Mon Sep 17 00:00:00 2001 From: Francesco Bartoli Date: Wed, 29 Jan 2020 00:16:09 +0100 Subject: [PATCH] Fix #349 (#350) --- docs/source/devel.rst | 44 +++++++++++++++++++++++++++++++++++++ docs/source/index.rst | 1 + pygeoapi/provider/sqlite.py | 7 +++++- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 docs/source/devel.rst diff --git a/docs/source/devel.rst b/docs/source/devel.rst new file mode 100644 index 0000000..8c43dd3 --- /dev/null +++ b/docs/source/devel.rst @@ -0,0 +1,44 @@ +.. _devel: + +OSX Developers +============== + +Using pyenv +----------- + +It is common among OSX developers to use the package manager homebrew for the installation of pyenv to being able to manage multiple versions of Python. +They can encounter errors about the load of some SQLite extensions that pygeoapi uses for handling spatial data formats. In order to run properly the server +you are required to follow these steps below carefully. + +Make Homebrew and pyenv play nicely together:: + +.. code-block:: console + + # see https://github.com/pyenv/pyenv/issues/106 + alias brew='env PATH=${PATH//$(pyenv root)\/shims:/} brew' + +Install python with the option to enable SQLite extensions:: + +.. code-block:: console + + LDFLAGS="-L/usr/local/opt/sqlite/lib -L/usr/local/opt/zlib/lib" CPPFLAGS="-I/usr/local/opt/sqlite/include -I/usr/local/opt/zlib/include" PYTHON_CONFIGURE_OPTS="--enable-loadable-sqlite-extensions" pyenv install 3.7.6 + +Configure SQLite from Homebrew over that one shipped with the OS:: + +.. code-block:: console + + export PATH="/usr/local/opt/sqlite/bin:$PATH" + +Install Spatialite from Homebrew:: + +.. code-block:: console + + brew update + brew install spatialite-tools + brew libspatialite + +Set the variable for the Spatialite library under OSX:: + +.. code-block:: console + + SPATIALITE_LIBRARY_PATH=/usr/local/lib/mod_spatialite.dylib diff --git a/docs/source/index.rst b/docs/source/index.rst index 7995741..5ebf84f 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -16,6 +16,7 @@ Welcome to pygeoapi's documentation! install openapi docker + devel wsgi asgi configuration diff --git a/pygeoapi/provider/sqlite.py b/pygeoapi/provider/sqlite.py index 2a60323..dd239a4 100644 --- a/pygeoapi/provider/sqlite.py +++ b/pygeoapi/provider/sqlite.py @@ -2,9 +2,11 @@ # # Authors: Jorge Samuel Mendes de Jesus # Tom Kralidis +# Francesco Bartoli # # Copyright (c) 2018 Jorge Samuel Mendes de Jesus # Copyright (c) 2019 Tom Kralidis +# Copyright (c) 2020 Francesco Bartoli # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation @@ -39,6 +41,9 @@ from pygeoapi.provider.base import BaseProvider, ProviderConnectionError LOGGER = logging.getLogger(__name__) +SPATIALITE_EXTENSION = os.getenv('SPATIALITE_LIBRARY_PATH', 'mod_spatialite.so') + + class SQLiteGPKGProvider(BaseProvider): """Generic provider for SQLITE and GPKG using sqlite3 module. This module requires install of libsqlite3-mod-spatialite @@ -147,7 +152,7 @@ class SQLiteGPKGProvider(BaseProvider): # conn.set_trace_callback(LOGGER.debug) cursor = conn.cursor() try: - cursor.execute("SELECT load_extension('mod_spatialite.so')") + cursor.execute(f"SELECT load_extension('{SPATIALITE_EXTENSION}')") except sqlite3.OperationalError as err: LOGGER.error('Extension loading error: {}'.format(err)) raise ProviderConnectionError()