Created
November 17, 2013 07:28
-
-
Save dakcarto/7510460 to your computer and use it in GitHub Desktop.
Update pyspatialite 3.0.1 for a dynamic-linking spatialite/sqlite build on Mac with libspatialite 4.1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 74985c2c228cac37420eadea7dfa89848df8581f Mon Sep 17 00:00:00 2001 | |
From: Larry Shaffer <larrys@dakotacarto.com> | |
Date: Tue, 22 Oct 2013 20:03:16 -0600 | |
Subject: [PATCH] [pyspatialite] Update setup.py for dynamic-linking | |
spatialite/sqlite build (libspatialite 4.1+) | |
- Remove libspatialite amalgamation download, as it is no longer offered | |
- Remove hard-coded paths for Mac, since they are not defaults, but one type of install | |
--- | |
setup.py | 47 +++++------------------------------------------ | |
1 file changed, 5 insertions(+), 42 deletions(-) | |
diff --git a/setup.py b/setup.py | |
index 4725e99..0b6bcf6 100644 | |
--- a/setup.py | |
+++ b/setup.py | |
@@ -44,7 +44,7 @@ sources = ["src/module.c", "src/connection.c", "src/cursor.c", "src/cache.c", | |
include_dirs = [] | |
library_dirs = [] | |
-libraries = ['geos','geos_c','proj'] | |
+libraries = ['geos','geos_c','proj', 'spatialite', 'sqlite3'] | |
runtime_library_dirs = [] | |
extra_objects = [] | |
define_macros = [] | |
@@ -82,57 +82,20 @@ class DocBuilder(Command): | |
if rc != 0: | |
print "Is sphinx installed? If not, try 'sudo easy_install sphinx'." | |
-AMALGAMATION_ROOT = "amalgamation" | |
- | |
-def get_amalgamation(): | |
- """Download the Spatialite amalgamation if it isn't there, already.""" | |
- if os.path.exists(AMALGAMATION_ROOT): | |
- return | |
- os.mkdir(AMALGAMATION_ROOT) | |
- print "Downloading amalgation." | |
- | |
- # find out what's current amalgamation ZIP file | |
- download_page = urllib.urlopen("https://www.gaia-gis.it/fossil/libspatialite/index").read() | |
- pattern = re.compile("(libspatialite-amalgamation.*?\.zip)") | |
- download_file = pattern.findall(download_page)[0] | |
- amalgamation_url = "http://www.gaia-gis.it/gaia-sins/" + download_file | |
- zip_dir = string.replace(download_file,'.zip','') | |
- # and download it | |
- urllib.urlretrieve(amalgamation_url, "tmp.zip") | |
- | |
- zf = zipfile.ZipFile("tmp.zip") | |
- files = ["sqlite3.c", "headers/spatialite/sqlite3.h", "spatialite.c", "headers/spatialite/sqlite3ext.h","headers/spatialite/spatialite.h","headers/spatialite/gaiaaux.h","headers/spatialite/gaiaexif.h","headers/spatialite/gaiageo.h"] | |
- for fn in files: | |
- print "Extracting", fn | |
- outf = open(AMALGAMATION_ROOT + os.sep + string.split(fn,'/')[-1], "wb") | |
- outf.write(zf.read(zip_dir + '/' + fn)) | |
- outf.close() | |
- zf.close() | |
- os.unlink("tmp.zip") | |
- | |
class MyBuildExt(build_ext): | |
def build_extension(self, ext): | |
- get_amalgamation() | |
# sometimes iconv is built in, sometimes it isn't | |
- if not self.compiler.has_function("iconv"): | |
- ext.libraries.append("iconv") | |
- | |
- #Default locations for Mac | |
- ext.include_dirs.append("/Library/Frameworks/GEOS.framework/unix/include/") | |
- ext.include_dirs.append("/Library/Frameworks/PROJ.framework/unix/include/") | |
- ext.library_dirs.append("/Library/Frameworks/GEOS.framework/unix/lib") | |
- ext.library_dirs.append("/Library/Frameworks/PROJ.framework/unix/lib") | |
+ if sys.platform.startswith("darwin") or not self.compiler.has_function("iconv"): | |
+ ext.libraries.append("iconv") | |
ext.define_macros.append(("SQLITE_ENABLE_FTS3", "1")) # build with fulltext search enabled | |
ext.define_macros.append(("SQLITE_ENABLE_RTREE", "1")) # build with fulltext search enabled | |
ext.define_macros.append(("SQLITE_ENABLE_COLUMN_METADATA", "1")) # build with fulltext search enabled | |
ext.define_macros.append(("OMIT_FREEXL","1")) # build without FreeXL | |
- ext.sources.append(os.path.join(AMALGAMATION_ROOT, "sqlite3.c")) | |
- ext.sources.append(os.path.join(AMALGAMATION_ROOT, "spatialite.c")) | |
- ext.include_dirs.append(AMALGAMATION_ROOT) | |
+ | |
build_ext.build_extension(self, ext) | |
- | |
+ | |
# def __setattr__(self, k, v): | |
# # Make sure we don't link against the SQLite library, no matter what setup.cfg says | |
-- | |
1.7.11.1 | |
From e311830786cfb709548ecb9d0b2a627184e2af2b Mon Sep 17 00:00:00 2001 | |
From: Larry Shaffer <larrys@dakotacarto.com> | |
Date: Tue, 22 Oct 2013 20:15:31 -0600 | |
Subject: [PATCH] [pyspatialite] Add setup.cfg template for typical Mac GIS | |
installs of supporting libs | |
- Caveat: should probably add conditional to setup.py to pause build and notify user of renaming and configuring template, if platform is darwin | |
--- | |
setup.cfg-MacOSX | 13 +++++++++++++ | |
1 file changed, 13 insertions(+) | |
create mode 100644 setup.cfg-MacOSX | |
diff --git a/setup.cfg-MacOSX b/setup.cfg-MacOSX | |
new file mode 100644 | |
index 0000000..bba6289 | |
--- /dev/null | |
+++ b/setup.cfg-MacOSX | |
@@ -0,0 +1,13 @@ | |
+# The options to build the '_spatialite' extension. | |
+ | |
+[build_ext] | |
+ | |
+# (Mac) Kyngchaos.com frameworks | |
+include_dirs=/Library/Frameworks/GEOS.framework/unix/include:/Library/Frameworks/PROJ.framework/unix/include:/Library/Frameworks/SQLite3.framework/unix/include | |
+# (Mac) homebrew | |
+#include_dirs=/usr/local/include/:/usr/local/opt/sqlite/include/ | |
+ | |
+# (Mac) Kyngchaos.com frameworks | |
+library_dirs=/Library/Frameworks/GEOS.framework/unix/lib:/Library/Frameworks/PROJ.framework/unix/lib:/Library/Frameworks/SQLite3.framework/unix/lib | |
+# (Mac) homebrew | |
+#library_dirs=/usr/local/lib:/usr/local/opt/sqlite/lib | |
-- | |
1.7.11.1 | |
From 741415414be8b6262cc0a707bffccdac9e4acaa5 Mon Sep 17 00:00:00 2001 | |
From: Larry Shaffer <larrys@dakotacarto.com> | |
Date: Tue, 22 Oct 2013 21:42:27 -0600 | |
Subject: [PATCH] [pyspatialite] Conditionally set macro to avoid | |
redeclaration of some functions | |
--- | |
setup.py | 4 ++++ | |
src/connection.h | 2 ++ | |
2 files changed, 6 insertions(+) | |
diff --git a/setup.py b/setup.py | |
index 0b6bcf6..946a9c7 100644 | |
--- a/setup.py | |
+++ b/setup.py | |
@@ -89,6 +89,10 @@ class MyBuildExt(build_ext): | |
if sys.platform.startswith("darwin") or not self.compiler.has_function("iconv"): | |
ext.libraries.append("iconv") | |
+ # set macro to avoid redeclaration of some functions | |
+ if self.compiler.has_function("spatialite_init", libraries=["spatialite"]): | |
+ ext.define_macros.append(("SPATIALITE_EXTERN", "1")) | |
+ | |
ext.define_macros.append(("SQLITE_ENABLE_FTS3", "1")) # build with fulltext search enabled | |
ext.define_macros.append(("SQLITE_ENABLE_RTREE", "1")) # build with fulltext search enabled | |
ext.define_macros.append(("SQLITE_ENABLE_COLUMN_METADATA", "1")) # build with fulltext search enabled | |
diff --git a/src/connection.h b/src/connection.h | |
index e5d3d41..80b3012 100644 | |
--- a/src/connection.h | |
+++ b/src/connection.h | |
@@ -33,7 +33,9 @@ | |
#include "sqlite3.h" | |
#include "spatialite.h" | |
+#ifndef SPATIALITE_EXTERN | |
int spatialite_init(int verbose); | |
+#endif | |
typedef struct | |
{ | |
-- | |
1.7.11.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment