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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 19 by bh, Tue Sep 4 15:11:27 2001 UTC revision 2007 by bh, Tue Dec 2 18:03:39 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 17  __version__ = "$Revision$" Line 17  __version__ = "$Revision$"
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  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
28  from distutils.util import convert_path, change_root  from distutils.util import convert_path, change_root
29    
30    from distutils import archive_util, dir_util
31  import distutils  import distutils
32    
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
# Line 41  if os.name == "posix": Line 52  if os.name == "posix":
52      proj4_lib = "proj"      proj4_lib = "proj"
53    
54    
55      # You shpuldn't have to modify anything below here      # You shouldn't have to modify anything below here
56      ###################################################################      ###################################################################
57            
58      # The installation prefix (similar to autoconf's --prefix). This is      # The installation prefix (similar to autoconf's --prefix). This is
59      # only the default value, you can override it on the command line      # only the default value, you can override it on the command line
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
63        # 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
67        # value on the commandline with the --create-init-module to the
68        # install command.
69        create_init_module = 1
70    
71      # On POSIX-systems we run wxgtk-config to determine the C++-compiler      # On POSIX-systems we run wxgtk-config to determine the C++-compiler
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      #################################################################      #################################################################
# Line 64  elif os.name == "nt": Line 83  elif os.name == "nt":
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\projects\thuban\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\projects\thuban\wxPython-2.4.0.7"
93      wx_inc =  os.path.join(wx_prefix, "include")      wx_inc = [os.path.join(wx_prefix, 'lib', 'mswdllh'),
94      wx_lib =  os.path.join(wx_prefix, "lib")                os.path.join(wx_prefix, "include")]
95        wx_lib = [os.path.join(wx_prefix, "lib")]
96    
97        # Define include and lib directories for GDAL
98        gdal_prefix = r"D:\cygwin\home\user\projects\thuban\gdal-1.1.8"
99        gdal_inc = [os.path.join(gdal_prefix, 'alg'),
100                    os.path.join(gdal_prefix, 'ogr'),
101                    os.path.join(gdal_prefix, 'port'),
102                    os.path.join(gdal_prefix, 'core')]
103        gdal_lib = [gdal_prefix]
104    
105      #      #
106      # 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
107      # shouldn't have to modify anything below here      # shouldn't have to modify anything below here
108      ##################################################################      ##################################################################
109            
# Line 84  elif os.name == "nt": Line 112  elif os.name == "nt":
112      # the command line with the install command's --prefix option      # the command line with the install command's --prefix option
113      prefix = r"install"      prefix = r"install"
114    
115        # Whether to create the thubaninit module. You can override this
116        # value on the commandline with the --create-init-module to the
117        # install command. By default we don't create it under NT because we
118        # most often run install only as part of bdist_inno where we can't
119        # really create because it needs information only known at install
120        # time.
121        create_init_module = 0
122    
123      # There doesn't seem to be an easy way to get at the wx compiler      # There doesn't seem to be an easy way to get at the wx compiler
124      # flags, so we define them here. These flags work for us with      # flags, so we define them here. These flags work for us with
125      # wxPython 2.3.1. They may have to be modified for other versions.      # wxPython 2.3.1. They may have to be modified for other versions.
# Line 91  elif os.name == "nt": Line 127  elif os.name == "nt":
127      # there's no config script.      # there's no config script.
128      wx_config_script = ""      wx_config_script = ""
129            
130        wx_cs_params = [[] for i in range(CS_NUM_PARAMS)]
131    
132      # the values of wx_defs and wx_libs. copied from the wxPython      # the values of wx_defs and wx_libs. copied from the wxPython
133      # setup.py      # setup.py
134      wx_defs = [ ('WIN32', None),        # Some of these are no longer      wx_cs_params[CS_DEFS] = \
135                  [ ('WIN32', None),        # Some of these are no longer
136                  ('__WIN32__', None),    # necessary.  Anybody know which?                  ('__WIN32__', None),    # necessary.  Anybody know which?
137                  ('_WINDOWS', None),                  ('_WINDOWS', None),
138                  ('__WINDOWS__', None),                  ('__WINDOWS__', None),
# Line 109  elif os.name == "nt": Line 148  elif os.name == "nt":
148                  ('WXP_USE_THREAD', '1'),                  ('WXP_USE_THREAD', '1'),
149                  ]                  ]
150            
151      wx_incdirs = [wx_inc]      wx_cs_params[CS_INCDIRS] = wx_inc
152      wx_libdirs = [wx_lib]      wx_cs_params[CS_LIBDIRS] = wx_lib
153      wx_libs = ["wx23_1h"]      wx_cs_params[CS_LIBS] = ["wxmsw24h"] \
154      wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32',                        + ['kernel32', 'user32', 'gdi32', 'comdlg32',
155                           'winspool', 'winmm', 'shell32', 'oldnames',                           'winspool', 'winmm', 'shell32', 'oldnames',
156                           'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32',                           'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32',
157                           'uuid', 'rpcrt4', 'advapi32', 'wsock32']                           'uuid', 'rpcrt4', 'advapi32', 'wsock32']
158    
159        gdal_config_script = ""
160        gdal_cs_params = [[] for i in range(CS_NUM_PARAMS)]
161    
162        gdal_cs_params[CS_INCDIRS] = gdal_inc
163        gdal_cs_params[CS_LIBDIRS] = gdal_lib
164        gdal_cs_params[CS_LIBS] = ["gdal_i"]
165    
166  else:  else:
167      raise RuntimeError("Unsupported platform " + os.name)      raise RuntimeError("Unsupported platform " + os.name)
168    
# Line 142  def run_script(cmdline): Line 189  def run_script(cmdline):
189      return result      return result
190    
191    
192  def run_wx_script(command):  def run_cs_script(command, store):
193      # first, determine the C++ preprocessor flags Use --cflags here      # first, determine the C++ preprocessor flags Use --cflags here
194      # because it seems that older version don't have --cxxflags and      # because it seems that older version don't have --cxxflags and
195      # newer ones return the same result for both      # newer ones return the same result for both
196      flags = run_script(command + ' --cflags ')      flags = run_script(command + ' --cflags ')
197      if flags is None:      if flags is None:
198          return 0          return False
199      for flag in split(flags):      for flag in split(flags):
200          start = flag[:2]          start = flag[:2]
201          value = flag[2:]          value = flag[2:]
202          if start == "-I":          if start == "-I":
203              wx_incdirs.append(value)              store[CS_INCDIRS].append(value)
204          elif start == "-D":          elif start == "-D":
205              wx_defs.append((value, None))              store[CS_DEFS].append((value, None))
206    
207      # determine the library flags      # determine the library flags
208      flags = run_script(command + ' --libs')      flags = run_script(command + ' --libs')
209      if flags is None:      if flags is None:
210          return 0          return False
211      for flag in split(flags):      for flag in split(flags):
212          start = flag[:2]          start = flag[:2]
213          value = flag[2:]          value = flag[2:]
214          if start == "-L":          if start == "-L":
215              wx_libdirs.append(value)              store[CS_LIBDIRS].append(value)
216          elif start == "-l":          elif start == "-l":
217              wx_libs.append(value)              store[CS_LIBS].append(value)
218    
219        return True
220    
221  if wx_config_script:  if wx_config_script:
222      # 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
223      run_wx_script(wx_config_script)      run_cs_script(wx_config_script, wx_cs_params)
       
