1 |
|
|
2 |
import os |
import os |
3 |
from distutils.core import setup, Extension |
from distutils.core import setup, Extension |
4 |
|
from distutils.util import convert_path |
5 |
|
|
6 |
# try to determine the directory where the shapelib source files are. |
# try to determine the directory where the shapelib source files are. |
7 |
# There are currently two supported situations. |
# There are currently two supported situations. |
8 |
# |
# |
9 |
# 1. "Standalone" build: the parent directory is the shapelib source |
# 1. "Standalone" build: the parent directory is the shapelib source |
10 |
# directory |
# directory |
11 |
# 2. Built in the Thuban source tree where it's ../shapelib/ relative to |
# 2. Built in the Thuban source tree where ../shapelib/ relative to the |
12 |
# the directory containing this setup.py |
# directory containing this setup.py contains (the relevant parts of) |
13 |
|
# shapelib |
14 |
|
|
15 |
# os.path expects filenames in OS-specific form so we have to construct |
# os.path expects filenames in OS-specific form so we have to construct |
16 |
# the files with os.path functions. distutils, OTOH, uses posix-style |
# the files with os.path functions. distutils, OTOH, uses posix-style |
17 |
# filenames exclusively, so we posix when making filenames for |
# filenames exclusively, so we use posix conventions when making |
18 |
# distutils. |
# filenames for distutils. |
19 |
if os.path.exists(os.path.join(os.pardir, "shpeopen.c")): |
for shp_dir in ["..", "../shapelib"]: |
20 |
shp_dir = ".." |
if os.path.exists(os.path.join(convert_path(shp_dir), "shpopen.c")): |
21 |
elif os.path.exists(os.path.join(os.pardir, "shapelib")): |
# shp_dir contains shpopen.c, so assume it's the directory with |
22 |
shp_dir = "../shapelib" |
# the shapefile library to use |
23 |
|
break |
24 |
|
|
25 |
|
def dbf_macros(): |
26 |
|
"""Return the macros to define when compiling the dbflib wrapper. |
27 |
|
|
28 |
|
The returned list specifies one macro, HAVE_UPDATE_HEADER, which is |
29 |
|
'1' if the dbflib version we will be compiling with has the |
30 |
|
DBFUpdateHeader function and '0' otherwise. To check whether |
31 |
|
DBFUpdateHeader is available, we scan shapefil.h for the string |
32 |
|
'DBFUpdateHeader'. |
33 |
|
""" |
34 |
|
f = open(convert_path(shp_dir + "/shapefil.h")) |
35 |
|
contents = f.read() |
36 |
|
f.close() |
37 |
|
print contents.find("DBFUpdateHeader") |
38 |
|
if contents.find("DBFUpdateHeader") >= 0: |
39 |
|
return [("HAVE_UPDATE_HEADER", "1")] |
40 |
|
else: |
41 |
|
return [("HAVE_UPDATE_HEADER", "0")] |
42 |
|
|
43 |
extensions = [Extension("shapelibc", |
extensions = [Extension("shapelibc", |
44 |
["shapelib_wrap.c", |
["shapelib_wrap.c", |
51 |
Extension("dbflibc", |
Extension("dbflibc", |
52 |
["dbflib_wrap.c", |
["dbflib_wrap.c", |
53 |
shp_dir + "/dbfopen.c"], |
shp_dir + "/dbfopen.c"], |
54 |
include_dirs = [shp_dir])] |
include_dirs = [shp_dir], |
55 |
|
define_macros = dbf_macros())] |
56 |
|
|
57 |
setup(name = "pyshapelib", |
setup(name = "pyshapelib", |
58 |
version = "0.3", |
version = "0.3", |