/[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 90 by bh, Thu Apr 4 14:55:02 2002 UTC revision 452 by bh, Tue Mar 4 11:31:04 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 18  __version__ = "$Revision$" Line 18  __version__ = "$Revision$"
18  import os  import os
19  from types import TupleType  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, INSTALL_SCHEMES, subst_vars
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  from distutils.command.bdist_rpm import bdist_rpm
24  from distutils.file_util import write_file  from distutils.file_util import write_file
# Line 43  if os.name == "posix": Line 43  if os.name == "posix":
43      proj4_lib = "proj"      proj4_lib = "proj"
44    
45    
46      # You shpuldn't have to modify anything below here      # You shouldn't have to modify anything below here
47      ###################################################################      ###################################################################
48            
49      # The installation prefix (similar to autoconf's --prefix). This is      # The installation prefix (similar to autoconf's --prefix). This is
50      # only the default value, you can override it on the command line      # only the default value, you can override it on the command line
51      # with the install command's --prefix option      # with the install command's --prefix option.
52        #
53        # Note that there's a separate prefix option for the bdist_rpm
54        # command completely independend of this one.
55      prefix = "/usr/local/"      prefix = "/usr/local/"
56    
57        # Whether to create the thubaninit module. You can override this
58        # value on the commandline with the --create-init-module to the
59        # install command.
60        create_init_module = 1
61    
62      # On POSIX-systems we run wxgtk-config to determine the C++-compiler      # On POSIX-systems we run wxgtk-config to determine the C++-compiler
63      # flags      # flags
64      wx_config_script = "wx-config"      wx_config_script = "wx-config"
# Line 86  elif os.name == "nt": Line 94  elif os.name == "nt":
94      # the command line with the install command's --prefix option      # the command line with the install command's --prefix option
95      prefix = r"install"      prefix = r"install"
96    
97        # Whether to create the thubaninit module. You can override this
98        # value on the commandline with the --create-init-module to the
99        # install command. By default we don't create it under NT because we
100        # most often run install only as part of bdist_inno where we can't
101        # really create because it needs information only known at install
102        # time.
103        create_init_module = 0
104    
105      # 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
106      # flags, so we define them here. These flags work for us with      # flags, so we define them here. These flags work for us with
107      # 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 200  py_modules = [] Line 216  py_modules = []
216  #  #
217    
218  extensions.append(Extension("Lib.wxproj",  extensions.append(Extension("Lib.wxproj",
219                              [ext_dir + "/thuban/wxproj.cpp",                              [ext_dir + "/thuban/wxproj.cpp"],
220                               shp_dir + "/shpopen.c"],                              include_dirs = ([shp_dir, proj4_incdir,
221                              include_dirs = [shp_dir, proj4_incdir] +wx_incdirs,                                               ext_dir + "/pyshapelib/"]
222                                                + wx_incdirs),
223                              define_macros = wx_defs,                              define_macros = wx_defs,
224                              library_dirs = [proj4_libdir] + wx_libdirs,                              library_dirs = [proj4_libdir] + wx_libdirs,
225                              libraries = [proj4_lib] + wx_libs))                              libraries = [proj4_lib] + wx_libs))
# Line 213  extensions.append(Extension("Lib.wxproj" Line 230  extensions.append(Extension("Lib.wxproj"
230    
231  extensions.append(Extension("Lib.shapelibc",  extensions.append(Extension("Lib.shapelibc",
232                              [ext_dir + "/pyshapelib/shapelib_wrap.c",                              [ext_dir + "/pyshapelib/shapelib_wrap.c",
233                               shp_dir + "/shpopen.c"],                               shp_dir + "/shpopen.c",
234                                 shp_dir + "/shptree.c"],
235                                include_dirs = [shp_dir]))
236    extensions.append(Extension("Lib.shptree",
237                                [ext_dir + "/pyshapelib/shptreemodule.c"],
238                              include_dirs = [shp_dir]))                              include_dirs = [shp_dir]))
239  extensions.append(Extension("Lib.dbflibc",  extensions.append(Extension("Lib.dbflibc",
240                              [ext_dir + "/pyshapelib/dbflib_wrap.c",                              [ext_dir + "/pyshapelib/dbflib_wrap.c",
# Line 396  class InstallLocal(Command): Line 417  class InstallLocal(Command):
417    
418      user_options = [      user_options = [
419          ('skip-build', None, "skip the build steps"),          ('skip-build', None, "skip the build steps"),
420            ('create-init-module', None,
421             "Create the thubaninit.py module to ease use of Thuban as a library"),
422            ('dont-create-init-module', None,
423             "Do not create the thubaninit.py module"),
424          ]          ]
425    
426        boolean_options = ["create-init-module"]
427        negative_opt = {'dont-create-init-module' : 'create-init-module'}
428    
429    
430      def initialize_options (self):      def initialize_options (self):
431          self.extensions = None          self.extensions = None
432          self.build_dir = None          self.build_dir = None
433          self.skip_build = None          self.skip_build = None
434            self.create_init_module = None
435    
436      def finalize_options (self):      def finalize_options (self):
437          self.set_undefined_options("install",          self.set_undefined_options("install",
438                                     ("build_lib", "build_dir"),                                     ("build_lib", "build_dir"),
439                                     ('skip_build', 'skip_build'))                                     ('skip_build', 'skip_build'))
440          self.extensions = self.distribution.ext_modules          self.extensions = self.distribution.ext_modules
441            if self.create_init_module is None:
442                # by default we create the init module
443                self.create_init_module = 1
444    
445      def run(self):      def run(self):
446          # Make sure we have built everything we need first          # Make sure we have built everything we need first
# Line 421  class InstallLocal(Command): Line 454  class InstallLocal(Command):
454          else:          else:
455              self.copy_tree(libdir, "Lib")              self.copy_tree(libdir, "Lib")
456    
457            # create the init module if desired
458            if self.create_init_module:
459                # create the init module
460                initfilename = "thubaninit.py"
461                contents = thubaninit_contents("")
462                self.execute(write_file, (initfilename, contents),
463                             "Create %s" % initfilename)
464    
465      def link_dir(self, src, dest):      def link_dir(self, src, dest):
466          """Create a symbolic link dest pointing to src"""          """Create a symbolic link dest pointing to src"""
467          if self.verbose:          if self.verbose:
# Line 447  class thuban_build_py(build_py): Line 488  class thuban_build_py(build_py):
488      distribution.      distribution.
489      """      """
490    
491        # FIXME: When Thuban can rely on Python 2.3 as the oldest supported
492        # Python release we don't need to override the run and
493        # find_all_modules methods anymore. distutils will allow both python
494        # modules and packages starting with 2.3.
495    
496      def run(self):      def run(self):
497          """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
498          that this allows both packages and modules to be in one          that this allows both packages and modules to be in one
# Line 498  class thuban_build_py(build_py): Line 544  class thuban_build_py(build_py):
544          return modules          return modules
545    
546    
547    thubaninit_contents_start = """
548    # This module was automatically generated by Thuban's install script
549    '''Import this module once per program (best place is probably the file
550    that ends up as your __main__ module) to be able to import Thuban
551    afterwards.
552    
553    Usage:
554    
555    import thubaninit
556    import Thuban
557    '''
558    import sys, os
559    """
560    
561    thubaninit_contents_thubaninitdir = """
562    sys.path.insert(0, %(thubandir)s)
563    """
564    thubaninit_contents_otherdirs = """
565    # Put the Lib dir into the path. The Lib dir contains some extra Python
566    # modules
567    import Thuban
568    thubandir = os.path.join(Thuban.__path__[0], '..')
569    dir = os.path.join(thubandir, "Lib")
570    if os.path.isdir(dir):
571        sys.path.insert(0, dir)
572    """
573    
574    def thubaninit_contents(thubandir):
575        """Return the contents of the the thubaninit file as a list of lines.
576    
577        The parameter thubandir is the parent directory where the Thuban/
578        package or the empty string if the thubaninit file itself will be
579        located in that direcory as well.
580        """
581        contents = thubaninit_contents_start
582        if thubandir:
583            thubandir = repr(thubandir)
584            contents += thubaninit_contents_thubaninitdir % locals()
585        contents += thubaninit_contents_otherdirs
586        return contents.split("\n")
587    
588    
589  class ThubanInstall(install):  class ThubanInstall(install):
590    
# Line 514  class ThubanInstall(install): Line 601  class ThubanInstall(install):
601                          "(default on posix systems and only relevant there)"),                          "(default on posix systems and only relevant there)"),
602    
603                           ("extra-files", None,                           ("extra-files", None,
604                            "List of filenames or (src, dest) pairs describing "                            "List of filenames or (src, dest) pairs describing"
605                            " extra files to install "                            " extra files to install "
606                            "(can only be set from witin setup.py"),                            "(can only be set from witin setup.py"),
607    
608                             ("create-init-module=", None,
609                              "If true, create a module in the site-packages"
610                              " directory that tweaks sys.path to let you easily"
611                              " import thuban modules from outside of thuban."),
612                             ("init-module-dir=", None,
613                              "Directory in which to create the init module."
614                              " Defaults to Python's site-packages directory."),
615                           ])                           ])
616    
617      boolean_options = install.boolean_options[:]      boolean_options = install.boolean_options[:]
618      boolean_options.append("do-symlink")      boolean_options.append("do-symlink")
619        boolean_options.append("create-init-module")
620    
621      def initialize_options(self):      def initialize_options(self):
622          self.do_symlink = None          self.do_symlink = None
623          self.extra_files = []          self.extra_files = []
624    
625            # initialize the create_init_module flag from the global
626            # determined at runtime
627            self.create_init_module = create_init_module
628            self.init_module_dir = None
629          install.initialize_options(self)          install.initialize_options(self)
630    
631      def finalize_options(self):      def finalize_options(self):
# Line 534  class ThubanInstall(install): Line 635  class ThubanInstall(install):
635              else:              else:
636                  self.do_symlink = 0                  self.do_symlink = 0
637          install.finalize_options(self)          install.finalize_options(self)
638            self.expand_with_pure_python_dirs(["init_module_dir"])
639    
640        def expand_with_pure_python_dirs(self, attrs):
641            """Expand the attributes with default values of base and platbase"""
642            # it seems that the values for "prefix" and "exec_prefix" in
643            # self.config_vars are the corresponding values used by the
644            # python interpreter, so we just assign these to "base" and
645            # "platbase".
646            config_vars = self.config_vars.copy()
647            config_vars["base"] = self.config_vars["prefix"]
648            config_vars["platbase"] = self.config_vars["exec_prefix"]
649            for attr in attrs:
650                val = getattr(self, attr)
651                if val is not None:
652                    if os.name == 'posix':
653                        val = os.path.expanduser(val)
654                    val = subst_vars(val, config_vars)
655                    setattr(self, attr, val)
656    
657        def select_scheme(self, scheme):
658            """Extend the inherited method to set init_module_dir"""
659            install.select_scheme(self, scheme)
660            # only set init_module_dir if it wasn't set by the user
661            if self.init_module_dir is None:
662                self.init_module_dir = INSTALL_SCHEMES[scheme]['purelib']
663    
664        def convert_paths(self, *args):
665            """Extend the inherited method so that we can remember some filename
666            """
667            # remember the installation directory before its root gets
668            # changed
669            self.install_lib_orig = self.install_lib
670            apply(install.convert_paths, (self,) + args)
671    
672      def run(self):      def run(self):
673          install.run(self)          install.run(self)
# Line 542  class ThubanInstall(install): Line 676  class ThubanInstall(install):
676                  src, dest = item                  src, dest = item
677              else:              else:
678                  src = dest = item                  src = dest = item
679              self.copy_file(convert_path(src),              self.copy_file(convert_path(src),
680                             os.path.join(self.root, convert_path(dest)))                             os.path.join(self.root, convert_path(dest)))
681    
682          if os.name == "posix" and self.do_symlink:          if os.name == "posix" and self.do_symlink:
# Line 557  class ThubanInstall(install): Line 691  class ThubanInstall(install):
691              self.mkpath(bindir)              self.mkpath(bindir)
692              self.link_file(scriptfile, binfile)              self.link_file(scriptfile, binfile)
693    
694            if self.create_init_module:
695                # create the init module
696                initfilename = self.thuban_init_filename()
697                if self.root:
698                    initfilename = change_root(self.root, initfilename)
699                contents = thubaninit_contents(self.install_lib_orig)
700                self.mkpath(os.path.dirname(initfilename))
701                self.execute(write_file, (initfilename, contents),
702                             "Create %s" % initfilename)
703    
704      def link_file(self, src, dest):      def link_file(self, src, dest):
705          """Create a symbolic link dest pointing to src.          """Create a symbolic link dest pointing to src.
706    
# Line 571  class ThubanInstall(install): Line 715  class ThubanInstall(install):
715          if not os.path.exists(dest):          if not os.path.exists(dest):
716              os.symlink(src, dest)              os.symlink(src, dest)
717    
718        def thuban_init_filename(self):
719            """Return the filename for the init-module"""
720            # Since we override the normal install dirs to point to our own
721            # prefix we have to reach into installed
722            return self.init_module_dir + "/thubaninit.py"
723    
724      def get_outputs (self):      def get_outputs (self):
725          outputs = install.get_outputs(self)          outputs = install.get_outputs(self)
# Line 586  class ThubanInstall(install): Line 735  class ThubanInstall(install):
735                  bindir = change_root(self.root, bindir)                  bindir = change_root(self.root, bindir)
736              binfile = os.path.join(bindir, "thuban")              binfile = os.path.join(bindir, "thuban")
737              outputs.append(binfile)              outputs.append(binfile)
738            if self.create_init_module:
739                initfilename = self.thuban_init_filename()
740                if self.root:
741                    initfilename = change_root(self.root, initfilename)
742                outputs.append(initfilename)
743          return outputs          return outputs
744    
745    
746    # scripts to override some of the commands put into the spec-file by the
747    # bdist_rpm command.
748    
749  bdist_rpm_prep_script = '''  bdist_rpm_prep_script = '''
750  %setup  %setup
751  cp extensions/pyshapelib/{README,README.pyshapelib}  cp extensions/pyshapelib/{README,README.pyshapelib}
# Line 596  cp extensions/pyshapelib/{COPYING,COPYIN Line 753  cp extensions/pyshapelib/{COPYING,COPYIN
753  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}
754  '''  '''
755    
756    bdist_rpm_install_script = '''
757    %(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \
758       --prefix=%(prefix)s
759    '''
760    
761    
       
762  class thuban_bdist_rpm(bdist_rpm):  class thuban_bdist_rpm(bdist_rpm):
763    
764      """Thuban specific RPM distribution command"""      """Thuban specific RPM distribution command"""
765    
766        user_options = bdist_rpm.user_options[:]
767        user_options.extend([("prefix=", None, "Install prefix for the RPM"),
768                             ])
769    
770      def initialize_options(self):      def initialize_options(self):
771          # create the prep script for the spec-file          # per default, RPMs are installed in /usr
772          open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)          self.prefix = "/usr/"
773    
774            # create the scripts we want to override. We actually fill them
775            # with contents later because some values we put into those
776            # scripts such as the python interpreter to use are only known
777            # then.
778            open("bdist_rpm_prep", "w").close()
779            open("bdist_rpm_install", "w").close()
780          bdist_rpm.initialize_options(self)          bdist_rpm.initialize_options(self)
781    
782        def _make_spec_file(self):
783            # create the scripts for the spec-file. Now we know the python
784            # interpreter to use.
785            open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)
786            install = bdist_rpm_install_script % {"python": self.python,
787                                                  "prefix": self.prefix}
788            open("bdist_rpm_install", "w").write(install)
789    
790            #
791            return bdist_rpm._make_spec_file(self)
792    
793    
794  class bdist_inno(Command):  class bdist_inno(Command):
795    
# Line 710  class bdist_inno(Command): Line 892  class bdist_inno(Command):
892          self.execute(write_file, (iss_file, self.generate_iss()),          self.execute(write_file, (iss_file, self.generate_iss()),
893                       "Create Inno Setup script file %s" % iss_file)                       "Create Inno Setup script file %s" % iss_file)
894    
895          # and invoke          # and invoke
896          if self.run_inno:          if self.run_inno:
897              self.spawn(["iscc", iss_file])              self.spawn(["iscc", iss_file])
898    
# Line 776  class bdist_inno(Command): Line 958  class bdist_inno(Command):
958              line = 'Name: "{group}\\%s"; Filename: "%s";' \              line = 'Name: "{group}\\%s"; Filename: "%s";' \
959                     % (icon.title, icon.install_name)                     % (icon.title, icon.install_name)
960              iss.append(line)              iss.append(line)
961                
962          return iss          return iss
963    
964    
# Line 792  class InnoIconItem: Line 974  class InnoIconItem:
974          else:          else:
975              self.install_name = filename              self.install_name = filename
976    
977                
978  class thuban_bdist_inno(bdist_inno):  class thuban_bdist_inno(bdist_inno):
979    
980      """Thuban specific Inno Setup stuff"""      """Thuban specific Inno Setup stuff"""
# Line 808  class thuban_bdist_inno(bdist_inno): Line 990  class thuban_bdist_inno(bdist_inno):
990          # that we can generate the iss-file even on Linux          # that we can generate the iss-file even on Linux
991          install_options["do_symlink"] = 0          install_options["do_symlink"] = 0
992          bdist_inno.run(self, install_options)          bdist_inno.run(self, install_options)
993        
994                
995  #  #
996  #   Run the script  #   Run the script
997  #  #
# Line 820  Thuban is a viewer for geographic data w Line 1002  Thuban is a viewer for geographic data w
1002  """  """
1003    
1004  setup(name = "Thuban",  setup(name = "Thuban",
1005        version = "0.1.1",        version = "0.1.3",
1006        description = "Geographic data viewer",        description = "Geographic data viewer",
1007        long_description = long_description,        long_description = long_description,
1008        licence = "GPL",        licence = "GPL",
1009        author = "Intevation GmbH",        author = "Intevation GmbH",
1010        author_email = "[email protected]",        author_email = "[email protected]",
1011        url = "ftp:intevation.de/",        url = "http://thuban.intevation.de/",
1012    
1013        scripts = ["thuban.py"],        scripts = ["thuban.py"],
1014        packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"],        packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"],
# Line 840  setup(name = "Thuban", Line 1022  setup(name = "Thuban",
1022                   {"prefix": prefix,                   {"prefix": prefix,
1023                    # make sure both libs and scripts are installed in the                    # make sure both libs and scripts are installed in the
1024                    # same directory.                    # same directory.
1025                    "install_lib": "$base/thuban",                    "install_lib": "$base/lib/thuban",
1026                    "install_scripts": "$base/thuban",                    "install_scripts": "$base/lib/thuban",
1027                    "install_data": "$base/thuban",                    "install_data": "$base/lib/thuban",
1028    
1029                    # Don't print warning messages about the lib dir not                    # Don't print warning messages about the lib dir not
1030                    # being on Python's path. The libraries are Thuban                    # being on Python's path. The libraries are Thuban

Legend:
Removed from v.90  
changed lines
  Added in v.452

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26