/[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 8 by bh, Tue Aug 28 16:48:50 2001 UTC revision 19 by bh, Tue Sep 4 15:11:27 2001 UTC
# Line 16  __version__ = "$Revision$" Line 16  __version__ = "$Revision$"
16  #  #
17    
18  import os  import os
19    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
25    from distutils.util import convert_path, change_root
26    
27  import distutils  import distutils
 print distutils.__file__  
28    
29  from string import split  from string import split
30  import string  import string
# Line 48  if os.name == "posix": Line 51  if os.name == "posix":
51    
52      # On POSIX-systems we run wxgtk-config to determine the C++-compiler      # On POSIX-systems we run wxgtk-config to determine the C++-compiler
53      # flags      # flags
54      wx_config_script = "wxgtk-config"      wx_config_script = "wx-config"
55      # These lists will be filled automatically below      # These lists will be filled automatically below
56      wx_defs = []      wx_defs = []
57      wx_incdirs = []      wx_incdirs = []
# Line 66  elif os.name == "nt": Line 69  elif os.name == "nt":
69      proj4_libdir =  proj4_prefix      proj4_libdir =  proj4_prefix
70      proj4_lib = "proj_i"      proj4_lib = "proj_i"
71    
72        # Define include and lib directories for wxWindows and
73        wx_prefix = r"D:\wx230"
74        wx_inc =  os.path.join(wx_prefix, "include")
75        wx_lib =  os.path.join(wx_prefix, "lib")
76    
77      #      #
78      # Unless you use a wxPython version other than 2.3.1, you probably      # Unless you use a wxPython version other than 2.3.1, you probably
79      # shouldn't have to modify anything below here      # shouldn't have to modify anything below here
# Line 83  elif os.name == "nt": Line 91  elif os.name == "nt":
91      # there's no config script.      # there's no config script.
92      wx_config_script = ""      wx_config_script = ""
93            
     # so we just define the flags manually  
     wx_prefix = r"D:\wx230"  
     wx_inc =  os.path.join(wx_prefix, "include")  
     wx_lib =  os.path.join(wx_prefix, "lib")  
94      # the values of wx_defs and wx_libs. copied from the wxPython      # the values of wx_defs and wx_libs. copied from the wxPython
95      # setup.py      # setup.py
96      wx_defs = [ ('WIN32', None),        # Some of these are no longer      wx_defs = [ ('WIN32', None),        # Some of these are no longer
# Line 139  def run_script(cmdline): Line 143  def run_script(cmdline):
143    
144    
145  def run_wx_script(command):  def run_wx_script(command):
146      # first, determine the C++ preprocessor flags      # first, determine the C++ preprocessor flags Use --cflags here
147      flags = run_script(command + ' --cxxflags ')      # because it seems that older version don't have --cxxflags and
148        # newer ones return the same result for both
149        flags = run_script(command + ' --cflags ')
150      if flags is None:      if flags is None:
151          return 0          return 0
152      for flag in split(flags):      for flag in split(flags):
# Line 232  py_modules.append(ext_dir + "/pyprojecti Line 238  py_modules.append(ext_dir + "/pyprojecti
238  data_files = []  data_files = []
239    
240  # bitmaps  # bitmaps
241  dir = "Resources/Bitmaps/"  dir = "Resources/Bitmaps"
242  bitmaps = []  bitmaps = []
243  for file in os.listdir(os.path.join("Resources", "Bitmaps")):  for file in os.listdir(os.path.join("Resources", "Bitmaps")):
244      if string.lower(file[-4:]) == ".xpm":      if string.lower(file[-4:]) == ".xpm":
245          bitmaps.append(dir + file)          bitmaps.append(dir + '/' +  file)
246  data_files.append((dir, bitmaps))  data_files.append((dir, bitmaps))
247    
248  #  #
# Line 259  class InstallLocal(Command): Line 265  class InstallLocal(Command):
265          "Create some symlink so you can run thubanfrom the source directory"          "Create some symlink so you can run thubanfrom the source directory"
266    
267      user_options = [      user_options = [
         ('debug', 'g', "compile/link with debugging information"),  
268          ('skip-build', None, "skip the build steps"),          ('skip-build', None, "skip the build steps"),
269          ]          ]
270    
# Line 267  class InstallLocal(Command): Line 272  class InstallLocal(Command):
272          self.extensions = None          self.extensions = None
273          self.build_dir = None          self.build_dir = None
274          self.skip_build = None          self.skip_build = None
         self.debug = None  
275    
276      def finalize_options (self):      def finalize_options (self):
277          self.set_undefined_options("install",          self.set_undefined_options("install",
# Line 290  class InstallLocal(Command): Line 294  class InstallLocal(Command):
294      def link_dir(self, src, dest):      def link_dir(self, src, dest):
295          """Create a symbolic link dest pointing to src"""          """Create a symbolic link dest pointing to src"""
296          if self.verbose:          if self.verbose:
297              print "symlinking %s -> %s" % (src, dest)              self.announce("symlinking %s -> %s" % (src, dest))
298          if self.dry_run:          if self.dry_run:
299              return              return
300    
# Line 348  class thuban_build_py(build_py): Line 352  class thuban_build_py(build_py):
352              modules.append(("Lib", module_base, module_file))              modules.append(("Lib", module_base, module_file))
353          return modules          return modules
354    
355        def find_all_modules (self):
356            # same as find_all_modules of the original build_py command
357            # (rev. 1.33) but handle installations with both modules and
358            # packages. Needed here so tha the get_outputs works correctly
359            modules = []
360            if self.py_modules:
361                modules.extend(self.find_modules())
362            if self.packages:
363                for package in self.packages:
364                    package_dir = self.get_package_dir(package)
365                    m = self.find_package_modules(package, package_dir)
366                    modules.extend(m)
367    
368            return modules
369    
370    
371    
372  class ThubanInstall(install):  class ThubanInstall(install):
373    
# Line 357  class ThubanInstall(install): Line 377  class ThubanInstall(install):
377      Extend the standard install command to symlink the installed script      Extend the standard install command to symlink the installed script
378      to $prefix/bin/      to $prefix/bin/
379      """      """
380    
381        user_options = install.user_options[:]
382        user_options.extend([("do-symlink", None,
383                              "Create a symlink to the script in <prefix>/bin."
384                            "(default on posix systems and only relevant there)"),
385    
386                             ("extra-files", None,
387                              "List of filenames or (src, dest) pairs describing "
388                              " extra files to install "
389                              "(can only be set from witin setup.py"),
390                             ])
391    
392        boolean_options = install.boolean_options[:]
393        boolean_options.append("do-symlink")
394    
395        def initialize_options(self):
396            self.do_symlink = None
397            self.extra_files = []
398            install.initialize_options(self)
399    
400        def finalize_options(self):
401            if self.do_symlink is None:
402                if os.name == "posix":
403                    self.do_symlink = 1
404                else:
405                    self.do_symlink = 0
406            install.finalize_options(self)
407    
408      def run(self):      def run(self):
409          install.run(self)          install.run(self)
410          if os.name == "posix":          for item in self.extra_files:
411              scriptfile = os.path.join(self.install_scripts, "thuban.py")              if type(item) == TupleType:
412                    src, dest = item
413                else:
414                    src = dest = item
415                self.copy_file(convert_path(src),
416                               os.path.join(self.root, convert_path(dest)))
417    
418            if os.name == "posix" and self.do_symlink:
419                install_scripts = self.install_scripts
420                if self.root:
421                    install_scripts = install_scripts[len(self.root):]
422                scriptfile = os.path.join(install_scripts, "thuban.py")
423              bindir = os.path.join(self.prefix, "bin")              bindir = os.path.join(self.prefix, "bin")
424                if self.root:
425                    bindir = change_root(self.root, bindir)
426              binfile = os.path.join(bindir, "thuban")              binfile = os.path.join(bindir, "thuban")
427              self.mkpath(bindir)              self.mkpath(bindir)
428              self.copy_file(scriptfile, binfile, link="sym")              self.link_file(scriptfile, binfile)
429    
430        def link_file(self, src, dest):
431            """Create a symbolic link dest pointing to src.
432    
433            Unlike the symlink variant of the command object's copy_file
434            method, this method even performs the link if src doesn't exist.
435            This is useful when installing with an alternat root directory"""
436            if self.verbose:
437                self.announce("symlinking %s -> %s" % (src, dest))
438            if self.dry_run:
439                return
440    
441            if not os.path.exists(dest):
442                os.symlink(src, dest)
443    
444    
445        def get_outputs (self):
446            outputs = install.get_outputs(self)
447            for item in self.extra_files:
448                if type(item) == TupleType:
449                    src, dest = item
450                else:
451                    src = dest = item
452                outputs.append(os.path.join(self.root, convert_path(dest)))
453            if os.name == "posix" and self.do_symlink:
454                bindir = os.path.join(self.prefix, "bin")
455                if self.root:
456                    bindir = change_root(self.root, bindir)
457                binfile = os.path.join(bindir, "thuban")
458                outputs.append(binfile)
459            return outputs
460    
461    
462    bdist_rpm_prep_script = '''
463    %setup
464    cp extensions/pyshapelib/{README,README.pyshapelib}
465    cp extensions/pyshapelib/{COPYING,COPYING.pyshapelib}
466    cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}
467    '''
468    
469    
470        
471    class thuban_bdist_rpm(bdist_rpm):
472    
473        """Thuban specific RPM distribution command"""
474    
475        def run(self):
476            # create the prep script for the spec-file
477            open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)
478    
479            bdist_rpm.run(self)
480    
481    
482    class bdist_inno(Command):
483    
484        """Command to create a windows installer with Inno Setup"""
485    
486        description = "Create a windows installer with Inno Setup"
487    
488        user_options = [
489            ('skip-build', None, "skip the build steps"),
490            ('bdist-dir=', None,
491             "temporary directory for creating the distribution"),
492            ('run-inno', None,
493             "Run inno-setup to create the installer. On by default on nt"),
494            ('iss-name', None,
495             "The name of the iss file to generate. "
496             "Shouldn't contain directories"),
497    
498            # Parameters for the Inno Setup script
499            ('copyright', None, "Copyright notice for the Inno Setup file"),
500            ('default-dir-name', None,
501             "Default installation directory. Defaults to '{pf}\\<name>'"),
502            ('default-group-name', None,
503             "Default program group name. Defaults to <name>'"),
504            ("license-file", None, "File containing the license."),
505            ("output-basename", None,
506             "Base filename for the Inno Setup output "
507             "(defaults to <name>-<version>-<issrevision>)."),
508            ("iss-revision", None,
509             "revision of the generated installer of the package version"),
510    
511            ("icons-entries", None,
512             "List if InnoIconItems "
513             "(this can only be set from inside the setup.py script)"),
514            ]
515    
516        boolean_options = ["do-symlink"]
517    
518        def initialize_options(self):
519            self.skip_build = 0
520            self.bdist_dir = None
521            self.run_inno = None
522            self.iss_name = None
523            self.copyright = ""
524            self.default_dir_name = None
525            self.default_group_name = None
526            self.license_file = None
527            self.output_basename = None
528            self.iss_revision = None
529            self.icons_entries = []
530    
531        def finalize_options(self):
532            self.set_undefined_options("install",
533                                       ('skip_build', 'skip_build'))
534            if self.bdist_dir is None:
535                bdist_base = self.get_finalized_command('bdist').bdist_base
536                self.bdist_dir = os.path.join(bdist_base, 'inno')
537    
538            if self.run_inno is None:
539                self.run_inno = os.name == "nt"
540    
541            name = self.distribution.get_name()
542            if self.iss_name is None:
543                self.iss_name = name + '.iss'
544    
545            if self.default_dir_name is None:
546                self.default_dir_name = "{pf}\\" + name
547            if self.default_group_name is None:
548                self.default_group_name = name
549    
550            if self.iss_revision is None:
551                self.iss_revision = 0
552            if self.output_basename is None:
553                self.output_basename = "%s-%s-%d" \
554                                       % (name, self.distribution.get_version(),
555                                          self.iss_revision)
556    
557        def run(self, install_options = None):
558            """Execute the command. install_options if given, should be a
559            directory of additional options to set in the install step"""
560            # Obviously have to build before we can install
561            if not self.skip_build:
562                self.run_command('build')
563    
564            # Install in a temporary directory
565            install = self.reinitialize_command('install')
566            install.root = self.bdist_dir
567            if install_options is not None:
568                for key, value in install_options.items():
569                    setattr(install, key, value)
570            if os.name != 'nt':
571                # Must force install to use the 'nt' scheme;
572                install.select_scheme('nt')
573                # don't make a symlink because we're simulating windows, so
574                # that we can generate the iss-file even on Linux
575                install.do_symlink = 0
576    
577            self.announce("installing to %s" % self.bdist_dir)
578            install.ensure_finalized()
579            install.run()
580    
581            # Create the iss file
582            iss_file = os.path.join(self.bdist_dir, self.iss_name)
583            self.execute(write_file, (iss_file, self.generate_iss()),
584                         "Create Inno Setup script file %s" % iss_file)
585    
586            # and invoke
587            if self.run_inno:
588                self.spawn(["iscc", iss_file])
589    
590        def generate_iss(self):
591            """Return the contents of the iss file as list of strings, one
592            string per line"""
593    
594            # first, turn the icons entries into a more usable form
595            icons = {}
596            for item in self.icons_entries:
597                icons[item.filename] = item
598    
599            iss = []
600    
601            name = self.distribution.get_name()
602            iss.extend(["[Setup]",
603                        "AppName=" + name,
604                        "AppVerName=" + name + " "+self.distribution.get_version(),
605                        "DefaultDirName=" + self.default_dir_name,
606                        "DefaultGroupName=" + self.default_group_name,
607                        ])
608            if self.copyright:
609                iss.append("AppCopyright=" + self.copyright)
610            if self.license_file:
611                iss.append("LicenseFile=" + self.license_file)
612    
613            iss.append("OutputBasefilename=" + self.output_basename)
614    
615            iss.append("")
616            iss.append("[Files]")
617    
618            install = self.get_finalized_command("install")
619            install_scripts = self.get_finalized_command("install_scripts")
620            script_files = install_scripts.get_outputs()
621            prefixlen = len(self.bdist_dir) + len(os.sep)
622            for filename in install.get_outputs():
623                filename = filename[prefixlen:]
624                icon = icons.get(filename)
625                dirname = os.path.dirname(filename)
626                if os.name != "nt":
627                    # change the separators to \ on non-windos systems
628                    filename = string.join(string.split(filename, os.sep), "\\")
629                    dirname =  string.join(string.split(dirname, os.sep), "\\")
630                line = 'Source: "%s"' % filename
631                if icon is not None:
632                    # install it as defined in the icon object
633                    backslash = string.rfind(icon.install_name, "\\")
634                    if backslash >= 0:
635                        dirname = icon.install_name[:backslash]
636                        basename = icon.install_name[backslash + 1:]
637                    else:
638                        dirname = ""
639                        basename = icon.install_name
640                    line = '%s; DestDir: "%s"; DestName: "%s"' % (line, dirname,
641                                                                  basename)
642                else:
643                    line = line + '; DestDir: "{app}\\%s"' % (dirname)
644                iss.append(line)
645    
646            iss.append("")
647            iss.append("[Icons]")
648            for icon in self.icons_entries:
649                line = 'Name: "{group}\\%s"; Filename: "%s";' \
650                       % (icon.title, icon.install_name)
651                iss.append(line)
652                
653            return iss
654    
655    
656    class InnoIconItem:
657    
658        """Describe one item for he start menu for the Inno Setup installer"""
659    
660        def __init__(self, filename, title, install_name = None):
661            self.filename = filename
662            self.title = title
663            if install_name is not None:
664                self.install_name = install_name
665            else:
666                self.install_name = filename
667    
668    
669    class thuban_bdist_inno(bdist_inno):
670    
671        """Thuban specific Inno Setup stuff"""
672    
673        def run(self):
674            install_options = {
675                "prefix": ".",
676                "install_scripts": "$base",
677                "warn_dir": 0,
678                "extra_files": ["COPYING", "Lib/proj.dll"],
679                }
680            bdist_inno.run(self, install_options)
681        
682                
683    #
684    #   Run the script
685    #
686    
687    
688  long_description = """\  long_description = """\
689  Thuban is a viewer for geographic data written in Python  Thuban is a viewer for geographic data written in Python
690  """  """
691    
692  setup(name = "thuban",  setup(name = "Thuban",
693        version = "0.0.3",        version = "0.0.3",
694        description = "Geographic data viewer",        description = "Geographic data viewer",
695        long_description = long_description,        long_description = long_description,
# Line 394  setup(name = "thuban", Line 712  setup(name = "thuban",
712                    # same directory.                    # same directory.
713                    "install_lib": "$base/thuban",                    "install_lib": "$base/thuban",
714                    "install_scripts": "$base/thuban",                    "install_scripts": "$base/thuban",
715                    "install_data": "$base/thuban/",                    "install_data": "$base/thuban",
716    
717                    # Don't print warning messages about the lib dir not                    # Don't print warning messages about the lib dir not
718                    # being on Python's path. The libraries are Thuban                    # being on Python's path. The libraries are Thuban
719                    # specific and are installed just for Thuban. They'll                    # specific and are installed just for Thuban. They'll
720                    # be automatically on Python's path when Thuban is run                    # be automatically on Python's path when Thuban is run
721                    "warn_dir": 0,                    "warn_dir": 0,
722                    }},                    },
723                     "bdist_inno":
724                     {"icons_entries": [InnoIconItem(".\\thuban.py",
725                                                     "Start Thuban",
726                                                     "{app}\\thuban.pyw")],
727                      "license_file": "COPYING",
728                      }
729                     },
730        cmdclass = {"build_py": thuban_build_py,        cmdclass = {"build_py": thuban_build_py,
731                    "install_local": InstallLocal,                    "install_local": InstallLocal,
732                    "install": ThubanInstall})                    "install": ThubanInstall,
733                      "bdist_rpm": thuban_bdist_rpm,
734                      "bdist_inno": thuban_bdist_inno
735                      })
736    
737    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26