224    
225    if gdal_config_script:
226        # if there's a gdal config script, run it to determine the configuration
227        include_gdal = include_gdal \
228                       and run_cs_script(gdal_config_script, gdal_cs_params)
229    
230  #  #
231  # Define some extension and python modules  # Define some extension and python modules
232  #  #
233  # The C-extension names are prefixed woth "Lib." so they get put into  # The C-extension names are prefixed with "Lib." so they get put into
234  # the Lib/ subdirectory. Lib/ is not really a package but distutils  # the Lib/ subdirectory. Lib/ is not really a package but distutils
235  # doesn't care  # doesn't care
236    
237  # subdirectory containing the extensions  # subdirectory containing the distutil extensions
238  ext_dir = "extensions"  ext_dir = "libraries"
239    
240  # subdirectory with some shapelib files  # subdirectory with some shapelib files
241  shp_dir = ext_dir + "/shapelib"  shp_dir = ext_dir + "/shapelib"
# Line 198  py_modules = [] Line 250  py_modules = []
250  #  #
251    
252  extensions.append(Extension("Lib.wxproj",  extensions.append(Extension("Lib.wxproj",
253                              [ext_dir + "/thuban/wxproj.cpp",                              [ext_dir + "/thuban/wxproj.cpp"],
254                               shp_dir + "/shpopen.c"],                              include_dirs = ([shp_dir, proj4_incdir,
255                              include_dirs = [shp_dir, proj4_incdir] +wx_incdirs,                                               ext_dir + "/pyshapelib/"]
256                              define_macros = wx_defs,                                              + wx_cs_params[CS_INCDIRS]),
257                              library_dirs = [proj4_libdir] + wx_libdirs,                              define_macros = wx_cs_params[CS_DEFS],
258                              libraries = [proj4_lib] + wx_libs))                              library_dirs = [proj4_libdir] +
259                                               wx_cs_params[CS_LIBDIRS],
260                                libraries = [proj4_lib] + wx_cs_params[CS_LIBS]))
261    
262    
263  #  #
264  # shapelib wrappers are also distributed with thuban  # shapelib wrappers are also distributed with thuban
# Line 211  extensions.append(Extension("Lib.wxproj" Line 266  extensions.append(Extension("Lib.wxproj"
266    
267  extensions.append(Extension("Lib.shapelibc",  extensions.append(Extension("Lib.shapelibc",
268                              [ext_dir + "/pyshapelib/shapelib_wrap.c",                              [ext_dir + "/pyshapelib/shapelib_wrap.c",
269                               shp_dir + "/shpopen.c"],                               shp_dir + "/shpopen.c",
270                                 shp_dir + "/shptree.c"],
271                                include_dirs = [shp_dir]))
272    extensions.append(Extension("Lib.shptree",
273                                [ext_dir + "/pyshapelib/shptreemodule.c"],
274                              include_dirs = [shp_dir]))                              include_dirs = [shp_dir]))
275  extensions.append(Extension("Lib.dbflibc",  extensions.append(Extension("Lib.dbflibc",
276                              [ext_dir + "/pyshapelib/dbflib_wrap.c",                              [ext_dir + "/pyshapelib/dbflib_wrap.c",
# Line 237  py_modules.append(ext_dir + "/pyprojecti Line 296  py_modules.append(ext_dir + "/pyprojecti
296    
297  data_files = []  data_files = []
298    
299  # bitmaps  # Resources
300  dir = "Resources/Bitmaps"  for d, patterns in [("Resources/Bitmaps",
301  bitmaps = []                      ("Resources/Bitmaps/*.xpm",)),
302  for file in os.listdir(os.path.join("Resources", "Bitmaps")):                     ("Resources/Projections",
303      if string.lower(file[-4:]) == ".xpm":                      ("Resources/Projections/*.proj",)),
304          bitmaps.append(dir + '/' +  file)                     ("Resources/XML",
305  data_files.append((dir, bitmaps))                      ("Resources/XML/*.dtd",)),
306                       ("Extensions/importAPR/samples",
307                        ("Extensions/importAPR/samples/README",
308                         "Extensions/importAPR/samples/*.apr")),
309                       ]:
310        for pattern in patterns:
311            data_files.append((d, glob.glob(pattern)))
312    if os.path.isdir("Resources/Locale"):
313        for d in os.listdir("Resources/Locale"):
314            data_files.append(("Resources/Locale/" + d +"/LC_MESSAGES",
315                               ["Resources/Locale/"+ d +"/LC_MESSAGES/thuban.mo"]))
316    
317  #  #
318  #       Command definitions  #       Command definitions
319  #  #
320  # So far distutils are only meant to distribute python extensions, not  # So far distutils are only meant to distribute python extensions, not
321  # complete applications, so we have to redefine a few commands  # complete applications, so we have to redefine a few commands
322    #
323    
324    
325    # Much of the data_dist command is directly copied from the distutils'
326    # sdist command
327    class data_dist(Command):
328    
329        description = "create a data distribution (tarball, zip file, etc.)"
330    
331        user_options = [
332            ('formats=', None,
333             "formats for source distribution (comma-separated list)"),
334            ('keep-temp', 'k',
335             "keep the distribution tree around after creating " +
336             "archive file(s)"),
337            ('dist-dir=', 'd',
338             "directory to put the source distribution archive(s) in "
339             "[default: dist]"),
340            ]
341    
342        boolean_options = ['keep-temp']
343    
344        def initialize_options (self):
345            self.formats = None
346            self.keep_temp = 0
347            self.dist_dir = None
348    
349        def finalize_options (self):
350            self.ensure_string_list('formats')
351            if self.formats is None:
352                self.formats = ["zip"]
353            bad_format = archive_util.check_archive_formats(self.formats)
354            if bad_format:
355                raise DistutilsOptionError, \
356                      "unknown archive format '%s'" % bad_format
357    
358            if self.dist_dir is None:
359                self.dist_dir = "dist"
360    
361    
362        def run(self):
363            # 'filelist' contains the list of files that will make up the
364            # manifest
365            self.filelist = FileList()
366            
367            # Do whatever it takes to get the list of files to process.
368            # File list is accumulated in 'self.filelist'.
369            self.get_file_list()
370    
371            # Otherwise, go ahead and create the source distribution tarball,
372            # or zipfile, or whatever.
373            self.make_distribution()
374    
375        def get_file_list(self):
376            """Figure out the list of files to include in the data
377            distribution, and put it in 'self.filelist'.
378            """
379            self.filelist.findall("Data")
380            self.filelist.include_pattern("*", anchor = 0)
381            self.filelist.exclude_pattern(r'/(RCS|CVS)/.*', is_regex=1)
382            self.filelist.sort()
383            self.filelist.remove_duplicates()
384    
385        def make_release_tree(self, base_dir, files):
386            """Create the directory tree that will become the source
387            distribution archive.  All directories implied by the filenames in
388            'files' are created under 'base_dir', and then we hard link or copy
389            (if hard linking is unavailable) those files into place.
390            Essentially, this duplicates the developer's source tree, but in a
391            directory named after the distribution, containing only the files
392            to be distributed.
393            """
394            # Create all the directories under 'base_dir' necessary to
395            # put 'files' there; the 'mkpath()' is just so we don't die
396            # if the manifest happens to be empty.
397            self.mkpath(base_dir)
398            dir_util.create_tree(base_dir, files,
399                                 verbose=self.verbose, dry_run=self.dry_run)
400    
401            # And walk over the list of files, either making a hard link (if
402            # os.link exists) to each one that doesn't already exist in its
403            # corresponding location under 'base_dir', or copying each file
404            # that's out-of-date in 'base_dir'.  (Usually, all files will be
405            # out-of-date, because by default we blow away 'base_dir' when
406            # we're done making the distribution archives.)
407        
408            if hasattr(os, 'link'):        # can make hard links on this system
409                link = 'hard'
410                msg = "making hard links in %s..." % base_dir
411            else:                           # nope, have to copy
412                link = None
413                msg = "copying files to %s..." % base_dir
414    
415            if not files:
416                self.warn("no files to distribute -- empty manifest?")
417            else:
418                self.announce(msg)
419            for file in files:
420                if not os.path.isfile(file):
421                    self.warn("'%s' not a regular file -- skipping" % file)
422                else:
423                    dest = os.path.join(base_dir, file)
424                    self.copy_file(file, dest, link=link)
425    
426    
427        def make_distribution (self):
428            """Create the source distribution(s).  First, we create the release
429            tree with 'make_release_tree()'; then, we create all required
430            archive files (according to 'self.formats') from the release tree.
431            Finally, we clean up by blowing away the release tree (unless
432            'self.keep_temp' is true).  The list of archive files created is
433            stored so it can be retrieved later by 'get_archive_files()'.
434            """
435            # Don't warn about missing meta-data here -- should be (and is!)
436            # done elsewhere.
437            base_dir = "Thuban-data-" + self.distribution.get_version()
438            base_name = os.path.join(self.dist_dir, base_dir)
439    
440            self.make_release_tree(base_dir, self.filelist.files)
441            archive_files = []              # remember names of files we create
442            for fmt in self.formats:
443                file = self.make_archive(base_name, fmt, base_dir=base_dir)
444                archive_files.append(file)
445    
446            self.archive_files = archive_files
447    
448            if not self.keep_temp:
449                dir_util.remove_tree(base_dir, self.verbose, self.dry_run)
450    
451    
452    
# Line 262  class InstallLocal(Command): Line 459  class InstallLocal(Command):
459      """      """
460    
461      description =\      description =\
462          "Create some symlink so you can run thubanfrom the source directory"          "Create some symlinks so you can run thuban from the source directory"
463    
464      user_options = [      user_options = [
465          ('skip-build', None, "skip the build steps"),          ('skip-build', None, "skip the build steps"),
466            ('create-init-module', None,
467             "Create the thubaninit.py module to ease use of Thuban as a library"),
468            ('dont-create-init-module', None,
469             "Do not create the thubaninit.py module"),
470          ]          ]
471    
472        boolean_options = ["create-init-module"]
473        negative_opt = {'dont-create-init-module' : 'create-init-module'}
474    
475    
476      def initialize_options (self):      def initialize_options (self):
477          self.extensions = None          self.extensions = None
478          self.build_dir = None          self.build_dir = None
479          self.skip_build = None          self.skip_build = None
480            self.create_init_module = None
481    
482      def finalize_options (self):      def finalize_options (self):
483          self.set_undefined_options("install",          self.set_undefined_options("install",
484                                     ("build_lib", "build_dir"),                                     ("build_lib", "build_dir"),
485                                     ('skip_build', 'skip_build'))                                     ('skip_build', 'skip_build'))
486          self.extensions = self.distribution.ext_modules          self.extensions = self.distribution.ext_modules
487            if self.create_init_module is None:
488                # by default we create the init module
489                self.create_init_module = 1
490    
491      def run(self):      def run(self):
492          # Make sure we have built everything we need first          # Make sure we have built everything we need first
# Line 286  class InstallLocal(Command): Line 495  class InstallLocal(Command):
495          # now do the work. Simply link or copy the Lib dir          # now do the work. Simply link or copy the Lib dir
496          libdir = os.path.join(self.build_dir, "Lib")          libdir = os.path.join(self.build_dir, "Lib")
497          if os.name == "posix":          if os.name == "posix":
498              # on posix, just lilnk the Lib dir              # on posix, just link the Lib dir
499              self.link_dir(libdir, "Lib")              self.link_dir(libdir, "Lib")
500          else:          else:
501              self.copy_tree(libdir, "Lib")              self.copy_tree(libdir, "Lib")
502    
503            # create the init module if desired
504            if self.create_init_module:
505                # create the init module
506                initfilename = "thubaninit.py"
507                contents = thubaninit_contents("")
508                self.execute(write_file, (initfilename, contents),
509                             "Create %s" % initfilename)
510    
511      def link_dir(self, src, dest):      def link_dir(self, src, dest):
512          """Create a symbolic link dest pointing to src"""          """Create a symbolic link dest pointing to src"""
513          if self.verbose:          if self.verbose:
# Line 317  class thuban_build_py(build_py): Line 534  class thuban_build_py(build_py):
534      distribution.      distribution.
535      """      """
536    
537        # FIXME: When Thuban can rely on Python 2.3 as the oldest supported
538        # Python release we don't need to override the run and
539        # find_all_modules methods anymore. distutils will allow both python
540        # modules and packages starting with 2.3.
541    
542      def run(self):      def run(self):
543          """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
544          that this allows both packages and modules to be in one          that this allows both packages and modules to be in one
# Line 368  class thuban_build_py(build_py): Line 590  class thuban_build_py(build_py):
590          return modules          return modules
591    
592    
593    thubaninit_contents_start = """
594    # This module was automatically generated by Thuban's install script
595    '''Import this module once per program (best place is probably the file
596    that ends up as your __main__ module) to be able to import Thuban
597    afterwards.
598    
599    Usage:
600    
601    import thubaninit
602    import Thuban
603    '''
604    import sys, os
605    """
606    
607    thubaninit_contents_thubaninitdir = """
608    sys.path.insert(0, %(thubandir)s)
609    """
610    thubaninit_contents_otherdirs = """
611    # Put the Lib dir into the path. The Lib dir contains some extra Python
612    # modules
613    import Thuban
614    thubandir = os.path.join(Thuban.__path__[0], '..')
615    dir = os.path.join(thubandir, "Lib")
616    if os.path.isdir(dir):
617        sys.path.insert(0, dir)
618    """
619    
620    def thubaninit_contents(thubandir):
621        """Return the contents of the the thubaninit file as a list of lines.
622    
623        The parameter thubandir is the parent directory where the Thuban/
624        package or the empty string if the thubaninit file itself will be
625        located in that direcory as well.
626        """
627        contents = thubaninit_contents_start
628        if thubandir:
629            thubandir = repr(thubandir)
630            contents += thubaninit_contents_thubaninitdir % locals()
631        contents += thubaninit_contents_otherdirs
632        return contents.split("\n")
633    
634    
635  class ThubanInstall(install):  class ThubanInstall(install):
636    
# Line 384  class ThubanInstall(install): Line 647  class ThubanInstall(install):
647                          "(default on posix systems and only relevant there)"),                          "(default on posix systems and only relevant there)"),
648    
649                           ("extra-files", None,                           ("extra-files", None,
650                            "List of filenames or (src, dest) pairs describing "                            "List of filenames or (src, dest) pairs describing"
651                            " extra files to install "                            " extra files to install "
652                            "(can only be set from witin setup.py"),                            "(can only be set from within setup.py"),
653    
654                             ("create-init-module=", None,
655                              "If true, create a module in the site-packages"
656                              " directory that tweaks sys.path to let you easily"
657                              " import thuban modules from outside of thuban."),
658                             ("init-module-dir=", None,
659                              "Directory in which to create the init module."
660                              " Defaults to Python's site-packages directory."),
661                           ])                           ])
662    
663      boolean_options = install.boolean_options[:]      boolean_options = install.boolean_options[:]
664      boolean_options.append("do-symlink")      boolean_options.append("do-symlink")
665        boolean_options.append("create-init-module")
666    
667      def initialize_options(self):      def initialize_options(self):
668          self.do_symlink = None          self.do_symlink = None
669          self.extra_files = []          self.extra_files = []
670    
671            # initialize the create_init_module flag from the global
672            # determined at runtime
673            self.create_init_module = create_init_module
674            self.init_module_dir = None
675          install.initialize_options(self)          install.initialize_options(self)
676    
677      def finalize_options(self):      def finalize_options(self):
# Line 404  class ThubanInstall(install): Line 681  class ThubanInstall(install):
681              else:              else:
682                  self.do_symlink = 0                  self.do_symlink = 0
683          install.finalize_options(self)          install.finalize_options(self)
684            self.expand_with_pure_python_dirs(["init_module_dir"])
685    
686        def expand_with_pure_python_dirs(self, attrs):
687            """Expand the attributes with default values of base and platbase"""
688            # it seems that the values for "prefix" and "exec_prefix" in
689            # self.config_vars are the corresponding values used by the
690            # python interpreter, so we just assign these to "base" and
691            # "platbase".
692            config_vars = self.config_vars.copy()
693            config_vars["base"] = self.config_vars["prefix"]
694            config_vars["platbase"] = self.config_vars["exec_prefix"]
695            for attr in attrs:
696                val = getattr(self, attr)
697                if val is not None:
698                    if os.name == 'posix':
699                        val = os.path.expanduser(val)
700                    val = subst_vars(val, config_vars)
701                    setattr(self, attr, val)
702    
703        def select_scheme(self, scheme):
704            """Extend the inherited method to set init_module_dir"""
705            install.select_scheme(self, scheme)
706            # only set init_module_dir if it wasn't set by the user
707            if self.init_module_dir is None:
708                self.init_module_dir = INSTALL_SCHEMES[scheme]['purelib']
709    
710        def convert_paths(self, *args):
711            """Extend the inherited method so that we can remember some filename
712            """
713            # remember the installation directory before its root gets
714            # changed
715            self.install_lib_orig = self.install_lib
716            apply(install.convert_paths, (self,) + args)
717    
718      def run(self):      def run(self):
719          install.run(self)          install.run(self)
# Line 412  class ThubanInstall(install): Line 722  class ThubanInstall(install):
722                  src, dest = item                  src, dest = item
723              else:              else:
724                  src = dest = item                  src = dest = item
725              self.copy_file(convert_path(src),              self.copy_file(convert_path(src),
726                             os.path.join(self.root, convert_path(dest)))                             os.path.join(self.root, convert_path(dest)))
727    
728          if os.name == "posix" and self.do_symlink:          if os.name == "posix" and self.do_symlink:
# Line 427  class ThubanInstall(install): Line 737  class ThubanInstall(install):
737              self.mkpath(bindir)              self.mkpath(bindir)
738              self.link_file(scriptfile, binfile)              self.link_file(scriptfile, binfile)
739    
740            if self.create_init_module:
741                # create the init module
742                initfilename = self.thuban_init_filename()
743                if self.root:
744                    initfilename = change_root(self.root, initfilename)
745                contents = thubaninit_contents(self.install_lib_orig)
746                self.mkpath(os.path.dirname(initfilename))
747                self.execute(write_file, (initfilename, contents),
748                             "Create %s" % initfilename)
749    
750      def link_file(self, src, dest):      def link_file(self, src, dest):
751          """Create a symbolic link dest pointing to src.          """Create a symbolic link dest pointing to src.
752    
# Line 441  class ThubanInstall(install): Line 761  class ThubanInstall(install):
761          if not os.path.exists(dest):          if not os.path.exists(dest):
762              os.symlink(src, dest)              os.symlink(src, dest)
763    
764        def thuban_init_filename(self):
765            """Return the filename for the init-module"""
766            # Since we override the normal install dirs to point to our own
767            # prefix we have to reach into installed
768            return self.init_module_dir + "/thubaninit.py"
769    
770      def get_outputs (self):      def get_outputs (self):
771          outputs = install.get_outputs(self)          outputs = install.get_outputs(self)
# Line 456  class ThubanInstall(install): Line 781  class ThubanInstall(install):
781                  bindir = change_root(self.root, bindir)                  bindir = change_root(self.root, bindir)
782              binfile = os.path.join(bindir, "thuban")              binfile = os.path.join(bindir, "thuban")
783              outputs.append(binfile)              outputs.append(binfile)
784            if self.create_init_module:
785                initfilename = self.thuban_init_filename()
786                if self.root:
787                    initfilename = change_root(self.root, initfilename)
788                outputs.append(initfilename)
789          return outputs          return outputs
790    
791    
792    # scripts to override some of the commands put into the spec-file by the
793    # bdist_rpm command.
794    
795  bdist_rpm_prep_script = '''  bdist_rpm_prep_script = '''
796  %setup  %setup
797  cp extensions/pyshapelib/{README,README.pyshapelib}  cp libraries/pyshapelib/{README,README.pyshapelib}
798  cp extensions/pyshapelib/{COPYING,COPYING.pyshapelib}  cp libraries/pyshapelib/{COPYING,COPYING.pyshapelib}
799  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}  cp libraries/pyprojection/{LICENSE,LICENSE.pyprojection}
800    '''
801    
802    bdist_rpm_build_script = '''
803    env PATH="$PATH:%(prefix)s/lib/wxPython/bin:/usr/lib/wxPython/bin" CFLAGS="$RPM_OPT_FLAGS" %(python)s setup.py build
804    '''
805    
806    bdist_rpm_install_script = '''
807    %(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \
808       --prefix=%(prefix)s
809  '''  '''
810    
811    
       
812  class thuban_bdist_rpm(bdist_rpm):  class thuban_bdist_rpm(bdist_rpm):
813    
814      """Thuban specific RPM distribution command"""      """Thuban specific RPM distribution command"""
815    
816      def run(self):      user_options = bdist_rpm.user_options[:]
817          # create the prep script for the spec-file      user_options.extend([("prefix=", None, "Install prefix for the RPM"),
818                             ])
819    
820        def initialize_options(self):
821            # per default, RPMs are installed in /usr
822            self.prefix = "/usr/"
823    
824            # create the scripts we want to override. We actually fill them
825            # with contents later because some values we put into those
826            # scripts such as the python interpreter to use are only known
827            # then.
828            open("bdist_rpm_prep", "w").close()
829            open("bdist_rpm_build", "w").close()
830            open("bdist_rpm_install", "w").close()
831            bdist_rpm.initialize_options(self)
832    
833        def _make_spec_file(self):
834            # create the scripts for the spec-file. Now we know the python
835            # interpreter to use.
836          open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)          open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)
837    
838          bdist_rpm.run(self)          build = bdist_rpm_build_script % {"python": self.python,
839                                              "prefix": self.prefix}
840            open("bdist_rpm_build", "w").write(build)
841    
842            install = bdist_rpm_install_script % {"python": self.python,
843                                                  "prefix": self.prefix}
844            open("bdist_rpm_install", "w").write(install)
845    
846            #
847            return bdist_rpm._make_spec_file(self)
848    
849    
850  class bdist_inno(Command):  class bdist_inno(Command):
# Line 558  class bdist_inno(Command): Line 926  class bdist_inno(Command):
926          """Execute the command. install_options if given, should be a          """Execute the command. install_options if given, should be a
927          directory of additional options to set in the install step"""          directory of additional options to set in the install step"""
928          # Obviously have to build before we can install          # Obviously have to build before we can install
929    
930          if not self.skip_build:          if not self.skip_build:
931              self.run_command('build')              self.run_command('build')
932    
# Line 570  class bdist_inno(Command): Line 939  class bdist_inno(Command):
939          if os.name != 'nt':          if os.name != 'nt':
940              # Must force install to use the 'nt' scheme;              # Must force install to use the 'nt' scheme;
941              install.select_scheme('nt')              install.select_scheme('nt')
             # don't make a symlink because we're simulating windows, so  
             # that we can generate the iss-file even on Linux  
             install.do_symlink = 0  
942    
943          self.announce("installing to %s" % self.bdist_dir)          self.announce("installing to %s" % self.bdist_dir)
944          install.ensure_finalized()          install.ensure_finalized()
# Line 583  class bdist_inno(Command): Line 949  class bdist_inno(Command):
949          self.execute(write_file, (iss_file, self.generate_iss()),          self.execute(write_file, (iss_file, self.generate_iss()),
950                       "Create Inno Setup script file %s" % iss_file)                       "Create Inno Setup script file %s" % iss_file)
951    
952          # and invoke          # and invoke
953          if self.run_inno:          if self.run_inno:
954              self.spawn(["iscc", iss_file])              self.spawn(["iscc", iss_file])
955    
# Line 649  class bdist_inno(Command): Line 1015  class bdist_inno(Command):
1015              line = 'Name: "{group}\\%s"; Filename: "%s";' \              line = 'Name: "{group}\\%s"; Filename: "%s";' \
1016                     % (icon.title, icon.install_name)                     % (icon.title, icon.install_name)
1017              iss.append(line)              iss.append(line)
1018                
1019          return iss          return iss
1020    
1021    
1022  class InnoIconItem:  class InnoIconItem:
1023    
1024      """Describe one item for he start menu for the Inno Setup installer"""      """Describe one item for the start menu for the Inno Setup installer"""
1025    
1026      def __init__(self, filename, title, install_name = None):      def __init__(self, filename, title, install_name = None):
1027          self.filename = filename          self.filename = filename
# Line 673  class thuban_bdist_inno(bdist_inno): Line 1039  class thuban_bdist_inno(bdist_inno):
1039      def run(self):      def run(self):
1040          install_options = {          install_options = {
1041              "prefix": ".",              "prefix": ".",
1042                "install_lib": "$base",
1043                "install_data": "$base",
1044              "install_scripts": "$base",              "install_scripts": "$base",
1045              "warn_dir": 0,              "warn_dir": 0,
1046              "extra_files": ["COPYING", "Lib/proj.dll"],              "extra_files": ["COPYING", "Lib/proj.dll"],
1047              }              }
1048            # don't make a symlink because we're simulating windows, so
1049            # that we can generate the iss-file even on Linux
1050            install_options["do_symlink"] = 0
1051    
1052          bdist_inno.run(self, install_options)          bdist_inno.run(self, install_options)
1053        
1054                class thuban_build_docs(Command):
1055    
1056        """Command to generate documentation from source code."""
1057    
1058        description = "Generate documentation."
1059    
1060        user_options = []
1061    
1062        def initialize_options(self): pass
1063    
1064        def finalize_options(self): pass
1065    
1066        def run(self, install_options = None):
1067            self.spawn(["happydoc", "-d./Doc", "./Thuban"])
1068    
1069    class thuban_build_ext(build_ext):
1070    
1071        """Extend the build_ext command to optionally include the
1072        GDAL extension.
1073        """
1074    
1075        user_options = build_ext.user_options[:]
1076        user_options.extend([("with-gdal", None, "Include GDAL support."),
1077                             ("without-gdal", None, "Don't include GDAL support.")])
1078    
1079        boolean_options = ["with-gdal"]
1080        negative_opt = {'without-gdal' : 'with-gdal'}
1081    
1082        def initialize_options(self):
1083            self.with_gdal = True
1084            build_ext.initialize_options(self)
1085    
1086        def finalize_options(self):
1087            build_ext.finalize_options(self)
1088            if self.with_gdal and include_gdal:
1089                self.extensions.append(Extension("Lib.gdalwarp",
1090                                    [ext_dir + "/thuban/gdalwarp.cpp",
1091                                    ext_dir + "/thuban/cpl_mfile.cpp",
1092                                    ext_dir + "/thuban/bmpdataset.cpp"],
1093                                    include_dirs = gdal_cs_params[CS_INCDIRS] +
1094                                                   [ext_dir + "/thuban/"],
1095                                    define_macros = gdal_cs_params[CS_DEFS],
1096                                    library_dirs = gdal_cs_params[CS_LIBDIRS],
1097                                    libraries = gdal_cs_params[CS_LIBS]))
1098    
1099        def run(self, install_options = None):
1100            build_ext.run(self)
1101    
1102  #  #
1103  #   Run the script  #   Run the script
1104  #  #
1105    
   
1106  long_description = """\  long_description = """\
1107  Thuban is a viewer for geographic data written in Python  Thuban is a viewer for geographic data written in Python
1108  """  """
1109    
1110  setup(name = "Thuban",  setup(name = "Thuban",
1111        version = "0.0.3",        version = "1.0rc1",
1112        description = "Geographic data viewer",        description = "Geographic data viewer",
1113        long_description = long_description,        long_description = long_description,
1114        licence = "GPL",        licence = "GPL",
1115        author = "Intevation GmbH",        author = "Intevation GmbH",
1116        author_email = "[email protected]",        author_email = "[email protected]",
1117        url = "ftp:intevation.de/",        url = "http://thuban.intevation.de/",
1118    
1119        scripts = ["thuban.py"],        scripts = ["thuban.py"],
1120        packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"],        packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI",
1121                      "Extensions", "Extensions.gns2shp", "Extensions.wms",
1122                      "Extensions.importAPR", "Extensions.profiling"],
1123        ext_modules = extensions,        ext_modules = extensions,
1124        py_modules = py_modules,        py_modules = py_modules,
1125        data_files = data_files,        data_files = data_files,
# Line 710  setup(name = "Thuban", Line 1130  setup(name = "Thuban",
1130                   {"prefix": prefix,                   {"prefix": prefix,
1131                    # make sure both libs and scripts are installed in the                    # make sure both libs and scripts are installed in the
1132                    # same directory.                    # same directory.
1133                    "install_lib": "$base/thuban",                    "install_lib": "$base/lib/thuban",
1134                    "install_scripts": "$base/thuban",                    "install_scripts": "$base/lib/thuban",
1135                    "install_data": "$base/thuban",                    "install_data": "$base/lib/thuban",
1136    
1137                    # Don't print warning messages about the lib dir not                    # Don't print warning messages about the lib dir not
1138                    # being on Python's path. The libraries are Thuban                    # being on Python's path. The libraries are Thuban
# Line 731  setup(name = "Thuban", Line 1151  setup(name = "Thuban",
1151                    "install_local": InstallLocal,                    "install_local": InstallLocal,
1152                    "install": ThubanInstall,                    "install": ThubanInstall,
1153                    "bdist_rpm": thuban_bdist_rpm,                    "bdist_rpm": thuban_bdist_rpm,
1154                    "bdist_inno": thuban_bdist_inno                    "bdist_inno": thuban_bdist_inno,
1155                      "data_dist": data_dist,
1156                      "build_docs": thuban_build_docs,
1157                      "build_ext": thuban_build_ext
1158                    })                    })
1159    
1160    

Legend:
Removed from v.19  
changed lines
  Added in v.2007

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26