[Python-checkins] CVS: distutils/distutils sysconfig.py,1.26,1.27

Greg Ward python-dev@python.org
Thu, 14 Sep 2000 18:15:11 -0700


Update of /cvsroot/python/distutils/distutils
In directory slayer.i.sourceforge.net:/tmp/cvs-serv26849

Modified Files:
	sysconfig.py 
Log Message:
Changed from eager parsing of Makefile (at import time) to lazy: only do
all that work when someone asks for a "configuration variable" from the
Makefile.  Details:
  - added 'get_config_vars()': responsible for calling one of the
    '_init_*()' functions to figure things out for this platform,
    and to provide an interface to the resulting dictionary
  - added 'get_config_var()' as a simple interface to the dictionary
    loaded by 'get_config_vars()'
  - changed the '_init_*()' functions so they load the global dictionary
    '_config_vars', rather than spewing their findings all over
    the module namespace
  - don't delete the '_init_*()' functions when done importing
  - adjusted 'customize_compiler()' to the new regime


Index: sysconfig.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/sysconfig.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -r1.26 -r1.27
*** sysconfig.py	2000/09/15 00:03:13	1.26
--- sysconfig.py	2000/09/15 01:15:08	1.27
***************
*** 16,20 ****
  from errors import DistutilsPlatformError
  
! 
  PREFIX = os.path.normpath(sys.prefix)
  EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
--- 16,20 ----
  from errors import DistutilsPlatformError
  
! # These are needed in a couple of spots, so just compute them once.
  PREFIX = os.path.normpath(sys.prefix)
  EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
***************
*** 104,116 ****
      """
      if compiler.compiler_type == "unix":
!         cc_cmd = CC + ' ' + OPT
          compiler.set_executables(
!             preprocessor=CC + " -E",    # not always!
              compiler=cc_cmd,
!             compiler_so=cc_cmd + ' ' + CCSHARED,
!             linker_so=LDSHARED,
!             linker_exe=CC)
  
!         compiler.shared_lib_extension = SO
  
  
--- 104,119 ----
      """
      if compiler.compiler_type == "unix":
!         (cc, opt, ccshared, ldshared, so_ext) = \
!             get_config_vars('CC', 'OPT', 'CCSHARED', 'LDSHARED', 'SO')
! 
!         cc_cmd = cc + ' ' + opt
          compiler.set_executables(
!             preprocessor=cc + " -E",    # not always!
              compiler=cc_cmd,
!             compiler_so=cc_cmd + ' ' + ccshared,
!             linker_so=ldshared,
!             linker_exe=cc)
  
!         compiler.shared_lib_extension = so_ext
  
  
***************
*** 231,237 ****
  
  
  def _init_posix():
      """Initialize the module as appropriate for POSIX systems."""
!     g = globals()
      # load the installed Makefile:
      try:
--- 234,242 ----
  
  
+ _config_vars = None
+ 
  def _init_posix():
      """Initialize the module as appropriate for POSIX systems."""
!     g = {}
      # load the installed Makefile:
      try:
***************
*** 258,262 ****
          g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
  
!     if sys.platform == 'beos':
  
          # Linker script is in the config directory.  In the Makefile it is
--- 263,267 ----
          g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
  
!     elif sys.platform == 'beos':
  
          # Linker script is in the config directory.  In the Makefile it is
***************
*** 273,282 ****
          # method.)
          g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
!                          (linkerscript, sys.prefix, sys.version[0:3]))
  
  
  def _init_nt():
      """Initialize the module as appropriate for NT"""
!     g = globals()
      # set basic install directories
      g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
--- 278,290 ----
          # method.)
          g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
!                          (linkerscript, PREFIX, sys.version[0:3]))
  
+     global _config_vars
+     _config_vars = g
  
+ 
  def _init_nt():
      """Initialize the module as appropriate for NT"""
!     g = {}
      # set basic install directories
      g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
***************
*** 288,297 ****
      g['SO'] = '.pyd'
      g['EXE'] = ".exe"
!     g['exec_prefix'] = EXEC_PREFIX
  
  
  def _init_mac():
      """Initialize the module as appropriate for Macintosh systems"""
!     g = globals()
      # set basic install directories
      g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
--- 296,307 ----
      g['SO'] = '.pyd'
      g['EXE'] = ".exe"
! 
!     global _config_vars
!     _config_vars = g
  
  
  def _init_mac():
      """Initialize the module as appropriate for Macintosh systems"""
!     g = {}
      # set basic install directories
      g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
***************
*** 302,307 ****
  
      g['SO'] = '.ppc.slb'
-     g['exec_prefix'] = EXEC_PREFIX
-     print sys.prefix, PREFIX
  
      # XXX are these used anywhere?
--- 312,315 ----
***************
*** 309,323 ****
      g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
  
  
- try:
-     exec "_init_" + os.name
- except NameError:
-     # not needed for this platform
-     pass
- else:
-     exec "_init_%s()" % os.name
  
  
! del _init_posix
! del _init_nt
! del _init_mac
--- 317,361 ----
      g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
  
+     global _config_vars
+     _config_vars = g
  
  
+ def get_config_vars(*args):
+     """With no arguments, return a dictionary of all configuration
+     variables relevant for the current platform.  Generally this includes
+     everything needed to build extensions and install both pure modules and
+     extensions.  On Unix, this means every variable defined in Python's
+     installed Makefile; on Windows and Mac OS it's a much smaller set.
  
!     With arguments, return a list of values that result from looking up
!     each argument in the configuration variable dictionary.
!     """
!     global _config_vars
!     if _config_vars is None:
!         from pprint import pprint
!         func = globals().get("_init_" + os.name)
!         if func:
!             func()
!         else:
!             _config_vars = {}
! 
!         # Normalized versions of prefix and exec_prefix are handy to have;
!         # in fact, these are the standard versions used most places in the
!         # Distutils.
!         _config_vars['prefix'] = PREFIX
!         _config_vars['exec_prefix'] = EXEC_PREFIX
! 
!     if args:
!         vals = []
!         for name in args:
!             vals.append(_config_vars.get(name))
!         return vals
!     else:
!         return _config_vars
! 
! def get_config_var(name):
!     """Return the value of a single variable using the dictionary
!     returned by 'get_config_vars()'.  Equivalent to
!       get_config_vars().get(name)
!     """
!     return get_config_vars().get(name)