home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / python2.5 / distutils / sysconfig.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-05-11  |  14.0 KB  |  476 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. """Provide access to Python's configuration information.  The specific
  5. configuration variables available depend heavily on the platform and
  6. configuration.  The values may be retrieved using
  7. get_config_var(name), and the list of variables is available via
  8. get_config_vars().keys().  Additional convenience functions are also
  9. available.
  10.  
  11. Written by:   Fred L. Drake, Jr.
  12. Email:        <fdrake@acm.org>
  13. """
  14. __revision__ = '$Id: sysconfig.py 52234 2006-10-08 17:50:26Z ronald.oussoren $'
  15. import os
  16. import re
  17. import string
  18. import sys
  19. from distutils.errors import DistutilsPlatformError
  20. PREFIX = os.path.normpath(sys.prefix)
  21. EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  22. argv0_path = os.path.dirname(os.path.abspath(sys.executable))
  23. landmark = os.path.join(argv0_path, 'Modules', 'Setup')
  24. python_build = os.path.isfile(landmark)
  25. del landmark
  26.  
  27. def get_python_version():
  28.     """Return a string containing the major and minor Python version,
  29.     leaving off the patchlevel.  Sample return values could be '1.5'
  30.     or '2.2'.
  31.     """
  32.     return sys.version[:3]
  33.  
  34.  
  35. def get_python_inc(plat_specific = 0, prefix = None):
  36.     """Return the directory containing installed Python header files.
  37.  
  38.     If 'plat_specific' is false (the default), this is the path to the
  39.     non-platform-specific header files, i.e. Python.h and so on;
  40.     otherwise, this is the path to platform-specific header files
  41.     (namely pyconfig.h).
  42.  
  43.     If 'prefix' is supplied, use it instead of sys.prefix or
  44.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  45.     """
  46.     if prefix is None:
  47.         if not plat_specific or EXEC_PREFIX:
  48.             pass
  49.         prefix = PREFIX
  50.     
  51.     if os.name == 'posix':
  52.         if python_build:
  53.             base = os.path.dirname(os.path.abspath(sys.executable))
  54.             if plat_specific:
  55.                 inc_dir = base
  56.             else:
  57.                 inc_dir = os.path.join(base, 'Include')
  58.                 if not os.path.exists(inc_dir):
  59.                     inc_dir = os.path.join(os.path.dirname(base), 'Include')
  60.                 
  61.             return inc_dir
  62.         
  63.         if not sys.pydebug or '_d':
  64.             pass
  65.         return os.path.join(prefix, 'include', 'python' + get_python_version() + '')
  66.     elif os.name == 'nt':
  67.         return os.path.join(prefix, 'include')
  68.     elif os.name == 'mac':
  69.         if plat_specific:
  70.             return os.path.join(prefix, 'Mac', 'Include')
  71.         else:
  72.             return os.path.join(prefix, 'Include')
  73.     elif os.name == 'os2':
  74.         return os.path.join(prefix, 'Include')
  75.     else:
  76.         raise DistutilsPlatformError("I don't know where Python installs its C header files on platform '%s'" % os.name)
  77.  
  78.  
  79. def get_python_lib(plat_specific = 0, standard_lib = 0, prefix = None):
  80.     """Return the directory containing the Python library (standard or
  81.     site additions).
  82.  
  83.     If 'plat_specific' is true, return the directory containing
  84.     platform-specific modules, i.e. any module from a non-pure-Python
  85.     module distribution; otherwise, return the platform-shared library
  86.     directory.  If 'standard_lib' is true, return the directory
  87.     containing standard Python library modules; otherwise, return the
  88.     directory for site-specific modules.
  89.  
  90.     If 'prefix' is supplied, use it instead of sys.prefix or
  91.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  92.     """
  93.     if prefix is None:
  94.         if not plat_specific or EXEC_PREFIX:
  95.             pass
  96.         prefix = PREFIX
  97.     
  98.     if os.name == 'posix':
  99.         libpython = os.path.join(prefix, 'lib', 'python' + get_python_version())
  100.         if standard_lib:
  101.             return libpython
  102.         else:
  103.             return os.path.join(libpython, 'site-packages')
  104.     elif os.name == 'nt':
  105.         if standard_lib:
  106.             return os.path.join(prefix, 'Lib')
  107.         elif get_python_version() < '2.2':
  108.             return prefix
  109.         else:
  110.             return os.path.join(PREFIX, 'Lib', 'site-packages')
  111.     elif os.name == 'mac':
  112.         if plat_specific:
  113.             if standard_lib:
  114.                 return os.path.join(prefix, 'Lib', 'lib-dynload')
  115.             else:
  116.                 return os.path.join(prefix, 'Lib', 'site-packages')
  117.         elif standard_lib:
  118.             return os.path.join(prefix, 'Lib')
  119.         else:
  120.             return os.path.join(prefix, 'Lib', 'site-packages')
  121.     elif os.name == 'os2':
  122.         if standard_lib:
  123.             return os.path.join(PREFIX, 'Lib')
  124.         else:
  125.             return os.path.join(PREFIX, 'Lib', 'site-packages')
  126.     else:
  127.         raise DistutilsPlatformError("I don't know where Python installs its library on platform '%s'" % os.name)
  128.  
  129.  
  130. def customize_compiler(compiler):
  131.     """Do any platform-specific customization of a CCompiler instance.
  132.  
  133.     Mainly needed on Unix, so we can plug in the information that
  134.     varies across Unices and is stored in Python's Makefile.
  135.     """
  136.     if compiler.compiler_type == 'unix':
  137.         (cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'SO')
  138.         if os.environ.has_key('CC'):
  139.             cc = os.environ['CC']
  140.         
  141.         if os.environ.has_key('CXX'):
  142.             cxx = os.environ['CXX']
  143.         
  144.         if os.environ.has_key('LDSHARED'):
  145.             ldshared = os.environ['LDSHARED']
  146.         
  147.         if os.environ.has_key('CPP'):
  148.             cpp = os.environ['CPP']
  149.         else:
  150.             cpp = cc + ' -E'
  151.         if os.environ.has_key('LDFLAGS'):
  152.             ldshared = ldshared + ' ' + os.environ['LDFLAGS']
  153.         
  154.         if os.environ.has_key('CFLAGS'):
  155.             cflags = opt + ' ' + os.environ['CFLAGS']
  156.             ldshared = ldshared + ' ' + os.environ['CFLAGS']
  157.         
  158.         if os.environ.has_key('CPPFLAGS'):
  159.             cpp = cpp + ' ' + os.environ['CPPFLAGS']
  160.             cflags = cflags + ' ' + os.environ['CPPFLAGS']
  161.             ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
  162.         
  163.         cc_cmd = cc + ' ' + cflags
  164.         compiler.set_executables(preprocessor = cpp, compiler = cc_cmd, compiler_so = cc_cmd + ' ' + ccshared, compiler_cxx = cxx, linker_so = ldshared, linker_exe = cc)
  165.         compiler.shared_lib_extension = so_ext
  166.     
  167.  
  168.  
  169. def get_config_h_filename():
  170.     '''Return full pathname of installed pyconfig.h file.'''
  171.     if python_build:
  172.         inc_dir = argv0_path
  173.     else:
  174.         inc_dir = get_python_inc(plat_specific = 1)
  175.     if get_python_version() < '2.2':
  176.         config_h = 'config.h'
  177.     else:
  178.         config_h = 'pyconfig.h'
  179.     return os.path.join(inc_dir, config_h)
  180.  
  181.  
  182. def get_makefile_filename():
  183.     '''Return full pathname of installed Makefile from the Python build.'''
  184.     if python_build:
  185.         return os.path.join(os.path.dirname(sys.executable), 'Makefile')
  186.     
  187.     lib_dir = get_python_lib(plat_specific = 1, standard_lib = 1)
  188.     if not sys.pydebug or '_d':
  189.         pass
  190.     return os.path.join(lib_dir, 'config' + '', 'Makefile')
  191.  
  192.  
  193. def parse_config_h(fp, g = None):
  194.     '''Parse a config.h-style file.
  195.  
  196.     A dictionary containing name/value pairs is returned.  If an
  197.     optional dictionary is passed in as the second argument, it is
  198.     used instead of a new dictionary.
  199.     '''
  200.     if g is None:
  201.         g = { }
  202.     
  203.     define_rx = re.compile('#define ([A-Z][A-Za-z0-9_]+) (.*)\n')
  204.     undef_rx = re.compile('/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n')
  205.     while None:
  206.         line = fp.readline()
  207.         if not line:
  208.             break
  209.         
  210.         m = define_rx.match(line)
  211.         if m:
  212.             (n, v) = m.group(1, 2)
  213.             
  214.             try:
  215.                 v = int(v)
  216.             except ValueError:
  217.                 pass
  218.  
  219.             g[n] = v
  220.             continue
  221.         m = undef_rx.match(line)
  222.         if m:
  223.             g[m.group(1)] = 0
  224.             continue
  225.         continue
  226.         return g
  227.  
  228. _variable_rx = re.compile('([a-zA-Z][a-zA-Z0-9_]+)\\s*=\\s*(.*)')
  229. _findvar1_rx = re.compile('\\$\\(([A-Za-z][A-Za-z0-9_]*)\\)')
  230. _findvar2_rx = re.compile('\\${([A-Za-z][A-Za-z0-9_]*)}')
  231.  
  232. def parse_makefile(fn, g = None):
  233.     '''Parse a Makefile-style file.
  234.  
  235.     A dictionary containing name/value pairs is returned.  If an
  236.     optional dictionary is passed in as the second argument, it is
  237.     used instead of a new dictionary.
  238.     '''
  239.     TextFile = TextFile
  240.     import distutils.text_file
  241.     fp = TextFile(fn, strip_comments = 1, skip_blanks = 1, join_lines = 1)
  242.     if g is None:
  243.         g = { }
  244.     
  245.     done = { }
  246.     notdone = { }
  247.     while None:
  248.         line = fp.readline()
  249.         if line is None:
  250.             break
  251.         
  252.         m = _variable_rx.match(line)
  253.         if m:
  254.             (n, v) = m.group(1, 2)
  255.             v = string.strip(v)
  256.             if '$' in v:
  257.                 notdone[n] = v
  258.             else:
  259.                 
  260.                 try:
  261.                     v = int(v)
  262.                 except ValueError:
  263.                     pass
  264.  
  265.                 done[n] = v
  266.         continue
  267.         while notdone:
  268.             for name in notdone.keys():
  269.                 value = notdone[name]
  270.                 if not _findvar1_rx.search(value):
  271.                     pass
  272.                 m = _findvar2_rx.search(value)
  273.                 if m:
  274.                     n = m.group(1)
  275.                     found = True
  276.                     if done.has_key(n):
  277.                         item = str(done[n])
  278.                     elif notdone.has_key(n):
  279.                         found = False
  280.                     elif os.environ.has_key(n):
  281.                         item = os.environ[n]
  282.                     else:
  283.                         done[n] = item = ''
  284.                     if found:
  285.                         after = value[m.end():]
  286.                         value = value[:m.start()] + item + after
  287.                         if '$' in after:
  288.                             notdone[name] = value
  289.                         else:
  290.                             
  291.                             try:
  292.                                 value = int(value)
  293.                             except ValueError:
  294.                                 done[name] = string.strip(value)
  295.  
  296.                             done[name] = value
  297.                             del notdone[name]
  298.                     
  299.                 found
  300.                 del notdone[name]
  301.             
  302.         fp.close()
  303.         g.update(done)
  304.         return g
  305.  
  306.  
  307. def expand_makefile_vars(s, vars):
  308.     '''Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
  309.     \'string\' according to \'vars\' (a dictionary mapping variable names to
  310.     values).  Variables not present in \'vars\' are silently expanded to the
  311.     empty string.  The variable values in \'vars\' should not contain further
  312.     variable expansions; if \'vars\' is the output of \'parse_makefile()\',
  313.     you\'re fine.  Returns a variable-expanded version of \'s\'.
  314.     '''
  315.     while not _findvar1_rx.search(s):
  316.         m = _findvar2_rx.search(s)
  317.         if m:
  318.             (beg, end) = m.span()
  319.             s = s[0:beg] + vars.get(m.group(1)) + s[end:]
  320.             continue
  321.     break
  322.     continue
  323.     return s
  324.  
  325. _config_vars = None
  326.  
  327. def _init_posix():
  328.     '''Initialize the module as appropriate for POSIX systems.'''
  329.     global _config_vars
  330.     g = { }
  331.     
  332.     try:
  333.         filename = get_makefile_filename()
  334.         parse_makefile(filename, g)
  335.     except IOError:
  336.         msg = None
  337.         my_msg = 'invalid Python installation: unable to open %s' % filename
  338.         if hasattr(msg, 'strerror'):
  339.             my_msg = my_msg + ' (%s)' % msg.strerror
  340.         
  341.         raise DistutilsPlatformError(my_msg)
  342.  
  343.     
  344.     try:
  345.         filename = get_config_h_filename()
  346.         parse_config_h(file(filename), g)
  347.     except IOError:
  348.         msg = None
  349.         my_msg = 'invalid Python installation: unable to open %s' % filename
  350.         if hasattr(msg, 'strerror'):
  351.             my_msg = my_msg + ' (%s)' % msg.strerror
  352.         
  353.         raise DistutilsPlatformError(my_msg)
  354.  
  355.     if sys.platform == 'darwin' and g.has_key('MACOSX_DEPLOYMENT_TARGET'):
  356.         cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
  357.         cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
  358.         if cur_target == '':
  359.             cur_target = cfg_target
  360.             os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
  361.         elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
  362.             my_msg = '$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure' % (cur_target, cfg_target)
  363.             raise DistutilsPlatformError(my_msg)
  364.         
  365.     
  366.     if python_build:
  367.         g['LDSHARED'] = g['BLDSHARED']
  368.     elif get_python_version() < '2.1':
  369.         if sys.platform == 'aix4':
  370.             python_lib = get_python_lib(standard_lib = 1)
  371.             ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
  372.             python_exp = os.path.join(python_lib, 'config', 'python.exp')
  373.             g['LDSHARED'] = '%s %s -bI:%s' % (ld_so_aix, g['CC'], python_exp)
  374.         elif sys.platform == 'beos':
  375.             python_lib = get_python_lib(standard_lib = 1)
  376.             linkerscript_path = string.split(g['LDSHARED'])[0]
  377.             linkerscript_name = os.path.basename(linkerscript_path)
  378.             linkerscript = os.path.join(python_lib, 'config', linkerscript_name)
  379.             g['LDSHARED'] = '%s -L%s/lib -lpython%s' % (linkerscript, PREFIX, get_python_version())
  380.         
  381.     
  382.     _config_vars = g
  383.  
  384.  
  385. def _init_nt():
  386.     '''Initialize the module as appropriate for NT'''
  387.     global _config_vars
  388.     g = { }
  389.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  390.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  391.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  392.     g['SO'] = '.pyd'
  393.     g['EXE'] = '.exe'
  394.     _config_vars = g
  395.  
  396.  
  397. def _init_mac():
  398.     '''Initialize the module as appropriate for Macintosh systems'''
  399.     global _config_vars
  400.     g = { }
  401.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  402.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  403.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  404.     import MacOS
  405.     if not hasattr(MacOS, 'runtimemodel'):
  406.         g['SO'] = '.ppc.slb'
  407.     else:
  408.         g['SO'] = '.%s.slb' % MacOS.runtimemodel
  409.     g['install_lib'] = os.path.join(EXEC_PREFIX, 'Lib')
  410.     g['install_platlib'] = os.path.join(EXEC_PREFIX, 'Mac', 'Lib')
  411.     g['srcdir'] = ':'
  412.     _config_vars = g
  413.  
  414.  
  415. def _init_os2():
  416.     '''Initialize the module as appropriate for OS/2'''
  417.     global _config_vars
  418.     g = { }
  419.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  420.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  421.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  422.     g['SO'] = '.pyd'
  423.     g['EXE'] = '.exe'
  424.     _config_vars = g
  425.  
  426.  
  427. def get_config_vars(*args):
  428.     """With no arguments, return a dictionary of all configuration
  429.     variables relevant for the current platform.  Generally this includes
  430.     everything needed to build extensions and install both pure modules and
  431.     extensions.  On Unix, this means every variable defined in Python's
  432.     installed Makefile; on Windows and Mac OS it's a much smaller set.
  433.  
  434.     With arguments, return a list of values that result from looking up
  435.     each argument in the configuration variable dictionary.
  436.     """
  437.     global _config_vars
  438.     if _config_vars is None:
  439.         func = globals().get('_init_' + os.name)
  440.         if func:
  441.             func()
  442.         else:
  443.             _config_vars = { }
  444.         _config_vars['prefix'] = PREFIX
  445.         _config_vars['exec_prefix'] = EXEC_PREFIX
  446.         if sys.platform == 'darwin':
  447.             kernel_version = os.uname()[2]
  448.             major_version = int(kernel_version.split('.')[0])
  449.             if major_version < 8:
  450.                 for key in ('LDFLAGS', 'BASECFLAGS', 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  451.                     flags = _config_vars[key]
  452.                     flags = re.sub('-arch\\s+\\w+\\s', ' ', flags)
  453.                     flags = re.sub('-isysroot [^ \t]*', ' ', flags)
  454.                     _config_vars[key] = flags
  455.                 
  456.             
  457.         
  458.     
  459.     if args:
  460.         vals = []
  461.         for name in args:
  462.             vals.append(_config_vars.get(name))
  463.         
  464.         return vals
  465.     else:
  466.         return _config_vars
  467.  
  468.  
  469. def get_config_var(name):
  470.     """Return the value of a single variable using the dictionary
  471.     returned by 'get_config_vars()'.  Equivalent to
  472.     get_config_vars().get(name)
  473.     """
  474.     return get_config_vars().get(name)
  475.  
  476.