/[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 15 by bh, Fri Aug 31 15:35:18 2001 UTC revision 97 by bh, Thu Apr 11 09:53:02 2002 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001 by Intevation GmbH  # Copyright (c) 2001, 2002 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 20  from types import TupleType Line 20  from types import TupleType
20  from distutils.core import setup, Extension, Command  from distutils.core import setup, Extension, Command
21  from distutils.command.install import install  from distutils.command.install import install
22  from distutils.command.build_py import build_py  from distutils.command.build_py import build_py
23    from distutils.command.bdist_rpm import bdist_rpm
24  from distutils.file_util import write_file  from distutils.file_util import write_file
25  from distutils.util import convert_path  from distutils.filelist import FileList
26    from distutils.util import convert_path, change_root
27    
28    from distutils import archive_util, dir_util
29  import distutils  import distutils
30    
31  from string import split  from string import split
# Line 50  if os.name == "posix": Line 53  if os.name == "posix":
53    
54      # On POSIX-systems we run wxgtk-config to determine the C++-compiler      # On POSIX-systems we run wxgtk-config to determine the C++-compiler
55      # flags      # flags
56      wx_config_script = "wxgtk-config"      wx_config_script = "wx-config"
57      # These lists will be filled automatically below      # These lists will be filled automatically below
58      wx_defs = []      wx_defs = []
59      wx_incdirs = []      wx_incdirs = []
# Line 142  def run_script(cmdline): Line 145  def run_script(cmdline):
145    
146    
147  def run_wx_script(command):  def run_wx_script(command):
148      # first, determine the C++ preprocessor flags      # first, determine the C++ preprocessor flags Use --cflags here
149      flags = run_script(command + ' --cxxflags ')      # because it seems that older version don't have --cxxflags and
150        # newer ones return the same result for both
151        flags = run_script(command + ' --cflags ')
152      if flags is None:      if flags is None:
153          return 0          return 0
154      for flag in split(flags):      for flag in split(flags):
# Line 195  py_modules = [] Line 200  py_modules = []
200  #  #
201    
202  extensions.append(Extension("Lib.wxproj",  extensions.append(Extension("Lib.wxproj",
203                              [ext_dir + "/thuban/wxproj.cpp",                              [ext_dir + "/thuban/wxproj.cpp"],
204                               shp_dir + "/shpopen.c"],                              include_dirs = ([shp_dir, proj4_incdir,
205                              include_dirs = [shp_dir, proj4_incdir] +wx_incdirs,                                               ext_dir + "/pyshapelib/"]
206                                                + wx_incdirs),
207                              define_macros = wx_defs,                              define_macros = wx_defs,
208                              library_dirs = [proj4_libdir] + wx_libdirs,                              library_dirs = [proj4_libdir] + wx_libdirs,
209                              libraries = [proj4_lib] + wx_libs))                              libraries = [proj4_lib] + wx_libs))
# Line 247  data_files.append((dir, bitmaps)) Line 253  data_files.append((dir, bitmaps))
253  #  #
254  # So far distutils are only meant to distribute python extensions, not  # So far distutils are only meant to distribute python extensions, not
255  # complete applications, so we have to redefine a few commands  # complete applications, so we have to redefine a few commands
256    #
257    
258    
259    # Much of the data_dist command is directly copied from the distutils'
260    # sdist command
261    class data_dist(Command):
262    
263        description = "create a data distribution (tarball, zip file, etc.)"
264    
265        user_options = [
266            ('formats=', None,
267             "formats for source distribution (comma-separated list)"),
268            ('keep-temp', 'k',
269             "keep the distribution tree around after creating " +
270             "archive file(s)"),
271            ('dist-dir=', 'd',
272             "directory to put the source distribution archive(s) in "
273             "[default: dist]"),
274            ]
275    
276        boolean_options = ['keep-temp']
277    
278        def initialize_options (self):
279            self.formats = None
280            self.keep_temp = 0
281            self.dist_dir = None
282    
283        def finalize_options (self):
284            self.ensure_string_list('formats')
285            if self.formats is None:
286                self.formats = ["zip"]
287            bad_format = archive_util.check_archive_formats(self.formats)
288            if bad_format:
289                raise DistutilsOptionError, \
290                      "unknown archive format '%s'" % bad_format
291    
292            if self.dist_dir is None:
293                self.dist_dir = "dist"
294    
295    
296        def run(self):
297            # 'filelist' contains the list of files that will make up the
298            # manifest
299            self.filelist = FileList()
300            
301            # Do whatever it takes to get the list of files to process.
302            # File list is accumulated in 'self.filelist'.
303            self.get_file_list()
304    
305            # Otherwise, go ahead and create the source distribution tarball,
306            # or zipfile, or whatever.
307            self.make_distribution()
308    
309        def get_file_list(self):
310            """Figure out the list of files to include in the data
311            distribution, and put it in 'self.filelist'.
312            """
313            self.filelist.findall("Data")
314            self.filelist.include_pattern("*", anchor = 0)
315            self.filelist.exclude_pattern(r'/(RCS|CVS)/.*', is_regex=1)
316            self.filelist.sort()
317            self.filelist.remove_duplicates()
318    
319        def make_release_tree(self, base_dir, files):
320            """Create the directory tree that will become the source
321            distribution archive.  All directories implied by the filenames in
322            'files' are created under 'base_dir', and then we hard link or copy
323            (if hard linking is unavailable) those files into place.
324            Essentially, this duplicates the developer's source tree, but in a
325            directory named after the distribution, containing only the files
326            to be distributed.
327            """
328            # Create all the directories under 'base_dir' necessary to
329            # put 'files' there; the 'mkpath()' is just so we don't die
330            # if the manifest happens to be empty.
331            self.mkpath(base_dir)
332            dir_util.create_tree(base_dir, files,
333                                 verbose=self.verbose, dry_run=self.dry_run)
334    
335            # And walk over the list of files, either making a hard link (if
336            # os.link exists) to each one that doesn't already exist in its
337            # corresponding location under 'base_dir', or copying each file
338            # that's out-of-date in 'base_dir'.  (Usually, all files will be
339            # out-of-date, because by default we blow away 'base_dir' when
340            # we're done making the distribution archives.)
341        
342            if hasattr(os, 'link'):        # can make hard links on this system
343                link = 'hard'
344                msg = "making hard links in %s..." % base_dir
345            else:                           # nope, have to copy
346                link = None
347                msg = "copying files to %s..." % base_dir
348    
349            if not files:
350                self.warn("no files to distribute -- empty manifest?")
351            else:
352                self.announce(msg)
353            for file in files:
354                if not os.path.isfile(file):
355                    self.warn("'%s' not a regular file -- skipping" % file)
356                else:
357                    dest = os.path.join(base_dir, file)
358                    self.copy_file(file, dest, link=link)
359    
360    
361        def make_distribution (self):
362            """Create the source distribution(s).  First, we create the release
363            tree with 'make_release_tree()'; then, we create all required
364            archive files (according to 'self.formats') from the release tree.
365            Finally, we clean up by blowing away the release tree (unless
366            'self.keep_temp' is true).  The list of archive files created is
367            stored so it can be retrieved later by 'get_archive_files()'.
368            """
369            # Don't warn about missing meta-data here -- should be (and is!)
370            # done elsewhere.
371            base_dir = "Thuban-data-" + self.distribution.get_version()
372            base_name = os.path.join(self.dist_dir, base_dir)
373    
374            self.make_release_tree(base_dir, self.filelist.files)
375            archive_files = []              # remember names of files we create
376            for fmt in self.formats:
377                file = self.make_archive(base_name, fmt, base_dir=base_dir)
378                archive_files.append(file)
379    
380            self.archive_files = archive_files
381    
382            if not self.keep_temp:
383                dir_util.remove_tree(base_dir, self.verbose, self.dry_run)
384    
385    
386    
# Line 259  class InstallLocal(Command): Line 393  class InstallLocal(Command):
393      """      """
394    
395      description =\      description =\
396          "Create some symlink so you can run thubanfrom the source directory"          "Create some symlinks so you can run thuban from the source directory"
397    
398      user_options = [      user_options = [
399          ('skip-build', None, "skip the build steps"),          ('skip-build', None, "skip the build steps"),
# Line 283  class InstallLocal(Command): Line 417  class InstallLocal(Command):
417          # now do the work. Simply link or copy the Lib dir          # now do the work. Simply link or copy the Lib dir
418          libdir = os.path.join(self.build_dir, "Lib")          libdir = os.path.join(self.build_dir, "Lib")
419          if os.name == "posix":          if os.name == "posix":
420              # on posix, just lilnk the Lib dir              # on posix, just link the Lib dir
421              self.link_dir(libdir, "Lib")              self.link_dir(libdir, "Lib")
422          else:          else:
423              self.copy_tree(libdir, "Lib")              self.copy_tree(libdir, "Lib")
# Line 413  class ThubanInstall(install): Line 547  class ThubanInstall(install):
547                             os.path.join(self.root, convert_path(dest)))                             os.path.join(self.root, convert_path(dest)))
548    
549          if os.name == "posix" and self.do_symlink:          if os.name == "posix" and self.do_symlink:
550              scriptfile = os.path.join(self.install_scripts, "thuban.py")              install_scripts = self.install_scripts
551                if self.root:
552                    install_scripts = install_scripts[len(self.root):]
553                scriptfile = os.path.join(install_scripts, "thuban.py")
554              bindir = os.path.join(self.prefix, "bin")              bindir = os.path.join(self.prefix, "bin")
555                if self.root:
556                    bindir = change_root(self.root, bindir)
557              binfile = os.path.join(bindir, "thuban")              binfile = os.path.join(bindir, "thuban")
558              self.mkpath(bindir)              self.mkpath(bindir)
559              self.copy_file(scriptfile, binfile, link="sym")              self.link_file(scriptfile, binfile)
560    
561        def link_file(self, src, dest):
562            """Create a symbolic link dest pointing to src.
563    
564            Unlike the symlink variant of the command object's copy_file
565            method, this method even performs the link if src doesn't exist.
566            This is useful when installing with an alternat root directory"""
567            if self.verbose:
568                self.announce("symlinking %s -> %s" % (src, dest))
569            if self.dry_run:
570                return
571    
572            if not os.path.exists(dest):
573                os.symlink(src, dest)
574    
575    
576      def get_outputs (self):      def get_outputs (self):
577          outputs = install.get_outputs(self)          outputs = install.get_outputs(self)
# Line 427  class ThubanInstall(install): Line 581  class ThubanInstall(install):
581              else:              else:
582                  src = dest = item                  src = dest = item
583              outputs.append(os.path.join(self.root, convert_path(dest)))              outputs.append(os.path.join(self.root, convert_path(dest)))
584            if os.name == "posix" and self.do_symlink:
585                bindir = os.path.join(self.prefix, "bin")
586                if self.root:
587                    bindir = change_root(self.root, bindir)
588                binfile = os.path.join(bindir, "thuban")
589                outputs.append(binfile)
590          return outputs          return outputs
591    
592    
593    bdist_rpm_prep_script = '''
594    %setup
595    cp extensions/pyshapelib/{README,README.pyshapelib}
596    cp extensions/pyshapelib/{COPYING,COPYING.pyshapelib}
597    cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}
598    '''
599    
600    
601        
602    class thuban_bdist_rpm(bdist_rpm):
603    
604        """Thuban specific RPM distribution command"""
605    
606        def initialize_options(self):
607            # create the prep script for the spec-file
608            open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)
609    
610            bdist_rpm.initialize_options(self)
611    
612    
613  class bdist_inno(Command):  class bdist_inno(Command):
614    
615      """Command to create a windows installer with Inno Setup"""      """Command to create a windows installer with Inno Setup"""
# Line 520  class bdist_inno(Command): Line 701  class bdist_inno(Command):
701          if os.name != 'nt':          if os.name != 'nt':
702              # Must force install to use the 'nt' scheme;              # Must force install to use the 'nt' scheme;
703              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  
704    
705          self.announce("installing to %s" % self.bdist_dir)          self.announce("installing to %s" % self.bdist_dir)
706          install.ensure_finalized()          install.ensure_finalized()
# Line 605  class bdist_inno(Command): Line 783  class bdist_inno(Command):
783    
784  class InnoIconItem:  class InnoIconItem:
785    
786      """Describe one item for he start menu for the Inno Setup installer"""      """Describe one item for the start menu for the Inno Setup installer"""
787    
788      def __init__(self, filename, title, install_name = None):      def __init__(self, filename, title, install_name = None):
789          self.filename = filename          self.filename = filename
# Line 615  class InnoIconItem: Line 793  class InnoIconItem:
793          else:          else:
794              self.install_name = filename              self.install_name = filename
795    
796                
797  class thuban_bdist_inno(bdist_inno):  class thuban_bdist_inno(bdist_inno):
798    
799      """Thuban specific Inno Setup stuff"""      """Thuban specific Inno Setup stuff"""
# Line 627  class thuban_bdist_inno(bdist_inno): Line 805  class thuban_bdist_inno(bdist_inno):
805              "warn_dir": 0,              "warn_dir": 0,
806              "extra_files": ["COPYING", "Lib/proj.dll"],              "extra_files": ["COPYING", "Lib/proj.dll"],
807              }              }
808            # don't make a symlink because we're simulating windows, so
809            # that we can generate the iss-file even on Linux
810            install_options["do_symlink"] = 0
811          bdist_inno.run(self, install_options)          bdist_inno.run(self, install_options)
812            
813                            
# Line 640  Thuban is a viewer for geographic data w Line 821  Thuban is a viewer for geographic data w
821  """  """
822    
823  setup(name = "Thuban",  setup(name = "Thuban",
824        version = "0.0.3",        version = "0.1.1",
825        description = "Geographic data viewer",        description = "Geographic data viewer",
826        long_description = long_description,        long_description = long_description,
827        licence = "GPL",        licence = "GPL",
# Line 680  setup(name = "Thuban", Line 861  setup(name = "Thuban",
861        cmdclass = {"build_py": thuban_build_py,        cmdclass = {"build_py": thuban_build_py,
862                    "install_local": InstallLocal,                    "install_local": InstallLocal,
863                    "install": ThubanInstall,                    "install": ThubanInstall,
864                    "bdist_inno": thuban_bdist_inno                    "bdist_rpm": thuban_bdist_rpm,
865                      "bdist_inno": thuban_bdist_inno,
866                      "data_dist": data_dist
867                    })                    })
868    
869    

Legend:
Removed from v.15  
changed lines
  Added in v.97

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26