home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / BUILD.PY < prev    next >
Encoding:
Python Source  |  2000-10-14  |  4.3 KB  |  131 lines

  1. """distutils.command.build
  2.  
  3. Implements the Distutils 'build' command."""
  4.  
  5. # created 1999/03/08, Greg Ward
  6.  
  7. __revision__ = "$Id: build.py,v 1.31 2000/10/14 04:06:40 gward Exp $"
  8.  
  9. import sys, os
  10. from distutils.core import Command
  11. from distutils.util import get_platform
  12.  
  13.  
  14. def show_compilers ():
  15.     from distutils.ccompiler import show_compilers
  16.     show_compilers()
  17.  
  18.  
  19. class build (Command):
  20.  
  21.     description = "build everything needed to install"
  22.  
  23.     user_options = [
  24.         ('build-base=', 'b',
  25.          "base directory for build library"),
  26.         ('build-purelib=', None,
  27.          "build directory for platform-neutral distributions"),
  28.         ('build-platlib=', None,
  29.          "build directory for platform-specific distributions"),
  30.         ('build-lib=', None,
  31.          "build directory for all distribution (defaults to either " +
  32.          "build-purelib or build-platlib"),
  33.         ('build-scripts=', None,
  34.          "build directory for scripts"),
  35.         ('build-temp=', 't',
  36.          "temporary build directory"),
  37.         ('compiler=', 'c',
  38.          "specify the compiler type"),
  39.         ('debug', 'g',
  40.          "compile extensions and libraries with debugging information"),
  41.         ('force', 'f',
  42.          "forcibly build everything (ignore file timestamps)"),
  43.         ]
  44.  
  45.     boolean_options = ['debug', 'force']
  46.  
  47.     help_options = [
  48.         ('help-compiler', None,
  49.          "list available compilers", show_compilers),
  50.         ]
  51.  
  52.     def initialize_options (self):
  53.         self.build_base = 'build'
  54.         # these are decided only after 'build_base' has its final value
  55.         # (unless overridden by the user or client)
  56.         self.build_purelib = None
  57.         self.build_platlib = None
  58.         self.build_lib = None
  59.         self.build_temp = None
  60.         self.build_scripts = None
  61.         self.compiler = None
  62.         self.debug = None
  63.         self.force = 0
  64.  
  65.     def finalize_options (self):
  66.  
  67.         plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
  68.  
  69.         # 'build_purelib' and 'build_platlib' just default to 'lib' and
  70.         # 'lib.<plat>' under the base build directory.  We only use one of
  71.         # them for a given distribution, though --
  72.         if self.build_purelib is None:
  73.             self.build_purelib = os.path.join(self.build_base, 'lib')
  74.         if self.build_platlib is None:
  75.             self.build_platlib = os.path.join(self.build_base,
  76.                                               'lib' + plat_specifier)
  77.  
  78.         # 'build_lib' is the actual directory that we will use for this
  79.         # particular module distribution -- if user didn't supply it, pick
  80.         # one of 'build_purelib' or 'build_platlib'.
  81.         if self.build_lib is None:
  82.             if self.distribution.ext_modules:
  83.                 self.build_lib = self.build_platlib
  84.             else:
  85.                 self.build_lib = self.build_purelib
  86.  
  87.         # 'build_temp' -- temporary directory for compiler turds,
  88.         # "build/temp.<plat>"
  89.         if self.build_temp is None:
  90.             self.build_temp = os.path.join(self.build_base,
  91.                                            'temp' + plat_specifier)
  92.         if self.build_scripts is None:
  93.             self.build_scripts = os.path.join(self.build_base, 'scripts')
  94.  
  95.     # finalize_options ()
  96.  
  97.  
  98.     def run (self):
  99.  
  100.         # Run all relevant sub-commands.  This will be some subset of:
  101.         #  - build_py      - pure Python modules
  102.         #  - build_clib    - standalone C libraries
  103.         #  - build_ext     - Python extensions
  104.         #  - build_scripts - (Python) scripts
  105.         for cmd_name in self.get_sub_commands():
  106.             self.run_command(cmd_name)
  107.  
  108.  
  109.     # -- Predicates for the sub-command list ---------------------------
  110.  
  111.     def has_pure_modules (self):
  112.         return self.distribution.has_pure_modules()
  113.  
  114.     def has_c_libraries (self):
  115.         return self.distribution.has_c_libraries()
  116.  
  117.     def has_ext_modules (self):
  118.         return self.distribution.has_ext_modules()
  119.  
  120.     def has_scripts (self):
  121.         return self.distribution.has_scripts()
  122.  
  123.  
  124.     sub_commands = [('build_py',      has_pure_modules),
  125.                     ('build_clib',    has_c_libraries),
  126.                     ('build_ext',     has_ext_modules),
  127.                     ('build_scripts', has_scripts),
  128.                    ]
  129.  
  130. # class build
  131.