Permalink
Browse files

Fixed #29484 -- Removed the need to specify SPATIALITE_LIBRARY_PATH w…

…ith Spatialite 4.2+.

Thanks Tim Graham for the review.
  • Loading branch information...
claudep committed Jun 1, 2018
1 parent 86988dd commit f3836144db1dc05bce5a2a1cc7e46a01b0f67db6
Showing with 22 additions and 18 deletions.
  1. +22 −12 django/contrib/gis/db/backends/spatialite/base.py
  2. +0 −6 docs/ref/contrib/gis/install/spatialite.txt
@@ -27,13 +27,12 @@ def __init__(self, *args, **kwargs):
# (`libspatialite`). If it's not in the system library path (e.g., it
# cannot be found by `ctypes.util.find_library`), then it may be set
# manually in the settings via the `SPATIALITE_LIBRARY_PATH` setting.
- self.spatialite_lib = getattr(settings, 'SPATIALITE_LIBRARY_PATH',
- find_library('spatialite'))
- if not self.spatialite_lib:
- raise ImproperlyConfigured('Unable to locate the SpatiaLite library. '
- 'Make sure it is in your library path, or set '
- 'SPATIALITE_LIBRARY_PATH in your settings.'
- )
+ self.lib_spatialite_paths = [name for name in [
+ getattr(settings, 'SPATIALITE_LIBRARY_PATH', None),
+ 'mod_spatialite.so',
+ 'mod_spatialite',
+ find_library('spatialite'),
+ ] if name is not None]
super().__init__(*args, **kwargs)
def get_new_connection(self, conn_params):
@@ -47,12 +46,23 @@ def get_new_connection(self, conn_params):
'extension loading.'
)
# Load the SpatiaLite library extension on the connection.
- try:
- conn.load_extension(self.spatialite_lib)
- except Exception as exc:
+ for path in self.lib_spatialite_paths:
+ try:
+ conn.load_extension(path)
+ except Exception:
+ if getattr(settings, 'SPATIALITE_LIBRARY_PATH', None):
+ raise ImproperlyConfigured(
+ 'Unable to load the SpatiaLite library extension '
+ 'as specified in your SPATIALITE_LIBRARY_PATH setting.'
+ )
+ continue
+ else:
+ break
+ else:
raise ImproperlyConfigured(
- 'Unable to load the SpatiaLite library extension "%s"' % self.spatialite_lib
- ) from exc
+ 'Unable to load the SpatiaLite library extension. '
+ 'Library names tried: %s' % ', '.join(self.lib_spatialite_paths)
+ )
return conn
def prepare_database(self):
@@ -21,12 +21,6 @@ In any case, you should always be able to :ref:`install from source
__ https://www.gaia-gis.it/fossil/libspatialite
__ https://www.gaia-gis.it/gaia-sins/
-.. admonition:: ``SPATIALITE_LIBRARY_PATH`` setting required for SpatiaLite 4.2+
-
- If you're using SpatiaLite 4.2+, you must put this in your ``settings.py``::
-
- SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
-
.. _spatialite_source:
Installing from source

0 comments on commit f383614

Please sign in to comment.