1 |
# Copyright (c) 2001, 2002 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
17 |
|
|
18 |
import os |
import os |
19 |
from types import TupleType |
from types import TupleType |
20 |
|
import glob |
21 |
from distutils.core import setup, Extension, Command |
from distutils.core import setup, Extension, Command |
22 |
from distutils.command.install import install, INSTALL_SCHEMES, subst_vars |
from distutils.command.install import install, INSTALL_SCHEMES, subst_vars |
23 |
from distutils.command.build_py import build_py |
from distutils.command.build_py import build_py |
24 |
from distutils.command.bdist_rpm import bdist_rpm |
from distutils.command.bdist_rpm import bdist_rpm |
25 |
|
from distutils.command.build_ext import build_ext |
26 |
from distutils.file_util import write_file |
from distutils.file_util import write_file |
27 |
from distutils.filelist import FileList |
from distutils.filelist import FileList |
28 |
from distutils.util import convert_path, change_root |
from distutils.util import convert_path, change_root |
33 |
from string import split |
from string import split |
34 |
import string |
import string |
35 |
|
|
36 |
|
# config script parameter list indices |
37 |
|
CS_DEFS, CS_INCDIRS, CS_LIBDIRS, CS_LIBS, CS_NUM_PARAMS = range(5) |
38 |
|
|
39 |
|
# support for gdal is on by default, but under posix we try to |
40 |
|
# detect it anyway. Set this to False to disable GDAL. |
41 |
|
include_gdal = True |
42 |
|
|
43 |
if os.name == "posix": |
if os.name == "posix": |
44 |
################################################################### |
################################################################### |
45 |
# Posix configuration. Adapt this if you're running some kind of |
# Posix configuration. Adapt this if you're running some kind of |
60 |
# with the install command's --prefix option. |
# with the install command's --prefix option. |
61 |
# |
# |
62 |
# Note that there's a separate prefix option for the bdist_rpm |
# Note that there's a separate prefix option for the bdist_rpm |
63 |
# command completely independend of this one. |
# command completely independent of this one. |
64 |
prefix = "/usr/local/" |
prefix = "/usr/local/" |
65 |
|
|
66 |
# Whether to create the thubaninit module. You can override this |
# Whether to create the thubaninit module. You can override this |
72 |
# flags |
# flags |
73 |
wx_config_script = "wx-config" |
wx_config_script = "wx-config" |
74 |
# These lists will be filled automatically below |
# These lists will be filled automatically below |
75 |
wx_defs = [] |
wx_cs_params = [[] for i in range(CS_NUM_PARAMS)] |
76 |
wx_incdirs = [] |
|
77 |
wx_libdirs = [] |
gdal_config_script = "gdal-config" |
78 |
wx_libs = [] |
gdal_cs_params = [[] for i in range(CS_NUM_PARAMS)] |
79 |
|
|
80 |
elif os.name == "nt": |
elif os.name == "nt": |
81 |
################################################################# |
################################################################# |
83 |
# |
# |
84 |
|
|
85 |
# Directories where Proj4 is installed |
# Directories where Proj4 is installed |
86 |
proj4_prefix = r"D:\cygwin\home\user\proj-4.4.3\src" |
proj4_prefix = r"D:\cygwin\home\user\proj-4.4.7\src" |
87 |
proj4_incdir = proj4_prefix |
proj4_incdir = proj4_prefix |
88 |
proj4_libdir = proj4_prefix |
proj4_libdir = proj4_prefix |
89 |
proj4_lib = "proj_i" |
proj4_lib = "proj_i" |
90 |
|
|
91 |
# Define include and lib directories for wxWindows and |
# Define include and lib directories for wxWindows and |
92 |
wx_prefix = r"D:\wx230" |
#wx_prefix = r"D:\cygwin\home\user\project\greater\wxPython-2.4.0.4" |
93 |
wx_inc = os.path.join(wx_prefix, "include") |
wx_prefix = r"D:\wx-sources\wxPythonSrc-2.4.0.7" |
94 |
wx_lib = os.path.join(wx_prefix, "lib") |
wx_inc = [os.path.join(wx_prefix, 'lib', 'mswdll'), |
95 |
|
os.path.join(wx_prefix, "include")] |
96 |
|
wx_lib = [os.path.join(wx_prefix, "lib")] |
97 |
|
|
98 |
|
# Define include and lib directories for GDAL |
99 |
|
gdal_prefix = r"D:\cygwin\home\user\build\gdal-1.1.8" |
100 |
|
gdal_inc = [os.path.join(gdal_prefix, 'alg'), |
101 |
|
os.path.join(gdal_prefix, 'ogr'), |
102 |
|
os.path.join(gdal_prefix, 'port'), |
103 |
|
os.path.join(gdal_prefix, 'core')] |
104 |
|
gdal_lib = [gdal_prefix] |
105 |
|
|
106 |
# |
# |
107 |
# Unless you use a wxPython version other than 2.3.1, you probably |
# Unless you use a wxPython version other than 2.4.0, you probably |
108 |
# shouldn't have to modify anything below here |
# shouldn't have to modify anything below here |
109 |
################################################################## |
################################################################## |
110 |
|
|
128 |
# there's no config script. |
# there's no config script. |
129 |
wx_config_script = "" |
wx_config_script = "" |
130 |
|
|
131 |
|
wx_cs_params = [[] for i in range(CS_NUM_PARAMS)] |
132 |
|
|
133 |
# the values of wx_defs and wx_libs. copied from the wxPython |
# the values of wx_defs and wx_libs. copied from the wxPython |
134 |
# setup.py |
# setup.py |
135 |
wx_defs = [ ('WIN32', None), # Some of these are no longer |
wx_cs_params[CS_DEFS] = \ |
136 |
|
[ ('WIN32', None), # Some of these are no longer |
137 |
('__WIN32__', None), # necessary. Anybody know which? |
('__WIN32__', None), # necessary. Anybody know which? |
138 |
('_WINDOWS', None), |
('_WINDOWS', None), |
139 |
('__WINDOWS__', None), |
('__WINDOWS__', None), |
149 |
('WXP_USE_THREAD', '1'), |
('WXP_USE_THREAD', '1'), |
150 |
] |
] |
151 |
|
|
152 |
wx_incdirs = [wx_inc] |
wx_cs_params[CS_INCDIRS] = wx_inc |
153 |
wx_libdirs = [wx_lib] |
wx_cs_params[CS_LIBDIRS] = wx_lib |
154 |
wx_libs = ["wx23_1h"] |
wx_cs_params[CS_LIBS] = ["wxmsw24"] \ |
155 |
wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32', |
+ ['kernel32', 'user32', 'gdi32', 'comdlg32', |
156 |
'winspool', 'winmm', 'shell32', 'oldnames', |
'winspool', 'winmm', 'shell32', 'oldnames', |
157 |
'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', |
'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', |
158 |
'uuid', 'rpcrt4', 'advapi32', 'wsock32'] |
'uuid', 'rpcrt4', 'advapi32', 'wsock32'] |
159 |
|
|
160 |
|
gdal_config_script = "" |
161 |
|
gdal_cs_params = [[] for i in range(CS_NUM_PARAMS)] |
162 |
|
|
163 |
|
gdal_cs_params[CS_INCDIRS] = gdal_inc |
164 |
|
gdal_cs_params[CS_LIBDIRS] = gdal_lib |
165 |
|
gdal_cs_params[CS_LIBS] = ["gdal_i"] |
166 |
|
|
167 |
else: |
else: |
168 |
raise RuntimeError("Unsupported platform " + os.name) |
raise RuntimeError("Unsupported platform " + os.name) |
169 |
|
|
190 |
return result |
return result |
191 |
|
|
192 |
|
|
193 |
def run_wx_script(command): |
def run_cs_script(command, store): |
194 |
# first, determine the C++ preprocessor flags Use --cflags here |
# first, determine the C++ preprocessor flags Use --cflags here |
195 |
# because it seems that older version don't have --cxxflags and |
# because it seems that older version don't have --cxxflags and |
196 |
# newer ones return the same result for both |
# newer ones return the same result for both |
197 |
flags = run_script(command + ' --cflags ') |
flags = run_script(command + ' --cflags ') |
198 |
if flags is None: |
if flags is None: |
199 |
return 0 |
return False |
200 |
for flag in split(flags): |
for flag in split(flags): |
201 |
start = flag[:2] |
start = flag[:2] |
202 |
value = flag[2:] |
value = flag[2:] |
203 |
if start == "-I": |
if start == "-I": |
204 |
wx_incdirs.append(value) |
store[CS_INCDIRS].append(value) |
205 |
elif start == "-D": |
elif start == "-D": |
206 |
wx_defs.append((value, None)) |
store[CS_DEFS].append((value, None)) |
207 |
|
|
208 |
# determine the library flags |
# determine the library flags |
209 |
flags = run_script(command + ' --libs') |
flags = run_script(command + ' --libs') |
210 |
if flags is None: |
if flags is None: |
211 |
return 0 |
return False |
212 |
for flag in split(flags): |
for flag in split(flags): |
213 |
start = flag[:2] |
start = flag[:2] |
214 |
value = flag[2:] |
value = flag[2:] |
215 |
if start == "-L": |
if start == "-L": |
216 |
wx_libdirs.append(value) |
store[CS_LIBDIRS].append(value) |
217 |
elif start == "-l": |
elif start == "-l": |
218 |
wx_libs.append(value) |
store[CS_LIBS].append(value) |
219 |
|
|
220 |
|
return True |
221 |
|
|
222 |
if wx_config_script: |
if wx_config_script: |
223 |
# if there's a wx config script, run it to determine the configuration |
# if there's a wx config script, run it to determine the configuration |
224 |
run_wx_script(wx_config_script) |
run_cs_script(wx_config_script, wx_cs_params) |
|
|
|
225 |
|
|
226 |
|
if gdal_config_script: |
227 |
|
# if there's a gdal config script, run it to determine the configuration |
228 |
|
include_gdal = include_gdal \ |
229 |
|
and run_cs_script(gdal_config_script, gdal_cs_params) |
230 |
|
|
231 |
# |
# |
232 |
# Define some extension and python modules |
# Define some extension and python modules |
254 |
[ext_dir + "/thuban/wxproj.cpp"], |
[ext_dir + "/thuban/wxproj.cpp"], |
255 |
include_dirs = ([shp_dir, proj4_incdir, |
include_dirs = ([shp_dir, proj4_incdir, |
256 |
ext_dir + "/pyshapelib/"] |
ext_dir + "/pyshapelib/"] |
257 |
+ wx_incdirs), |
+ wx_cs_params[CS_INCDIRS]), |
258 |
define_macros = wx_defs, |
define_macros = wx_cs_params[CS_DEFS], |
259 |
library_dirs = [proj4_libdir] + wx_libdirs, |
library_dirs = [proj4_libdir] + |
260 |
libraries = [proj4_lib] + wx_libs)) |
wx_cs_params[CS_LIBDIRS], |
261 |
|
libraries = [proj4_lib] + wx_cs_params[CS_LIBS])) |
262 |
|
|
263 |
|
|
264 |
# |
# |
265 |
# shapelib wrappers are also distributed with thuban |
# shapelib wrappers are also distributed with thuban |
298 |
data_files = [] |
data_files = [] |
299 |
|
|
300 |
# bitmaps |
# bitmaps |
301 |
dir = "Resources/Bitmaps" |
for d, pattern in [("Resources/Bitmaps", "Resources/Bitmaps/*.xpm"), |
302 |
bitmaps = [] |
("Resources/Locale", "Resources/Locale/*/LC_MESSAGES/*.mo") |
303 |
for file in os.listdir(os.path.join("Resources", "Bitmaps")): |
]: |
304 |
if string.lower(file[-4:]) == ".xpm": |
data_files.append((d, glob.glob(pattern))) |
|
bitmaps.append(dir + '/' + file) |
|
|
data_files.append((dir, bitmaps)) |
|
305 |
|
|
306 |
# |
# |
307 |
# Command definitions |
# Command definitions |
523 |
distribution. |
distribution. |
524 |
""" |
""" |
525 |
|
|
526 |
|
# FIXME: When Thuban can rely on Python 2.3 as the oldest supported |
527 |
|
# Python release we don't need to override the run and |
528 |
|
# find_all_modules methods anymore. distutils will allow both python |
529 |
|
# modules and packages starting with 2.3. |
530 |
|
|
531 |
def run(self): |
def run(self): |
532 |
"""The same the as the original in build_py revision 1.33 except |
"""The same the as the original in build_py revision 1.33 except |
533 |
that this allows both packages and modules to be in one |
that this allows both packages and modules to be in one |
638 |
("extra-files", None, |
("extra-files", None, |
639 |
"List of filenames or (src, dest) pairs describing" |
"List of filenames or (src, dest) pairs describing" |
640 |
" extra files to install " |
" extra files to install " |
641 |
"(can only be set from witin setup.py"), |
"(can only be set from within setup.py"), |
642 |
|
|
643 |
("create-init-module=", None, |
("create-init-module=", None, |
644 |
"If true, create a module in the site-packages" |
"If true, create a module in the site-packages" |
788 |
cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection} |
cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection} |
789 |
''' |
''' |
790 |
|
|
791 |
|
bdist_rpm_build_script = ''' |
792 |
|
env PATH="$PATH:%(prefix)s/lib/wxPython/bin:/usr/lib/wxPython/bin" CFLAGS="$RPM_OPT_FLAGS" %(python)s setup.py build |
793 |
|
''' |
794 |
|
|
795 |
bdist_rpm_install_script = ''' |
bdist_rpm_install_script = ''' |
796 |
%(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \ |
%(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \ |
797 |
--prefix=%(prefix)s |
--prefix=%(prefix)s |
815 |
# scripts such as the python interpreter to use are only known |
# scripts such as the python interpreter to use are only known |
816 |
# then. |
# then. |
817 |
open("bdist_rpm_prep", "w").close() |
open("bdist_rpm_prep", "w").close() |
818 |
|
open("bdist_rpm_build", "w").close() |
819 |
open("bdist_rpm_install", "w").close() |
open("bdist_rpm_install", "w").close() |
820 |
bdist_rpm.initialize_options(self) |
bdist_rpm.initialize_options(self) |
821 |
|
|
823 |
# create the scripts for the spec-file. Now we know the python |
# create the scripts for the spec-file. Now we know the python |
824 |
# interpreter to use. |
# interpreter to use. |
825 |
open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script) |
open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script) |
826 |
|
|
827 |
|
build = bdist_rpm_build_script % {"python": self.python, |
828 |
|
"prefix": self.prefix} |
829 |
|
open("bdist_rpm_build", "w").write(build) |
830 |
|
|
831 |
install = bdist_rpm_install_script % {"python": self.python, |
install = bdist_rpm_install_script % {"python": self.python, |
832 |
"prefix": self.prefix} |
"prefix": self.prefix} |
833 |
open("bdist_rpm_install", "w").write(install) |
open("bdist_rpm_install", "w").write(install) |
915 |
"""Execute the command. install_options if given, should be a |
"""Execute the command. install_options if given, should be a |
916 |
directory of additional options to set in the install step""" |
directory of additional options to set in the install step""" |
917 |
# Obviously have to build before we can install |
# Obviously have to build before we can install |
918 |
|
|
919 |
if not self.skip_build: |
if not self.skip_build: |
920 |
self.run_command('build') |
self.run_command('build') |
921 |
|
|
1028 |
def run(self): |
def run(self): |
1029 |
install_options = { |
install_options = { |
1030 |
"prefix": ".", |
"prefix": ".", |
1031 |
|
"install_lib": "$base", |
1032 |
|
"install_data": "$base", |
1033 |
"install_scripts": "$base", |
"install_scripts": "$base", |
1034 |
"warn_dir": 0, |
"warn_dir": 0, |
1035 |
"extra_files": ["COPYING", "Lib/proj.dll"], |
"extra_files": ["COPYING", "Lib/proj.dll"], |
1037 |
# don't make a symlink because we're simulating windows, so |
# don't make a symlink because we're simulating windows, so |
1038 |
# that we can generate the iss-file even on Linux |
# that we can generate the iss-file even on Linux |
1039 |
install_options["do_symlink"] = 0 |
install_options["do_symlink"] = 0 |
1040 |
|
|
1041 |
bdist_inno.run(self, install_options) |
bdist_inno.run(self, install_options) |
1042 |
|
|
1043 |
|
class thuban_build_docs(Command): |
1044 |
|
|
1045 |
|
"""Command to generate documentation from source code.""" |
1046 |
|
|
1047 |
|
description = "Generate documentation." |
1048 |
|
|
1049 |
|
user_options = [] |
1050 |
|
|
1051 |
|
def initialize_options(self): pass |
1052 |
|
|
1053 |
|
def finalize_options(self): pass |
1054 |
|
|
1055 |
|
def run(self, install_options = None): |
1056 |
|
self.spawn(["happydoc", "-d./Doc", "./Thuban"]) |
1057 |
|
|
1058 |
|
class thuban_build_ext(build_ext): |
1059 |
|
|
1060 |
|
"""Extend the build_ext command to optionally include the |
1061 |
|
GDAL extension. |
1062 |
|
""" |
1063 |
|
|
1064 |
|
user_options = build_ext.user_options[:] |
1065 |
|
user_options.extend([("with-gdal", None, "Include GDAL support."), |
1066 |
|
("without-gdal", None, "Don't include GDAL support.")]) |
1067 |
|
|
1068 |
|
boolean_options = ["with-gdal"] |
1069 |
|
negative_opt = {'without-gdal' : 'with-gdal'} |
1070 |
|
|
1071 |
|
def initialize_options(self): |
1072 |
|
self.with_gdal = True |
1073 |
|
build_ext.initialize_options(self) |
1074 |
|
|
1075 |
|
def finalize_options(self): |
1076 |
|
build_ext.finalize_options(self) |
1077 |
|
if self.with_gdal and include_gdal: |
1078 |
|
self.extensions.append(Extension("Lib.gdalwarp", |
1079 |
|
[ext_dir + "/thuban/gdalwarp.cpp", |
1080 |
|
ext_dir + "/thuban/cpl_mfile.cpp", |
1081 |
|
ext_dir + "/thuban/bmpdataset.cpp"], |
1082 |
|
include_dirs = gdal_cs_params[CS_INCDIRS] + |
1083 |
|
[ext_dir + "/thuban/"], |
1084 |
|
define_macros = gdal_cs_params[CS_DEFS], |
1085 |
|
library_dirs = gdal_cs_params[CS_LIBDIRS], |
1086 |
|
libraries = gdal_cs_params[CS_LIBS])) |
1087 |
|
|
1088 |
|
def run(self, install_options = None): |
1089 |
|
build_ext.run(self) |
1090 |
|
|
1091 |
# |
# |
1092 |
# Run the script |
# Run the script |
1093 |
# |
# |
1094 |
|
|
|
|
|
1095 |
long_description = """\ |
long_description = """\ |
1096 |
Thuban is a viewer for geographic data written in Python |
Thuban is a viewer for geographic data written in Python |
1097 |
""" |
""" |
1098 |
|
|
1099 |
setup(name = "Thuban", |
setup(name = "Thuban", |
1100 |
version = "0.1.3", |
version = "0.2.0", |
1101 |
description = "Geographic data viewer", |
description = "Geographic data viewer", |
1102 |
long_description = long_description, |
long_description = long_description, |
1103 |
licence = "GPL", |
licence = "GPL", |
1139 |
"install": ThubanInstall, |
"install": ThubanInstall, |
1140 |
"bdist_rpm": thuban_bdist_rpm, |
"bdist_rpm": thuban_bdist_rpm, |
1141 |
"bdist_inno": thuban_bdist_inno, |
"bdist_inno": thuban_bdist_inno, |
1142 |
"data_dist": data_dist |
"data_dist": data_dist, |
1143 |
|
"build_docs": thuban_build_docs, |
1144 |
|
"build_ext": thuban_build_ext |
1145 |
}) |
}) |
1146 |
|
|
1147 |
|
|