/[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 203 by bh, Mon Jul 8 15:04:57 2002 UTC revision 928 by jonathan, Tue May 20 15:22:10 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# 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.file_util import write_file  from distutils.file_util import write_file
# Line 43  if os.name == "posix": Line 44  if os.name == "posix":
44      proj4_lib = "proj"      proj4_lib = "proj"
45    
46    
47      # You shpuldn't have to modify anything below here      # You shouldn't have to modify anything below here
48      ###################################################################      ###################################################################
49            
50      # The installation prefix (similar to autoconf's --prefix). This is      # The installation prefix (similar to autoconf's --prefix). This is
# Line 54  if os.name == "posix": Line 55  if os.name == "posix":
55      # command completely independend of this one.      # command completely independend of this one.
56      prefix = "/usr/local/"      prefix = "/usr/local/"
57    
58        # Whether to create the thubaninit module. You can override this
59        # value on the commandline with the --create-init-module to the
60        # install command.
61        create_init_module = 1
62    
63      # On POSIX-systems we run wxgtk-config to determine the C++-compiler      # On POSIX-systems we run wxgtk-config to determine the C++-compiler
64      # flags      # flags
65      wx_config_script = "wx-config"      wx_config_script = "wx-config"
# Line 75  elif os.name == "nt": Line 81  elif os.name == "nt":
81      proj4_lib = "proj_i"      proj4_lib = "proj_i"
82    
83      # Define include and lib directories for wxWindows and      # Define include and lib directories for wxWindows and
84      wx_prefix = r"D:\wx230"      wx_prefix = r"D:\wx240"
85      wx_inc =  os.path.join(wx_prefix, "include")      wx_inc = [os.path.join(wx_prefix, 'lib', 'mswdllh'),
86      wx_lib =  os.path.join(wx_prefix, "lib")                os.path.join(wx_prefix, "include")]
87        wx_lib = [os.path.join(wx_prefix, "lib")]
88    
89    
90      #      #
91      # 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
92      # shouldn't have to modify anything below here      # shouldn't have to modify anything below here
93      ##################################################################      ##################################################################
94            
# Line 89  elif os.name == "nt": Line 97  elif os.name == "nt":
97      # the command line with the install command's --prefix option      # the command line with the install command's --prefix option
98      prefix = r"install"      prefix = r"install"
99    
100        # Whether to create the thubaninit module. You can override this
101        # value on the commandline with the --create-init-module to the
102        # install command. By default we don't create it under NT because we
103        # most often run install only as part of bdist_inno where we can't
104        # really create because it needs information only known at install
105        # time.
106        create_init_module = 0
107    
108      # 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
109      # flags, so we define them here. These flags work for us with      # flags, so we define them here. These flags work for us with
110      # 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 114  elif os.name == "nt": Line 130  elif os.name == "nt":
130                  ('WXP_USE_THREAD', '1'),                  ('WXP_USE_THREAD', '1'),
131                  ]                  ]
132            
133      wx_incdirs = [wx_inc]      wx_incdirs = wx_inc
134      wx_libdirs = [wx_lib]      wx_libdirs = wx_lib
135      wx_libs = ["wx23_1h"]      wx_libs = ["wxmsw24h"]
136    
137      wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32',      wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32',
138                           'winspool', 'winmm', 'shell32', 'oldnames',                           'winspool', 'winmm', 'shell32', 'oldnames',
139                           'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32',                           'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32',
# Line 211  extensions.append(Extension("Lib.wxproj" Line 228  extensions.append(Extension("Lib.wxproj"
228                              library_dirs = [proj4_libdir] + wx_libdirs,                              library_dirs = [proj4_libdir] + wx_libdirs,
229                              libraries = [proj4_lib] + wx_libs))                              libraries = [proj4_lib] + wx_libs))
230    
231    extensions.append(Extension("Lib.gdalwarp",
232                                [ext_dir + "/thuban/gdalwarp.cpp",
233                                 ext_dir + "/thuban/cpl_mfile.cpp",
234                                 ext_dir + "/thuban/bmpdataset.cpp"],
235                                libraries = [proj4_lib] + ["gdal.1.1"]))
236    
237    
238  #  #
239  # shapelib wrappers are also distributed with thuban  # shapelib wrappers are also distributed with thuban
240  #  #
# Line 248  py_modules.append(ext_dir + "/pyprojecti Line 272  py_modules.append(ext_dir + "/pyprojecti
272  data_files = []  data_files = []
273    
274  # bitmaps  # bitmaps
275  dir = "Resources/Bitmaps"  for d, pattern in [("Resources/Bitmaps", "Resources/Bitmaps/*.xpm"),
276  bitmaps = []                     ("Resources/Locale", "Resources/Locale/*/LC_MESSAGES/*.mo")
277  for file in os.listdir(os.path.join("Resources", "Bitmaps")):                     ]:
278      if string.lower(file[-4:]) == ".xpm":      data_files.append((d, glob.glob(pattern)))
         bitmaps.append(dir + '/' +  file)  
 data_files.append((dir, bitmaps))  
