/[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 67 by bh, Thu Oct 18 14:50:21 2001 UTC revision 204 by bh, Tue Jul 9 14:02:27 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 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 48  if os.name == "posix": Line 48  if os.name == "posix":
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      # On POSIX-systems we run wxgtk-config to determine the C++-compiler      # On POSIX-systems we run wxgtk-config to determine the C++-compiler
# Line 200  py_modules = [] Line 203  py_modules = []
203  #  #
204    
205  extensions.append(Extension("Lib.wxproj",  extensions.append(Extension("Lib.wxproj",
206                              [ext_dir + "/thuban/wxproj.cpp",                              [ext_dir + "/thuban/wxproj.cpp"],
207                               shp_dir + "/shpopen.c"],                              include_dirs = ([shp_dir, proj4_incdir,
208                              include_dirs = [shp_dir, proj4_incdir] +wx_incdirs,                                               ext_dir + "/pyshapelib/"]
209                                                + wx_incdirs),
210                              define_macros = wx_defs,                              define_macros = wx_defs,
211                              library_dirs = [proj4_libdir] + wx_libdirs,                              library_dirs = [proj4_libdir] + wx_libdirs,
212                              libraries = [proj4_lib] + wx_libs))                              libraries = [proj4_lib] + wx_libs))
# Line 213  extensions.append(Extension("Lib.wxproj" Line 217  extensions.append(Extension("Lib.wxproj"
217    
218  extensions.append(Extension("Lib.shapelibc",  extensions.append(Extension("Lib.shapelibc",
219                              [ext_dir + "/pyshapelib/shapelib_wrap.c",                              [ext_dir + "/pyshapelib/shapelib_wrap.c",
220                               shp_dir + "/shpopen.c"],                               shp_dir + "/shpopen.c",
221                                 shp_dir + "/shptree.c"],
222                                include_dirs = [shp_dir]))
223    extensions.append(Extension("Lib.shptree",
224                                [ext_dir + "/pyshapelib/shptreemodule.c"],
225                              include_dirs = [shp_dir]))                              include_dirs = [shp_dir]))
226  extensions.append(Extension("Lib.dbflibc",  extensions.append(Extension("Lib.dbflibc",
227                              [ext_dir + "/pyshapelib/dbflib_wrap.c",                              [ext_dir + "/pyshapelib/dbflib_wrap.c",
# Line 392  class InstallLocal(Command): Line 400  class InstallLocal(Command):
400      """      """
401    
402      description =\      description =\
403          "Create some symlink so you can run thubanfrom the source directory"          "Create some symlinks so you can run thuban from the source directory"
404    
405      user_options = [      user_options = [
406          ('skip-build', None, "skip the build steps"),          ('skip-build', None, "skip the build steps"),
# Line 416  class InstallLocal(Command): Line 424  class InstallLocal(Command):
424          # now do the work. Simply link or copy the Lib dir          # now do the work. Simply link or copy the Lib dir
425          libdir = os.path.join(self.build_dir, "Lib")          libdir = os.path.join(self.build_dir, "Lib")
426          if os.name == "posix":          if os.name == "posix":
427              # on posix, just lilnk the Lib dir              # on posix, just link the Lib dir
428              self.link_dir(libdir, "Lib")              self.link_dir(libdir, "Lib")
429          else:          else:
430              self.copy_tree(libdir, "Lib")              self.copy_tree(libdir, "Lib")
# Line 498  class thuban_build_py(build_py): Line 506  class thuban_build_py(build_py):
506          return modules          return modules
507    
508    
509    thubaninit_contents = """
510    # This module was automatically generated by Thuban's install script
511    '''Import this module once per program (best place is probably the file
512    that ends up as your __main__ module) to be able to import Thuban
513    afterwards.
514    
515    Usage:
516    
517    import thubaninit
518    import Thuban
519    '''
520    import sys, os
521    sys.path.insert(0, %(thubandir)s)
522    
523    # Put the Lib dir into the path. The Lib dir contains some extra Python
524    # modules
525    import Thuban
526    thubandir = os.path.join(Thuban.__path__[0], '..')
527    dir = os.path.join(thubandir, "Lib")
528    if os.path.isdir(dir):
529        sys.path.insert(0, dir)
530    """
531    
532    
533  class ThubanInstall(install):  class ThubanInstall(install):
534    
# Line 514  class ThubanInstall(install): Line 545  class ThubanInstall(install):
545                          "(default on posix systems and only relevant there)"),                          "(default on posix systems and only relevant there)"),
546    
547                           ("extra-files", None,                           ("extra-files", None,
548                            "List of filenames or (src, dest) pairs describing "                            "List of filenames or (src, dest) pairs describing"
549                            " extra files to install "                            " extra files to install "
550                            "(can only be set from witin setup.py"),                            "(can only be set from witin setup.py"),
551    
552                             ("create-init-module", None,
553                              "Create a module in the site-packages directory that"
554                              " tweaks sys.path to let you easily import thuban"
555                              " modules from outside of thuban."),
556                             ("init-module-dir", None,
557                              "Directory in which to create the init module."
558                              " Defaults to Python's site-packages directory."),
559                            
560                           ])                           ])
561    
562      boolean_options = install.boolean_options[:]      boolean_options = install.boolean_options[:]
563      boolean_options.append("do-symlink")      boolean_options.append("do-symlink")
564        boolean_options.append("create-init-module")
565    
566      def initialize_options(self):      def initialize_options(self):
567          self.do_symlink = None          self.do_symlink = None
568          self.extra_files = []          self.extra_files = []
569            self.create_init_module = 1
570            self.init_module_dir = None
571          install.initialize_options(self)          install.initialize_options(self)
572    
573      def finalize_options(self):      def finalize_options(self):
# Line 534  class ThubanInstall(install): Line 577  class ThubanInstall(install):
577              else:              else:
578                  self.do_symlink = 0                  self.do_symlink = 0
579          install.finalize_options(self)          install.finalize_options(self)
580            self.expand_with_pure_python_dirs(["init_module_dir"])
581    
582        def expand_with_pure_python_dirs(self, attrs):
583            """Expand the attributes with default values of base and platbase"""
584            # it seems that the values for "prefix" and "exec_prefix" in
585            # self.config_vars are the corresponding values used by the
586            # python interpreter, so we just assign these to "base" and
587            # "platbase".
588            config_vars = self.config_vars.copy()
589            config_vars["base"] = self.config_vars["prefix"]
590            config_vars["platbase"] = self.config_vars["exec_prefix"]
591            for attr in attrs:
592                val = getattr(self, attr)
593                if val is not None:
594                    if os.name == 'posix':
595                        val = os.path.expanduser(val)
596                    val = subst_vars(val, config_vars)
597                    setattr(self, attr, val)
598    
599        def select_scheme(self, scheme):
600            """Extend the inherited method to set init_module_dir"""
601            install.select_scheme(self, scheme)
602            # only set init_module_dir if it wasn't set by the user
603            if self.init_module_dir is None:
604                self.init_module_dir = INSTALL_SCHEMES[scheme]['purelib']
605    
606        def convert_paths(self, *args):
607            """Extend the inherited method so that we can remember some filename
608            """
609            # remember the installation directory before its root gets
610            # changed
611            self.install_lib_orig = self.install_lib
612            apply(install.convert_paths, (self,) + args)
613    
614      def run(self):      def run(self):
615          install.run(self)          install.run(self)
# Line 557  class ThubanInstall(install): Line 633  class ThubanInstall(install):
633              self.mkpath(bindir)              self.mkpath(bindir)
634              self.link_file(scriptfile, binfile)              self.link_file(scriptfile, binfile)
635    
636            if self.create_init_module:
637                # create the init module
638                initfilename = self.thuban_init_filename()
639                if self.root:
640                    initfilename = change_root(self.root, initfilename)
641                contents = thubaninit_contents % {
642                    "thubandir": repr(self.install_lib_orig)
643                    }
644                self.mkpath(os.path.dirname(initfilename))
645                self.execute(write_file, (initfilename, split(contents, "\n")),
646                             "Create %s" % initfilename)
647    
648      def link_file(self, src, dest):      def link_file(self, src, dest):
649          """Create a symbolic link dest pointing to src.          """Create a symbolic link dest pointing to src.
650    
# Line 571  class ThubanInstall(install): Line 659  class ThubanInstall(install):
659          if not os.path.exists(dest):          if not os.path.exists(dest):
660              os.symlink(src, dest)              os.symlink(src, dest)
661    
662        def thuban_init_filename(self):
663            """Return the filename for the init-module"""
664            # Since we override the normal install dirs to point to our own
665            # prefix we have to reach into installed
666            return self.init_module_dir + "/thubaninit.py"
667    
668      def get_outputs (self):      def get_outputs (self):
669          outputs = install.get_outputs(self)          outputs = install.get_outputs(self)
# Line 586  class ThubanInstall(install): Line 679  class ThubanInstall(install):
679                  bindir = change_root(self.root, bindir)                  bindir = change_root(self.root, bindir)
680              binfile = os.path.join(bindir, "thuban")              binfile = os.path.join(bindir, "thuban")
681              outputs.append(binfile)              outputs.append(binfile)
682            if self.create_init_module:
683                initfilename = self.thuban_init_filename()
684                if self.root:
685                    initfilename = change_root(self.root, initfilename)
686                outputs.append(initfilename)
687          return outputs          return outputs
688    
689    
690    # scripts to override some of the commands put into the spec-file by the
691    # bdist_rpm command.
692    
693  bdist_rpm_prep_script = '''  bdist_rpm_prep_script = '''
694  %setup  %setup
695  cp extensions/pyshapelib/{README,README.pyshapelib}  cp extensions/pyshapelib/{README,README.pyshapelib}
# Line 596  cp extensions/pyshapelib/{COPYING,COPYIN Line 697  cp extensions/pyshapelib/{COPYING,COPYIN
697  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}
698  '''  '''
699    
700    bdist_rpm_install_script = '''
701    %(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \
702       --prefix=%(prefix)s
703    '''
704    
705            
706  class thuban_bdist_rpm(bdist_rpm):  class thuban_bdist_rpm(bdist_rpm):
707    
708      """Thuban specific RPM distribution command"""      """Thuban specific RPM distribution command"""
709    
710      def run(self):      user_options = bdist_rpm.user_options[:]
711          # create the prep script for the spec-file      user_options.extend([("prefix=", None, "Install prefix for the RPM"),
712                             ])
713    
714        def initialize_options(self):
715            # per default, RPMs are installed in /usr
716            self.prefix = "/usr/"
717    
718            # create the scripts we want to override. We actually fill them
719            # with contents later because some values we put into those
720            # scripts such as the python interpreter to use are only known
721            # then.
722            open("bdist_rpm_prep", "w").close()
723            open("bdist_rpm_install", "w").close()
724            bdist_rpm.initialize_options(self)
725    
726        def _make_spec_file(self):
727            # create the scripts for the spec-file. Now we know the python
728            # interpreter to use.
729          open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)          open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)
730            install = bdist_rpm_install_script % {"python": self.python,
731                                                  "prefix": self.prefix}
732            open("bdist_rpm_install", "w").write(install)
733    
734          bdist_rpm.run(self)          #
735            return bdist_rpm._make_spec_file(self)
736    
737    
738  class bdist_inno(Command):  class bdist_inno(Command):
# Line 820  Thuban is a viewer for geographic data w Line 946  Thuban is a viewer for geographic data w
946  """  """
947    
948  setup(name = "Thuban",  setup(name = "Thuban",
949        version = "0.1",        version = "0.1.2",
950        description = "Geographic data viewer",        description = "Geographic data viewer",
951        long_description = long_description,        long_description = long_description,
952        licence = "GPL",        licence = "GPL",
# Line 840  setup(name = "Thuban", Line 966  setup(name = "Thuban",
966                   {"prefix": prefix,                   {"prefix": prefix,
967                    # make sure both libs and scripts are installed in the                    # make sure both libs and scripts are installed in the
968                    # same directory.                    # same directory.
969                    "install_lib": "$base/thuban",                    "install_lib": "$base/lib/thuban",
970                    "install_scripts": "$base/thuban",                    "install_scripts": "$base/lib/thuban",
971                    "install_data": "$base/thuban",                    "install_data": "$base/lib/thuban",
972    
973                    # Don't print warning messages about the lib dir not                    # Don't print warning messages about the lib dir not
974                    # being on Python's path. The libraries are Thuban                    # being on Python's path. The libraries are Thuban

Legend:
Removed from v.67  
changed lines
  Added in v.204

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26