/[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 160 by bh, Wed May 8 13:46:34 2002 UTC revision 253 by bh, Wed Aug 14 13:38:45 2002 UTC
# 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 224  extensions.append(Extension("Lib.dbflibc Line 240  extensions.append(Extension("Lib.dbflibc
240                              [ext_dir + "/pyshapelib/dbflib_wrap.c",                              [ext_dir + "/pyshapelib/dbflib_wrap.c",
241                               shp_dir + "/dbfopen.c"],                               shp_dir + "/dbfopen.c"],
242                              include_dirs = [shp_dir]))                              include_dirs = [shp_dir]))
243  for name in ("shapelib", "shptree", "dbflib"):  for name in ("shapelib", "dbflib"):
244      py_modules.append(ext_dir + "/pyshapelib/" + name)      py_modules.append(ext_dir + "/pyshapelib/" + name)
245    
246  #  #
# Line 401  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 426  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 503  class thuban_build_py(build_py): Line 539  class thuban_build_py(build_py):
539          return modules          return modules
540    
541    
542    thubaninit_contents_start = """
543    # This module was automatically generated by Thuban's install script
544    '''Import this module once per program (best place is probably the file
545    that ends up as your __main__ module) to be able to import Thuban
546    afterwards.
547    
548    Usage:
549    
550    import thubaninit
551    import Thuban
552    '''
553    import sys, os
554    """
555    
556    thubaninit_contents_thubaninitdir = """
557    sys.path.insert(0, %(thubandir)s)
558    """
559    thubaninit_contents_otherdirs = """
560    # Put the Lib dir into the path. The Lib dir contains some extra Python
561    # modules
562    import Thuban
563    thubandir = os.path.join(Thuban.__path__[0], '..')
564    dir = os.path.join(thubandir, "Lib")
565    if os.path.isdir(dir):
566        sys.path.insert(0, dir)
567    """
568    
569    def thubaninit_contents(thubandir):
570        """Return the contents of the the thubaninit file as a list of lines.
571    
572        The parameter thubandir is the parent directory where the Thuban/
573        package or the empty string if the thubaninit file itself will be
574        located in that direcory as well.
575        """
576        contents = thubaninit_contents_start
577        if thubandir:
578            thubandir = repr(thubandir)
579            contents += thubaninit_contents_thubaninitdir % locals()
580        contents += thubaninit_contents_otherdirs
581        return contents.split("\n")
582    
583    
584  class ThubanInstall(install):  class ThubanInstall(install):
585    
# Line 519  class ThubanInstall(install): Line 596  class ThubanInstall(install):
596                          "(default on posix systems and only relevant there)"),                          "(default on posix systems and only relevant there)"),
597    
598                           ("extra-files", None,                           ("extra-files", None,
599                            "List of filenames or (src, dest) pairs describing "                            "List of filenames or (src, dest) pairs describing"
600                            " extra files to install "                            " extra files to install "
601                            "(can only be set from witin setup.py"),                            "(can only be set from witin setup.py"),
602    
603                             ("create-init-module=", None,
604                              "If true, create a module in the site-packages"
605                              " directory that tweaks sys.path to let you easily"
606                              " import thuban modules from outside of thuban."),
607                             ("init-module-dir=", None,
608                              "Directory in which to create the init module."
609                              " Defaults to Python's site-packages directory."),
610                           ])                           ])
611    
612      boolean_options = install.boolean_options[:]      boolean_options = install.boolean_options[:]
613      boolean_options.append("do-symlink")      boolean_options.append("do-symlink")
614        boolean_options.append("create-init-module")
615    
616      def initialize_options(self):      def initialize_options(self):
617          self.do_symlink = None          self.do_symlink = None
618          self.extra_files = []          self.extra_files = []
619    
620            # initialize the create_init_module flag from the global
621            # determined at runtime
622            self.create_init_module = create_init_module
623            self.init_module_dir = None
624          install.initialize_options(self)          install.initialize_options(self)
625    
626      def finalize_options(self):      def finalize_options(self):
# Line 539  class ThubanInstall(install): Line 630  class ThubanInstall(install):
630              else:              else:
631                  self.do_symlink = 0                  self.do_symlink = 0
632          install.finalize_options(self)          install.finalize_options(self)
633            self.expand_with_pure_python_dirs(["init_module_dir"])
634    
635        def expand_with_pure_python_dirs(self, attrs):
636            """Expand the attributes with default values of base and platbase"""
637            # it seems that the values for "prefix" and "exec_prefix" in
638            # self.config_vars are the corresponding values used by the
639            # python interpreter, so we just assign these to "base" and
640            # "platbase".
641            config_vars = self.config_vars.copy()
642            config_vars["base"] = self.config_vars["prefix"]
643            config_vars["platbase"] = self.config_vars["exec_prefix"]
644            for attr in attrs:
645                val = getattr(self, attr)
646                if val is not None:
647                    if os.name == 'posix':
648                        val = os.path.expanduser(val)
649                    val = subst_vars(val, config_vars)
650                    setattr(self, attr, val)
651    
652        def select_scheme(self, scheme):
653            """Extend the inherited method to set init_module_dir"""
654            install.select_scheme(self, scheme)
655            # only set init_module_dir if it wasn't set by the user
656            if self.init_module_dir is None:
657                self.init_module_dir = INSTALL_SCHEMES[scheme]['purelib']
658    
659        def convert_paths(self, *args):
660            """Extend the inherited method so that we can remember some filename
661            """
662            # remember the installation directory before its root gets
663            # changed
664            self.install_lib_orig = self.install_lib
665            apply(install.convert_paths, (self,) + args)
666    
667      def run(self):      def run(self):
668          install.run(self)          install.run(self)
# Line 562  class ThubanInstall(install): Line 686  class ThubanInstall(install):
686              self.mkpath(bindir)              self.mkpath(bindir)
687              self.link_file(scriptfile, binfile)              self.link_file(scriptfile, binfile)
688    
689            if self.create_init_module:
690                # create the init module
691                initfilename = self.thuban_init_filename()
692                if self.root:
693                    initfilename = change_root(self.root, initfilename)
694                contents = thubaninit_contents(repr(self.install_lib_orig))
695                self.mkpath(os.path.dirname(initfilename))
696                self.execute(write_file, (initfilename, contents),
697                             "Create %s" % initfilename)
698    
699      def link_file(self, src, dest):      def link_file(self, src, dest):
700          """Create a symbolic link dest pointing to src.          """Create a symbolic link dest pointing to src.
701    
# Line 576  class ThubanInstall(install): Line 710  class ThubanInstall(install):
710          if not os.path.exists(dest):          if not os.path.exists(dest):
711              os.symlink(src, dest)              os.symlink(src, dest)
712    
713        def thuban_init_filename(self):
714            """Return the filename for the init-module"""
715            # Since we override the normal install dirs to point to our own
716            # prefix we have to reach into installed
717            return self.init_module_dir + "/thubaninit.py"
718    
719      def get_outputs (self):      def get_outputs (self):
720          outputs = install.get_outputs(self)          outputs = install.get_outputs(self)
# Line 591  class ThubanInstall(install): Line 730  class ThubanInstall(install):
730                  bindir = change_root(self.root, bindir)                  bindir = change_root(self.root, bindir)
731              binfile = os.path.join(bindir, "thuban")              binfile = os.path.join(bindir, "thuban")
732              outputs.append(binfile)              outputs.append(binfile)
733            if self.create_init_module:
734                initfilename = self.thuban_init_filename()
735                if self.root:
736                    initfilename = change_root(self.root, initfilename)
737                outputs.append(initfilename)
738          return outputs          return outputs
739    
740    
741    # scripts to override some of the commands put into the spec-file by the
742    # bdist_rpm command.
743    
744  bdist_rpm_prep_script = '''  bdist_rpm_prep_script = '''
745  %setup  %setup
746  cp extensions/pyshapelib/{README,README.pyshapelib}  cp extensions/pyshapelib/{README,README.pyshapelib}
# Line 601  cp extensions/pyshapelib/{COPYING,COPYIN Line 748  cp extensions/pyshapelib/{COPYING,COPYIN
748  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}  cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection}
749  '''  '''
750    
751    bdist_rpm_install_script = '''
752    %(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \
753       --prefix=%(prefix)s
754    '''
755    
756            
757  class thuban_bdist_rpm(bdist_rpm):  class thuban_bdist_rpm(bdist_rpm):
758    
759      """Thuban specific RPM distribution command"""      """Thuban specific RPM distribution command"""
760    
761        user_options = bdist_rpm.user_options[:]
762        user_options.extend([("prefix=", None, "Install prefix for the RPM"),
763                             ])
764    
765      def initialize_options(self):      def initialize_options(self):
766          # create the prep script for the spec-file          # per default, RPMs are installed in /usr
767          open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)          self.prefix = "/usr/"
768    
769            # create the scripts we want to override. We actually fill them
770            # with contents later because some values we put into those
771            # scripts such as the python interpreter to use are only known
772            # then.
773            open("bdist_rpm_prep", "w").close()
774            open("bdist_rpm_install", "w").close()
775          bdist_rpm.initialize_options(self)          bdist_rpm.initialize_options(self)
776    
777        def _make_spec_file(self):
778            # create the scripts for the spec-file. Now we know the python
779            # interpreter to use.
780            open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script)
781            install = bdist_rpm_install_script % {"python": self.python,
782                                                  "prefix": self.prefix}
783            open("bdist_rpm_install", "w").write(install)
784    
785            #
786            return bdist_rpm._make_spec_file(self)
787    
788    
789  class bdist_inno(Command):  class bdist_inno(Command):
790    
# Line 825  Thuban is a viewer for geographic data w Line 997  Thuban is a viewer for geographic data w
997  """  """
998    
999  setup(name = "Thuban",  setup(name = "Thuban",
1000        version = "0.1.2",        version = "0.1.3cvs",
1001        description = "Geographic data viewer",        description = "Geographic data viewer",
1002        long_description = long_description,        long_description = long_description,
1003        licence = "GPL",        licence = "GPL",
1004        author = "Intevation GmbH",        author = "Intevation GmbH",
1005        author_email = "[email protected]",        author_email = "[email protected]",
1006        url = "ftp:intevation.de/",        url = "http://thuban.intevation.de/",
1007    
1008        scripts = ["thuban.py"],        scripts = ["thuban.py"],
1009        packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"],        packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"],
# Line 845  setup(name = "Thuban", Line 1017  setup(name = "Thuban",
1017                   {"prefix": prefix,                   {"prefix": prefix,
1018                    # make sure both libs and scripts are installed in the                    # make sure both libs and scripts are installed in the
1019                    # same directory.                    # same directory.
1020                    "install_lib": "$base/thuban",                    "install_lib": "$base/lib/thuban",
1021                    "install_scripts": "$base/thuban",                    "install_scripts": "$base/lib/thuban",
1022                    "install_data": "$base/thuban",                    "install_data": "$base/lib/thuban",
1023    
1024                    # Don't print warning messages about the lib dir not                    # Don't print warning messages about the lib dir not
1025                    # being on Python's path. The libraries are Thuban                    # being on Python's path. The libraries are Thuban

Legend:
Removed from v.160  
changed lines
  Added in v.253

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26