279    
280  #  #
281  #       Command definitions  #       Command definitions
# Line 404  class InstallLocal(Command): Line 426  class InstallLocal(Command):
426    
427      user_options = [      user_options = [
428          ('skip-build', None, "skip the build steps"),          ('skip-build', None, "skip the build steps"),
429            ('create-init-module', None,
430             "Create the thubaninit.py module to ease use of Thuban as a library"),
431            ('dont-create-init-module', None,
432             "Do not create the thubaninit.py module"),
433          ]          ]
434    
435        boolean_options = ["create-init-module"]
436        negative_opt = {'dont-create-init-module' : 'create-init-module'}
437    
438    
439      def initialize_options (self):      def initialize_options (self):
440          self.extensions = None          self.extensions = None
441          self.build_dir = None          self.build_dir = None
442          self.skip_build = None          self.skip_build = None
443            self.create_init_module = None
444    
445      def finalize_options (self):      def finalize_options (self):
446          self.set_undefined_options("install",          self.set_undefined_options("install",
447                                     ("build_lib", "build_dir"),                                     ("build_lib", "build_dir"),
448                                     ('skip_build', 'skip_build'))                                     ('skip_build', 'skip_build'))
449          self.extensions = self.distribution.ext_modules          self.extensions = self.distribution.ext_modules
450            if self.create_init_module is None:
451                # by default we create the init module
452                self.create_init_module = 1
453    
454      def run(self):      def run(self):
455          # Make sure we have built everything we need first          # Make sure we have built everything we need first
# Line 429  class InstallLocal(Command): Line 463  class InstallLocal(Command):
463          else:          else:
464              self.copy_tree(libdir, "Lib")              self.copy_tree(libdir, "Lib")
465    
466            # create the init module if desired
467            if self.create_init_module:
468                # create the init module
469                initfilename = "thubaninit.py"
470                contents = thubaninit_contents("")
471                self.execute(write_file, (initfilename, contents),
472                             "Create %s" % initfilename)
473    
474      def link_dir(self, src, dest):      def link_dir(self, src, dest):
475          """Create a symbolic link dest pointing to src"""          """Create a symbolic link dest pointing to src"""
476          if self.verbose:          if self.verbose:
# Line 455  class thuban_build_py(build_py): Line 497  class thuban_build_py(build_py):
497      distribution.      distribution.
498      """      """
499    
500        # FIXME: When Thuban can rely on Python 2.3 as the oldest supported
501        # Python release we don't need to override the run and
502        # find_all_modules methods anymore. distutils will allow both python
503        # modules and packages starting with 2.3.
504    
505      def run(self):      def run(self):
506          """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
507          that this allows both packages and modules to be in one          that this allows both packages and modules to be in one
# Line 506  class thuban_build_py(build_py): Line 553  class thuban_build_py(build_py):
553          return modules          return modules
554    
555    
556    thubaninit_contents_start = """
557    # This module was automatically generated by Thuban's install script
558    '''Import this module once per program (best place is probably the file
559    that ends up as your __main__ module) to be able to import Thuban
560    afterwards.
561    
562    Usage:
563    
564    import thubaninit
565    import Thuban
566    '''
567    import sys, os
568    """
569    
570    thubaninit_contents_thubaninitdir = """
571    sys.path.insert(0, %(thubandir)s)
572    """
573    thubaninit_contents_otherdirs = """
574    # Put the Lib dir into the path. The Lib dir contains some extra Python
575    # modules
576    import Thuban
577    thubandir = os.path.join(Thuban.__path__[0], '..')
578    dir = os.path.join(thubandir, "Lib")
579    if os.path.isdir(dir):
580        sys.path.insert(0, dir)
581    """
582    
583    def thubaninit_contents(thubandir):
584        """Return the contents of the the thubaninit file as a list of lines.
585    
586        The parameter thubandir is the parent directory where the Thuban/
587        package or the empty string if the thubaninit file itself will be
588        located in that direcory as well.
589        """
590        contents = thubaninit_contents_start
591        if thubandir:
592            thubandir = repr(thubandir)
593            contents += thubaninit_contents_thubaninitdir % locals()
594        contents += thubaninit_contents_otherdirs
595        return contents.split("\n")
596    
597    
598  class ThubanInstall(install):  class ThubanInstall(install):
599    
# Line 522  class ThubanInstall(install): Line 610  class ThubanInstall(install):
610                          "(default on posix systems and only relevant there)"),                          "(default on posix systems and only relevant there)"),
611    
612                           ("extra-files", None,                           ("extra-files", None,
613                            "List of filenames or (src, dest) pairs describing "                            "List of filenames or (src, dest) pairs describing"
614                            " extra files to install "                            " extra files to install "
615                            "(can only be set from witin setup.py"),                            "(can only be set from witin setup.py"),
616    
617                             ("create-init-module=", None,
618                              "If true, create a module in the site-packages"
619                              " directory that tweaks sys.path to let you easily"
620                              " import thuban modules from outside of thuban."),
621                             ("init-module-dir=", None,
622                              "Directory in which to create the init module."
623                              " Defaults to Python's site-packages directory."),
624                           ])                           ])
625    
626      boolean_options = install.boolean_options[:]      boolean_options = install.boolean_options[:]
627      boolean_options.append("do-symlink")      boolean_options.append("do-symlink")
628        boolean_options.append("create-init-module")
629    
630      def initialize_options(self):      def initialize_options(self):
631          self.do_symlink = None          self.do_symlink = None
632          self.extra_files = []          self.extra_files = []
633    
634            # initialize the create_init_module flag from the global
635            # determined at runtime
636            self.create_init_module = create_init_module
637            self.init_module_dir = None
638          install.initialize_options(self)          install.initialize_options(self)
639    
640      def finalize_options(self):      def finalize_options(self):
# Line 542  class ThubanInstall(install): Line 644  class ThubanInstall(install):
644              else:              else:
645                  self.do_symlink = 0                  self.do_symlink = 0
646          install.finalize_options(self)          install.finalize_options(self)
647            self.expand_with_pure_python_dirs(["init_module_dir"])
648    
649        def expand_with_pure_python_dirs(self, attrs):
650            """Expand the attributes with default values of base and platbase"""
651            # it seems that the values for "prefix" and "exec_prefix" in
652            # self.config_vars are the corresponding values used by the
653            # python interpreter, so we just assign these to "base" and
654            # "platbase".
655            config_vars = self.config_vars.copy()
656            config_vars["base"] = self.config_vars["prefix"]
657            config_vars["platbase"] = self.config_vars["exec_prefix"]
658            for attr in attrs:
659                val = getattr(self, attr)
660                if val is not None:
661                    if os.name == 'posix':
662                        val = os.path.expanduser(val)
663                    val = subst_vars(val, config_vars)
664                    setattr(self, attr, val)
665    
666        def select_scheme(self, scheme):
667            """Extend the inherited method to set init_module_dir"""
668            install.select_scheme(self, scheme)
669            # only set init_module_dir if it wasn't set by the user
670            if self.init_module_dir is None:
671                self.init_module_dir = INSTALL_SCHEMES[scheme]['purelib']
672    
673        def convert_paths(self, *args):
674            """Extend the inherited method so that we can remember some filename
675            """
676            # remember the installation directory before its root gets
677            # changed
678            self.install_lib_orig = self.install_lib
679            apply(install.convert_paths, (self,) + args)
680    
681      def run(self):      def run(self):
682          install.run(self)          install.run(self)
# Line 550  class ThubanInstall(install): Line 685  class ThubanInstall(install):
685                  src, dest = item                  src, dest = item
686              else:              else:
687                  src = dest = item                  src = dest = item
688              self.copy_file(convert_path(src),              self.copy_file(convert_path(src),
689                             os.path.join(self.root, convert_path(dest)))                             os.path.join(self.root, convert_path(dest)))
690    
691          if os.name == "posix" and self.do_symlink:          if os.name == "posix" and self.do_symlink:
# Line 565  class ThubanInstall(install): Line 700  class ThubanInstall(install):
700              self.mkpath(bindir)              self.mkpath(bindir)
701              self.link_file(scriptfile, binfile)              self.link_file(scriptfile, binfile)
702    
703            if self.create_init_module:
704                # create the init module
705                initfilename = self.thuban_init_filename()
706                if self.root:
707                    initfilename = change_root(self.root, initfilename)
708                contents = thubaninit_contents(self.install_lib_orig)
709                self.mkpath(os.path.dirname(initfilename))
710                self.execute(write_file, (initfilename, contents),
711                             "Create %s" % initfilename)
712    
713      def link_file(self, src, dest):      def link_file(self, src, dest):
714          """Create a symbolic link dest pointing to src.          """Create a symbolic link dest pointing to src.
715    
# Line 579  class ThubanInstall(install): Line 724  class ThubanInstall(install):
724          if not os.path.exists(dest):          if not os.path.exists(dest):
725              os.symlink(src, dest)              os.symlink(src, dest)
726    
727        def thuban_init_filename(self):
728            """Return the filename for the init-module"""
729            # Since we override the normal install dirs to point to our own
730            # prefix we have to reach into installed
731            return self.init_module_dir + "/thubaninit.py"
732    
733      def get_outputs (self):      def get_outputs (self):
734          outputs = install.get_outputs(self)          outputs = install.get_outputs(self)
# Line 594  class ThubanInstall(install): Line 744  class ThubanInstall(install):
744                  bindir = change_root(self.root, bindir)                  bindir = change_root(self.root, bindir)
745              binfile = os.path.join(bindir, "thuban")              binfile = os.path.join(bindir, "thuban")
746              outputs.append(binfile)              outputs.append(binfile)
747            if self.create_init_module:
748                initfilename = self.thuban_init_filename()
749                if self.root:
750                    initfilename = change_root(self.root, initfilename)
751                outputs.append(initfilename)
752          return outputs          return outputs
753    
754    
# Line 607  cp extensions/pyshapelib/{COPYING,COPYIN Line 762  cp extensions/pyshapelib/{COPYING,COPYIN
762  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}
763  '''  '''
764    
765    bdist_rpm_build_script = '''
766    env PATH="$PATH:%(prefix)s/lib/wxPython/bin:/usr/lib/wxPython/bin" CFLAGS="$RPM_OPT_FLAGS" %(python)s setup.py build
767    '''
768    
769  bdist_rpm_install_script = '''  bdist_rpm_install_script = '''
770  %(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \  %(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \
771     --prefix=%(prefix)s     --prefix=%(prefix)s
772  '''  '''
773    
774        
775  class thuban_bdist_rpm(bdist_rpm):  class thuban_bdist_rpm(bdist_rpm):
776    
777      """Thuban specific RPM distribution command"""      """Thuban specific RPM distribution command"""
# Line 630  class thuban_bdist_rpm(bdist_rpm): Line 789  class thuban_bdist_rpm(bdist_rpm):
789          # scripts such as the python interpreter to use are only known          # scripts such as the python interpreter to use are only known
790          # then.          # then.
791          open("bdist_rpm_prep", "w").close()          open("bdist_rpm_prep", "w").close()
792            open("bdist_rpm_build", "w").close()
793          open("bdist_rpm_install", "w").close()          open("bdist_rpm_install", "w").close()
794          bdist_rpm.initialize_options(self)          bdist_rpm.initialize_options(self)
795    
# Line 637  class thuban_bdist_rpm(bdist_rpm): Line 797  class thuban_bdist_rpm(bdist_rpm):
797          # create the scripts for the spec-file. Now we know the python          # create the scripts for the spec-file. Now we know the python
798          # interpreter to use.          # interpreter to use.
799          open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)          open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)
800    
801            build = bdist_rpm_build_script % {"python": self.python,
802                                              "prefix": self.prefix}
803            open("bdist_rpm_build", "w").write(build)
804    
805          install = bdist_rpm_install_script % {"python": self.python,          install = bdist_rpm_install_script % {"python": self.python,
806                                                "prefix": self.prefix}                                                "prefix": self.prefix}
807          open("bdist_rpm_install", "w").write(install)          open("bdist_rpm_install", "w").write(install)
# Line 724  class bdist_inno(Command): Line 889  class bdist_inno(Command):
889          """Execute the command. install_options if given, should be a          """Execute the command. install_options if given, should be a
890          directory of additional options to set in the install step"""          directory of additional options to set in the install step"""
891          # Obviously have to build before we can install          # Obviously have to build before we can install
892    
893          if not self.skip_build:          if not self.skip_build:
894              self.run_command('build')              self.run_command('build')
895    
# Line 746  class bdist_inno(Command): Line 912  class bdist_inno(Command):
912          self.execute(write_file, (iss_file, self.generate_iss()),          self.execute(write_file, (iss_file, self.generate_iss()),
913                       "Create Inno Setup script file %s" % iss_file)                       "Create Inno Setup script file %s" % iss_file)
914    
915          # and invoke          # and invoke
916          if self.run_inno:          if self.run_inno:
917              self.spawn(["iscc", iss_file])              self.spawn(["iscc", iss_file])
918    
# Line 812  class bdist_inno(Command): Line 978  class bdist_inno(Command):
978              line = 'Name: "{group}\\%s"; Filename: "%s";' \              line = 'Name: "{group}\\%s"; Filename: "%s";' \
979                     % (icon.title, icon.install_name)                     % (icon.title, icon.install_name)
980              iss.append(line)              iss.append(line)
981                
982          return iss          return iss
983    
984    
# Line 828  class InnoIconItem: Line 994  class InnoIconItem:
994          else:          else:
995              self.install_name = filename              self.install_name = filename
996    
997                
998  class thuban_bdist_inno(bdist_inno):  class thuban_bdist_inno(bdist_inno):
999    
1000      """Thuban specific Inno Setup stuff"""      """Thuban specific Inno Setup stuff"""
# Line 836  class thuban_bdist_inno(bdist_inno): Line 1002  class thuban_bdist_inno(bdist_inno):
1002      def run(self):      def run(self):
1003          install_options = {          install_options = {
1004              "prefix": ".",              "prefix": ".",
1005                "install_lib": "$base",
1006                "install_data": "$base",
1007              "install_scripts": "$base",              "install_scripts": "$base",
1008              "warn_dir": 0,              "warn_dir": 0,
1009              "extra_files": ["COPYING", "Lib/proj.dll"],              "extra_files": ["COPYING", "Lib/proj.dll"],
# Line 843  class thuban_bdist_inno(bdist_inno): Line 1011  class thuban_bdist_inno(bdist_inno):
1011          # don't make a symlink because we're simulating windows, so          # don't make a symlink because we're simulating windows, so
1012          # that we can generate the iss-file even on Linux          # that we can generate the iss-file even on Linux
1013          install_options["do_symlink"] = 0          install_options["do_symlink"] = 0
1014    
1015          bdist_inno.run(self, install_options)          bdist_inno.run(self, install_options)
1016        
1017                class thuban_build_docs(Command):
1018    
1019        """Command to generate documentation from source code."""
1020    
1021        description = "Generate documentation."
1022    
1023        user_options = []
1024    
1025        def initialize_options(self): pass
1026    
1027        def finalize_options(self): pass
1028    
1029        def run(self, install_options = None):
1030            self.spawn(["happydoc", "-d./Doc", "./Thuban"])
1031    
1032  #  #
1033  #   Run the script  #   Run the script
1034  #  #
# Line 856  Thuban is a viewer for geographic data w Line 1039  Thuban is a viewer for geographic data w
1039  """  """
1040    
1041  setup(name = "Thuban",  setup(name = "Thuban",
1042        version = "0.1.2",        version = "0.2.0",
1043        description = "Geographic data viewer",        description = "Geographic data viewer",
1044        long_description = long_description,        long_description = long_description,
1045        licence = "GPL",        licence = "GPL",
1046        author = "Intevation GmbH",        author = "Intevation GmbH",
1047        author_email = "[email protected]",        author_email = "[email protected]",
1048        url = "ftp:intevation.de/",        url = "http://thuban.intevation.de/",
1049    
1050        scripts = ["thuban.py"],        scripts = ["thuban.py"],
1051        packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"],        packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"],
# Line 898  setup(name = "Thuban", Line 1081  setup(name = "Thuban",
1081                    "install": ThubanInstall,                    "install": ThubanInstall,
1082                    "bdist_rpm": thuban_bdist_rpm,                    "bdist_rpm": thuban_bdist_rpm,
1083                    "bdist_inno": thuban_bdist_inno,                    "bdist_inno": thuban_bdist_inno,
1084                    "data_dist": data_dist                    "data_dist": data_dist,
1085                      "build_docs": thuban_build_docs
1086                    })                    })
1087    
1088    

Legend:
Removed from v.203  
changed lines
  Added in v.928

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26