/[thuban]/branches/WIP-pyshapelib-bramz/setup.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/setup.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (hide annotations)
Tue Aug 28 15:41:52 2001 UTC (23 years, 6 months ago) by bh
Original Path: trunk/thuban/setup.py
File MIME type: text/x-python
File size: 12921 byte(s)
import all the source files

1 bh 6 # Copyright (c) 2001 by Intevation GmbH
2     # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """Distutils setup script for Thuban."""
9    
10     __version__ = "$Revision$"
11    
12     # Configuration:
13     #
14     # depending on your platform you may have to configure some variables by
15     # hand below.
16     #
17    
18     import os
19     from distutils.core import setup, Extension, Command
20     from distutils.command.install import install
21     from distutils.command.build_py import build_py
22    
23     import distutils
24     print distutils.__file__
25    
26     from string import split
27     import string
28    
29     if os.name == "posix":
30     ###################################################################
31     # Posix configuration. Adapt this if you're running some kind of
32     # Unix like system.
33    
34     # Directories where Proj4 is installed
35     proj4_prefix = "/usr/local/"
36     proj4_incdir = os.path.join(proj4_prefix, "include")
37     proj4_libdir = os.path.join(proj4_prefix, "lib")
38     proj4_lib = "proj"
39    
40    
41     # You shpuldn't have to modify anything below here
42     ###################################################################
43    
44     # The installation prefix (similar to autoconf's --prefix). This is
45     # only the default value, you can override it on the command line
46     # with the install command's --prefix option
47     prefix = "/usr/local/"
48    
49     # On POSIX-systems we run wxgtk-config to determine the C++-compiler
50     # flags
51     wx_config_script = "wxgtk-config"
52     # These lists will be filled automatically below
53     wx_defs = []
54     wx_incdirs = []
55     wx_libdirs = []
56     wx_libs = []
57    
58     elif os.name == "nt":
59     #################################################################
60     # Windows configuration.
61     #
62    
63     # Directories where Proj4 is installed
64     proj4_prefix = r"D:\cygwin\home\user\proj-4.4.3\src"
65     proj4_incdir = proj4_prefix
66     proj4_libdir = proj4_prefix
67     proj4_lib = "proj_i"
68    
69     #
70     # Unless you use a wxPython version other than 2.3.1, you probably
71     # shouldn't have to modify anything below here
72     ##################################################################
73    
74     # Installation prefix. Just install relative to current directory by
75     # default. This is only the default value, you can override it on
76     # the command line with the install command's --prefix option
77     prefix = r"install"
78    
79     # There doesn't seem to be an easy way to get at the wx compiler
80     # flags, so we define them here. These flags work for us with
81     # wxPython 2.3.1. They may have to be modified for other versions.
82    
83     # there's no config script.
84     wx_config_script = ""
85    
86     # so we just define the flags manually
87     wx_prefix = r"D:\wx230"
88     wx_inc = os.path.join(wx_prefix, "include")
89     wx_lib = os.path.join(wx_prefix, "lib")
90     # the values of wx_defs and wx_libs. copied from the wxPython
91     # setup.py
92     wx_defs = [ ('WIN32', None), # Some of these are no longer
93     ('__WIN32__', None), # necessary. Anybody know which?
94     ('_WINDOWS', None),
95     ('__WINDOWS__', None),
96     ('WINVER', '0x0400'),
97     ('__WIN95__', None),
98     ('STRICT', None),
99    
100     ('__WXMSW__', None),
101     ('WXUSINGDLL', '1'),
102    
103     ('SWIG_GLOBAL', None),
104     ('HAVE_CONFIG_H', None),
105     ('WXP_USE_THREAD', '1'),
106     ]
107    
108     wx_incdirs = [wx_inc]
109     wx_libdirs = [wx_lib]
110     wx_libs = ["wx23_1h"]
111     wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32',
112     'winspool', 'winmm', 'shell32', 'oldnames',
113     'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32',
114     'uuid', 'rpcrt4', 'advapi32', 'wsock32']
115     else:
116     raise RuntimeError("Unsupported platform " + os.name)
117    
118    
119     ######################################################################
120     #
121     # There's nothing beyond this point that has to be modified for a
122     # normal installation
123     #
124     ######################################################################
125    
126    
127     #
128     # Functions to determine wxWindows config on POSIX systems
129     #
130    
131     def run_script(cmdline):
132     """Run command and return its stdout or none in case of errors"""
133     pipe = os.popen(cmdline)
134     result = pipe.read()
135     if pipe.close() is not None:
136     print '"' + cmdline + '"', 'failed'
137     return None
138     return result
139    
140    
141     def run_wx_script(command):
142     # first, determine the C++ preprocessor flags
143     flags = run_script(command + ' --cxxflags ')
144     if flags is None:
145     return 0
146     for flag in split(flags):
147     start = flag[:2]
148     value = flag[2:]
149     if start == "-I":
150     wx_incdirs.append(value)
151     elif start == "-D":
152     wx_defs.append((value, None))
153    
154     # determine the library flags
155     flags = run_script(command + ' --libs')
156     if flags is None:
157     return 0
158     for flag in split(flags):
159     start = flag[:2]
160     value = flag[2:]
161     if start == "-L":
162     wx_libdirs.append(value)
163     elif start == "-l":
164     wx_libs.append(value)
165    
166     if wx_config_script:
167     # if there's a wx config script, run it to determine the configuration
168     run_wx_script(wx_config_script)
169    
170    
171    
172     #
173     # Define some extension and python modules
174     #
175     # The C-extension names are prefixed woth "Lib." so they get put into
176     # the Lib/ subdirectory. Lib/ is not really a package but distutils
177     # doesn't care
178    
179     # subdirectory containing the extensions
180     ext_dir = "extensions"
181    
182     # subdirectory with some shapelib files
183     shp_dir = ext_dir + "/shapelib"
184    
185     # lists to fill with the module descriptions
186     extensions = []
187     py_modules = []
188    
189    
190     #
191     # Thuban specific modules
192     #
193    
194     extensions.append(Extension("Lib.wxproj",
195     [ext_dir + "/thuban/wxproj.cpp",
196     shp_dir + "/shpopen.c"],
197     include_dirs = [shp_dir, proj4_incdir] +wx_incdirs,
198     define_macros = wx_defs,
199     library_dirs = [proj4_libdir] + wx_libdirs,
200     libraries = [proj4_lib] + wx_libs))
201    
202     #
203     # shapelib wrappers are also distributed with thuban
204     #
205    
206     extensions.append(Extension("Lib.shapelibc",
207     [ext_dir + "/pyshapelib/shapelib_wrap.c",
208     shp_dir + "/shpopen.c"],
209     include_dirs = [shp_dir]))
210     extensions.append(Extension("Lib.dbflibc",
211     [ext_dir + "/pyshapelib/dbflib_wrap.c",
212     shp_dir + "/dbfopen.c"],
213     include_dirs = [shp_dir]))
214     for name in ("shapelib", "dbflib"):
215     py_modules.append(ext_dir + "/pyshapelib/" + name)
216    
217     #
218     # PROJ4 bindings are also distributed with thuban
219     #
220     extensions.append(Extension("Lib.Projectionc",
221     [ext_dir + "/pyprojection/Projection_wrap.c"],
222     include_dirs = [proj4_incdir],
223     library_dirs = [proj4_libdir],
224     libraries = [proj4_lib]))
225     py_modules.append(ext_dir + "/pyprojection/Projection")
226    
227    
228     #
229     # Data files
230     #
231    
232     data_files = []
233    
234     # bitmaps
235     dir = "Resources/Bitmaps/"
236     bitmaps = []
237     for file in os.listdir(os.path.join("Resources", "Bitmaps")):
238     if string.lower(file[-4:]) == ".xpm":
239     bitmaps.append(dir + file)
240     data_files.append((dir, bitmaps))
241    
242     #
243     # Command definitions
244     #
245     # So far distutils are only meant to distribute python extensions, not
246     # complete applications, so we have to redefine a few commands
247    
248    
249    
250     class InstallLocal(Command):
251    
252     """
253     A new install command to just link (or copy, on non-POSIX systems)
254     the extension modules to the top directory so that Thuban can be run
255     directly from the source dir.
256     """
257    
258     description =\
259     "Create some symlink so you can run thubanfrom the source directory"
260    
261     user_options = [
262     ('debug', 'g', "compile/link with debugging information"),
263     ('skip-build', None, "skip the build steps"),
264     ]
265    
266     def initialize_options (self):
267     self.extensions = None
268     self.build_dir = None
269     self.skip_build = None
270     self.debug = None
271    
272     def finalize_options (self):
273     self.set_undefined_options("install",
274     ("build_lib", "build_dir"),
275     ('skip_build', 'skip_build'))
276     self.extensions = self.distribution.ext_modules
277    
278     def run(self):
279     # Make sure we have built everything we need first
280     self.build()
281    
282     # now do the work. Simply link or copy the Lib dir
283     libdir = os.path.join(self.build_dir, "Lib")
284     if os.name == "posix":
285     # on posix, just lilnk the Lib dir
286     self.link_dir(libdir, "Lib")
287     else:
288     self.copy_tree(libdir, "Lib")
289    
290     def link_dir(self, src, dest):
291     """Create a symbolic link dest pointing to src"""
292     if self.verbose:
293     print "symlinking %s -> %s" % (src, dest)
294     if self.dry_run:
295     return
296    
297     if not (os.path.exists(dest) and os.path.samefile(src, dest)):
298     os.symlink(src, dest)
299    
300     def build (self):
301     if not self.skip_build:
302     if self.distribution.has_pure_modules():
303     self.run_command('build_py')
304     if self.distribution.has_ext_modules():
305     self.run_command('build_ext')
306    
307    
308    
309     class thuban_build_py(build_py):
310    
311     """
312     A new build_py that can deal with both packages and modules in
313     one distribution.
314     """
315    
316     def run(self):
317     """The same the as teh original in build_py revision 1.33 except
318     that this allows both packages and modules to be in one
319     distribution
320     """
321     if not self.py_modules and not self.packages:
322     return
323    
324     # Now we're down to two cases: 'py_modules' only and 'packages' only.
325     if self.py_modules:
326     self.build_modules()
327     if self.packages:
328     self.build_packages()
329    
330     self.byte_compile(self.get_outputs(include_bytecode=0))
331    
332     def find_modules (self):
333     """Thuban specific version of build_py.find_modules. Unlike the
334     original version, we assume that the modules in self.py_modules
335     can contain directories and are all to be placed into the same
336     subdirectory, Lib, in the build directory. This is achieved by
337     returning the modules as a list (package, module, filename)
338     where package is 'Lib', module is the basename of the module name
339     and filename is the filename relative to the package root.
340     """
341     modules = []
342     for module in self.py_modules:
343     module_base = os.path.basename(module)
344     module_file = module + ".py"
345     if not self.check_module(module, module_file):
346     continue
347    
348     modules.append(("Lib", module_base, module_file))
349     return modules
350    
351     #
352     # Extend the standard install command to symlink the installed script to
353     # $prefix/bin/
354     #
355    
356     class ThubanInstall(install):
357    
358     def run(self):
359     install.run(self)
360     if os.name == "posix":
361     scriptfile = os.path.join(self.install_scripts, "thuban.py")
362     bindir = os.path.join(self.prefix, "bin")
363     binfile = os.path.join(bindir, "thuban")
364     self.mkpath(bindir)
365     self.copy_file(scriptfile, binfile, link="sym")
366    
367    
368     long_description = """\
369     Thuban is a viewer for geographic data written in Python
370     """
371    
372     setup(name = "thuban",
373     version = "0.0.3",
374     description = "Geographic data viewer",
375     long_description = long_description,
376     licence = "GPL",
377     author = "Intevation GmbH",
378     author_email = "[email protected]",
379     url = "ftp:intevation.de/",
380    
381     scripts = ["thuban.py"],
382     packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"],
383     ext_modules = extensions,
384     py_modules = py_modules,
385     data_files = data_files,
386    
387     # defaults for the install command
388     options = {"install":
389     # prefix defaults to python's prefix normally
390     {"prefix": prefix,
391     # make sure both libs and scripts are installed in the
392     # same directory.
393     "install_lib": "$base/thuban",
394     "install_scripts": "$base/thuban",
395     "install_data": "$base/thuban/",
396    
397     # Don't print warning messages about the lib dir not
398     # being on Python's path. The libraries are Thuban
399     # specific and are installed just for Thuban. They'll
400     # be automatically on Python's path when Thuban is run
401     "warn_dir": 0,
402     }},
403     cmdclass = {"build_py": thuban_build_py,
404     "install_local": InstallLocal,
405     "install": ThubanInstall})
406    

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26