home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / sysconfig.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-11-11  |  16.4 KB  |  527 lines

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