Back to index

python3.2  3.2.2
Functions | Variables
sysconfig Namespace Reference

Functions

def _safe_realpath
def is_python_build
def _subst_vars
def _extend_dict
def _expand_vars
def _get_default_scheme
def _getuserbase
def _parse_makefile
def get_makefile_filename
def _init_posix
def _init_non_posix
def parse_config_h
def get_config_h_filename
def get_scheme_names
def get_path_names
def get_paths
def get_path
def get_config_vars
def get_config_var
def get_platform
def get_python_version
def _print_dict
def _main

Variables

list __all__
dictionary _INSTALL_SCHEMES
tuple _SCHEME_KEYS
tuple _PY_VERSION = sys.version.split()
list _PY_VERSION_SHORT = sys.version[:3]
list _PY_VERSION_SHORT_NO_DOT = _PY_VERSION[0]
tuple _PREFIX = os.path.normpath(sys.prefix)
tuple _EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
 _CONFIG_VARS = None
 _USER_BASE = None
tuple _PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable))
tuple _PYTHON_BUILD = is_python_build()

Detailed Description

Provide access to Python's configuration information.

Function Documentation

def sysconfig._expand_vars (   scheme,
  vars 
) [private]

Definition at line 164 of file sysconfig.py.

00164 
00165 def _expand_vars(scheme, vars):
00166     res = {}
00167     if vars is None:
00168         vars = {}
00169     _extend_dict(vars, get_config_vars())
00170 
00171     for key, value in _INSTALL_SCHEMES[scheme].items():
00172         if os.name in ('posix', 'nt'):
00173             value = os.path.expanduser(value)
00174         res[key] = os.path.normpath(_subst_vars(value, vars))
00175     return res

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig._extend_dict (   target_dict,
  other_dict 
) [private]

Definition at line 157 of file sysconfig.py.

00157 
00158 def _extend_dict(target_dict, other_dict):
00159     target_keys = target_dict.keys()
00160     for key, value in other_dict.items():
00161         if key in target_keys:
00162             continue
00163         target_dict[key] = value

Here is the caller graph for this function:

def sysconfig._get_default_scheme ( ) [private]

Definition at line 176 of file sysconfig.py.

00176 
00177 def _get_default_scheme():
00178     if os.name == 'posix':
00179         # the default scheme for posix is posix_prefix
00180         return 'posix_prefix'
00181     return os.name

Here is the caller graph for this function:

def sysconfig._getuserbase ( ) [private]

Definition at line 182 of file sysconfig.py.

00182 
00183 def _getuserbase():
00184     env_base = os.environ.get("PYTHONUSERBASE", None)
00185     def joinuser(*args):
00186         return os.path.expanduser(os.path.join(*args))
00187 
00188     # what about 'os2emx', 'riscos' ?
00189     if os.name == "nt":
00190         base = os.environ.get("APPDATA") or "~"
00191         return env_base if env_base else joinuser(base, "Python")
00192 
00193     if sys.platform == "darwin":
00194         framework = get_config_var("PYTHONFRAMEWORK")
00195         if framework:
00196             return env_base if env_base else joinuser("~", "Library", framework, "%d.%d"%(
00197                 sys.version_info[:2]))
00198 
00199     return env_base if env_base else joinuser("~", ".local")
00200 

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig._init_non_posix (   vars) [private]
Initialize the module as appropriate for NT

Definition at line 356 of file sysconfig.py.

00356 
00357 def _init_non_posix(vars):
00358     """Initialize the module as appropriate for NT"""
00359     # set basic install directories
00360     vars['LIBDEST'] = get_path('stdlib')
00361     vars['BINLIBDEST'] = get_path('platstdlib')
00362     vars['INCLUDEPY'] = get_path('include')
00363     vars['SO'] = '.pyd'
00364     vars['EXE'] = '.exe'
00365     vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
00366     vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
00367 
00368 #
00369 # public APIs
00370 #
00371 

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig._init_posix (   vars) [private]
Initialize the module as appropriate for POSIX systems.

Definition at line 329 of file sysconfig.py.

00329 
00330 def _init_posix(vars):
00331     """Initialize the module as appropriate for POSIX systems."""
00332     # load the installed Makefile:
00333     makefile = get_makefile_filename()
00334     try:
00335         _parse_makefile(makefile, vars)
00336     except IOError as e:
00337         msg = "invalid Python installation: unable to open %s" % makefile
00338         if hasattr(e, "strerror"):
00339             msg = msg + " (%s)" % e.strerror
00340         raise IOError(msg)
00341     # load the installed pyconfig.h:
00342     config_h = get_config_h_filename()
00343     try:
00344         with open(config_h) as f:
00345             parse_config_h(f, vars)
00346     except IOError as e:
00347         msg = "invalid Python installation: unable to open %s" % config_h
00348         if hasattr(e, "strerror"):
00349             msg = msg + " (%s)" % e.strerror
00350         raise IOError(msg)
00351     # On AIX, there are wrong paths to the linker scripts in the Makefile
00352     # -- these paths are relative to the Python source, but when installed
00353     # the scripts are in another directory.
00354     if _PYTHON_BUILD:
00355         vars['LDSHARED'] = vars['BLDSHARED']

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig._main ( ) [private]
Display all information sysconfig detains.

Definition at line 753 of file sysconfig.py.

00753 
00754 def _main():
00755     """Display all information sysconfig detains."""
00756     print('Platform: "{0}"'.format(get_platform()))
00757     print('Python version: "{0}"'.format(get_python_version()))
00758     print('Current installation scheme: "{0}"'.format(_get_default_scheme()))
00759     print('')
00760     _print_dict('Paths', get_paths())
00761     print('')
00762     _print_dict('Variables', get_config_vars())

Here is the call graph for this function:

def sysconfig._parse_makefile (   filename,
  vars = None 
) [private]
Parse a Makefile-style file.

A dictionary containing name/value pairs is returned.  If an
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.

Definition at line 201 of file sysconfig.py.

00201 
00202 def _parse_makefile(filename, vars=None):
00203     """Parse a Makefile-style file.
00204 
00205     A dictionary containing name/value pairs is returned.  If an
00206     optional dictionary is passed in as the second argument, it is
00207     used instead of a new dictionary.
00208     """
00209     import re
00210     # Regexes needed for parsing Makefile (and similar syntaxes,
00211     # like old-style Setup files).
00212     _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
00213     _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
00214     _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
00215 
00216     if vars is None:
00217         vars = {}
00218     done = {}
00219     notdone = {}
00220 
00221     with open(filename, errors="surrogateescape") as f:
00222         lines = f.readlines()
00223 
00224     for line in lines:
00225         if line.startswith('#') or line.strip() == '':
00226             continue
00227         m = _variable_rx.match(line)
00228         if m:
00229             n, v = m.group(1, 2)
00230             v = v.strip()
00231             # `$$' is a literal `$' in make
00232             tmpv = v.replace('$$', '')
00233 
00234             if "$" in tmpv:
00235                 notdone[n] = v
00236             else:
00237                 try:
00238                     v = int(v)
00239                 except ValueError:
00240                     # insert literal `$'
00241                     done[n] = v.replace('$$', '$')
00242                 else:
00243                     done[n] = v
00244 
00245     # do variable interpolation here
00246     variables = list(notdone.keys())
00247 
00248     # Variables with a 'PY_' prefix in the makefile. These need to
00249     # be made available without that prefix through sysconfig.
00250     # Special care is needed to ensure that variable expansion works, even
00251     # if the expansion uses the name without a prefix.
00252     renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
00253 
00254     while len(variables) > 0:
00255         for name in tuple(variables):
00256             value = notdone[name]
00257             m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
00258             if m is not None:
00259                 n = m.group(1)
00260                 found = True
00261                 if n in done:
00262                     item = str(done[n])
00263                 elif n in notdone:
00264                     # get it on a subsequent round
00265                     found = False
00266                 elif n in os.environ:
00267                     # do it like make: fall back to environment
00268                     item = os.environ[n]
00269 
00270                 elif n in renamed_variables:
00271                     if name.startswith('PY_') and name[3:] in renamed_variables:
00272                         item = ""
00273 
00274                     elif 'PY_' + n in notdone:
00275                         found = False
00276 
00277                     else:
00278                         item = str(done['PY_' + n])
00279 
00280                 else:
00281                     done[n] = item = ""
00282 
00283                 if found:
00284                     after = value[m.end():]
00285                     value = value[:m.start()] + item + after
00286                     if "$" in after:
00287                         notdone[name] = value
00288                     else:
00289                         try:
00290                             value = int(value)
00291                         except ValueError:
00292                             done[name] = value.strip()
00293                         else:
00294                             done[name] = value
00295                         variables.remove(name)
00296 
00297                         if name.startswith('PY_') \
00298                         and name[3:] in renamed_variables:
00299 
00300                             name = name[3:]
00301                             if name not in done:
00302                                 done[name] = value
00303 
00304 
00305             else:
00306                 # bogus variable reference (e.g. "prefix=$/opt/python");
00307                 # just drop it since we can't deal
00308                 done[name] = value
00309                 variables.remove(name)
00310 
00311     # strip spurious spaces
00312     for k, v in done.items():
00313         if isinstance(v, str):
00314             done[k] = v.strip()
00315 
00316     # save the results in the global dictionary
00317     vars.update(done)
00318     return vars
00319 

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig._print_dict (   title,
  data 
) [private]

Definition at line 747 of file sysconfig.py.

00747 
00748 def _print_dict(title, data):
00749     for index, (key, value) in enumerate(sorted(data.items())):
00750         if index == 0:
00751             print('{0}: '.format(title))
00752         print('\t{0} = "{1}"'.format(key, value))

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig._safe_realpath (   path) [private]

Definition at line 113 of file sysconfig.py.

00113 
00114 def _safe_realpath(path):
00115     try:
00116         return realpath(path)
00117     except OSError:
00118         return path

Here is the caller graph for this function:

def sysconfig._subst_vars (   s,
  local_vars 
) [private]

Definition at line 148 of file sysconfig.py.

00148 
00149 def _subst_vars(s, local_vars):
00150     try:
00151         return s.format(**local_vars)
00152     except KeyError:
00153         try:
00154             return s.format(**os.environ)
00155         except KeyError as var:
00156             raise AttributeError('{%s}' % var)

Here is the caller graph for this function:

Return the path of pyconfig.h.

Definition at line 401 of file sysconfig.py.

00401 
00402 def get_config_h_filename():
00403     """Return the path of pyconfig.h."""
00404     if _PYTHON_BUILD:
00405         if os.name == "nt":
00406             inc_dir = os.path.join(_PROJECT_BASE, "PC")
00407         else:
00408             inc_dir = _PROJECT_BASE
00409     else:
00410         inc_dir = get_path('platinclude')
00411     return os.path.join(inc_dir, 'pyconfig.h')

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig.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)

Definition at line 571 of file sysconfig.py.

00571 
00572 def get_config_var(name):
00573     """Return the value of a single variable using the dictionary returned by
00574     'get_config_vars()'.
00575 
00576     Equivalent to get_config_vars().get(name)
00577     """
00578     return get_config_vars().get(name)

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig.get_config_vars (   args)
With no arguments, return a dictionary of all configuration
variables relevant for the current platform.

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.

Definition at line 440 of file sysconfig.py.

00440 
00441 def get_config_vars(*args):
00442     """With no arguments, return a dictionary of all configuration
00443     variables relevant for the current platform.
00444 
00445     On Unix, this means every variable defined in Python's installed Makefile;
00446     On Windows and Mac OS it's a much smaller set.
00447 
00448     With arguments, return a list of values that result from looking up
00449     each argument in the configuration variable dictionary.
00450     """
00451     import re
00452     global _CONFIG_VARS
00453     if _CONFIG_VARS is None:
00454         _CONFIG_VARS = {}
00455         # Normalized versions of prefix and exec_prefix are handy to have;
00456         # in fact, these are the standard versions used most places in the
00457         # Distutils.
00458         _CONFIG_VARS['prefix'] = _PREFIX
00459         _CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX
00460         _CONFIG_VARS['py_version'] = _PY_VERSION
00461         _CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT
00462         _CONFIG_VARS['py_version_nodot'] = _PY_VERSION[0] + _PY_VERSION[2]
00463         _CONFIG_VARS['base'] = _PREFIX
00464         _CONFIG_VARS['platbase'] = _EXEC_PREFIX
00465         _CONFIG_VARS['projectbase'] = _PROJECT_BASE
00466         try:
00467             _CONFIG_VARS['abiflags'] = sys.abiflags
00468         except AttributeError:
00469             # sys.abiflags may not be defined on all platforms.
00470             _CONFIG_VARS['abiflags'] = ''
00471 
00472         if os.name in ('nt', 'os2'):
00473             _init_non_posix(_CONFIG_VARS)
00474         if os.name == 'posix':
00475             _init_posix(_CONFIG_VARS)
00476         # Setting 'userbase' is done below the call to the
00477         # init function to enable using 'get_config_var' in
00478         # the init-function.
00479         _CONFIG_VARS['userbase'] = _getuserbase()
00480 
00481         if 'srcdir' not in _CONFIG_VARS:
00482             _CONFIG_VARS['srcdir'] = _PROJECT_BASE
00483         else:
00484             _CONFIG_VARS['srcdir'] = _safe_realpath(_CONFIG_VARS['srcdir'])
00485 
00486 
00487         # Convert srcdir into an absolute path if it appears necessary.
00488         # Normally it is relative to the build directory.  However, during
00489         # testing, for example, we might be running a non-installed python
00490         # from a different directory.
00491         if _PYTHON_BUILD and os.name == "posix":
00492             base = _PROJECT_BASE
00493             try:
00494                 cwd = os.getcwd()
00495             except OSError:
00496                 cwd = None
00497             if (not os.path.isabs(_CONFIG_VARS['srcdir']) and
00498                 base != cwd):
00499                 # srcdir is relative and we are not in the same directory
00500                 # as the executable. Assume executable is in the build
00501                 # directory and make srcdir absolute.
00502                 srcdir = os.path.join(base, _CONFIG_VARS['srcdir'])
00503                 _CONFIG_VARS['srcdir'] = os.path.normpath(srcdir)
00504 
00505         if sys.platform == 'darwin':
00506             kernel_version = os.uname()[2] # Kernel version (8.4.3)
00507             major_version = int(kernel_version.split('.')[0])
00508 
00509             if major_version < 8:
00510                 # On Mac OS X before 10.4, check if -arch and -isysroot
00511                 # are in CFLAGS or LDFLAGS and remove them if they are.
00512                 # This is needed when building extensions on a 10.3 system
00513                 # using a universal build of python.
00514                 for key in ('LDFLAGS', 'BASECFLAGS',
00515                         # a number of derived variables. These need to be
00516                         # patched up as well.
00517                         'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
00518                     flags = _CONFIG_VARS[key]
00519                     flags = re.sub('-arch\s+\w+\s', ' ', flags)
00520                     flags = re.sub('-isysroot [^ \t]*', ' ', flags)
00521                     _CONFIG_VARS[key] = flags
00522             else:
00523                 # Allow the user to override the architecture flags using
00524                 # an environment variable.
00525                 # NOTE: This name was introduced by Apple in OSX 10.5 and
00526                 # is used by several scripting languages distributed with
00527                 # that OS release.
00528                 if 'ARCHFLAGS' in os.environ:
00529                     arch = os.environ['ARCHFLAGS']
00530                     for key in ('LDFLAGS', 'BASECFLAGS',
00531                         # a number of derived variables. These need to be
00532                         # patched up as well.
00533                         'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
00534 
00535                         flags = _CONFIG_VARS[key]
00536                         flags = re.sub('-arch\s+\w+\s', ' ', flags)
00537                         flags = flags + ' ' + arch
00538                         _CONFIG_VARS[key] = flags
00539 
00540                 # If we're on OSX 10.5 or later and the user tries to
00541                 # compiles an extension using an SDK that is not present
00542                 # on the current machine it is better to not use an SDK
00543                 # than to fail.
00544                 #
00545                 # The major usecase for this is users using a Python.org
00546                 # binary installer  on OSX 10.6: that installer uses
00547                 # the 10.4u SDK, but that SDK is not installed by default
00548                 # when you install Xcode.
00549                 #
00550                 CFLAGS = _CONFIG_VARS.get('CFLAGS', '')
00551                 m = re.search('-isysroot\s+(\S+)', CFLAGS)
00552                 if m is not None:
00553                     sdk = m.group(1)
00554                     if not os.path.exists(sdk):
00555                         for key in ('LDFLAGS', 'BASECFLAGS',
00556                              # a number of derived variables. These need to be
00557                              # patched up as well.
00558                             'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
00559 
00560                             flags = _CONFIG_VARS[key]
00561                             flags = re.sub('-isysroot\s+\S+(\s|$)', ' ', flags)
00562                             _CONFIG_VARS[key] = flags
00563 
00564     if args:
00565         vals = []
00566         for name in args:
00567             vals.append(_CONFIG_VARS.get(name))
00568         return vals
00569     else:
00570         return _CONFIG_VARS

Here is the call graph for this function:

Here is the caller graph for this function:

Return the path of the Makefile.

Definition at line 320 of file sysconfig.py.

00320 
00321 def get_makefile_filename():
00322     """Return the path of the Makefile."""
00323     if _PYTHON_BUILD:
00324         return os.path.join(_PROJECT_BASE, "Makefile")
00325     return os.path.join(get_path('stdlib'),
00326                         'config-{}{}'.format(_PY_VERSION_SHORT, sys.abiflags),
00327                         'Makefile')
00328 

Here is the call graph for this function:

Here is the caller graph for this function:

def sysconfig.get_path (   name,
  scheme = _get_default_scheme(),
  vars = None,
  expand = True 
)
Return a path corresponding to the scheme.

``scheme`` is the install scheme name.

Definition at line 433 of file sysconfig.py.

00433 
00434 def get_path(name, scheme=_get_default_scheme(), vars=None, expand=True):
00435     """Return a path corresponding to the scheme.
00436 
00437     ``scheme`` is the install scheme name.
00438     """
00439     return get_paths(scheme, vars, expand)[name]

Here is the call graph for this function:

Here is the caller graph for this function:

Return a tuple containing the paths names.

Definition at line 418 of file sysconfig.py.

00418 
00419 def get_path_names():
00420     """Return a tuple containing the paths names."""
00421     return _SCHEME_KEYS

Here is the caller graph for this function:

def sysconfig.get_paths (   scheme = _get_default_scheme(),
  vars = None,
  expand = True 
)
Return a mapping containing an install scheme.

``scheme`` is the install scheme name. If not provided, it will
return the default scheme for the current platform.

Definition at line 422 of file sysconfig.py.

00422 
00423 def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):
00424     """Return a mapping containing an install scheme.
00425 
00426     ``scheme`` is the install scheme name. If not provided, it will
00427     return the default scheme for the current platform.
00428     """
00429     if expand:
00430         return _expand_vars(scheme, vars)
00431     else:
00432         return _INSTALL_SCHEMES[scheme]

Here is the call graph for this function:

Here is the caller graph for this function:

Return a string that identifies the current platform.

This is used mainly to distinguish platform-specific build directories and
platform-specific built distributions.  Typically includes the OS name
and version and the architecture (as supplied by 'os.uname()'),
although the exact information included depends on the OS; eg. for IRIX
the architecture isn't particularly important (IRIX only runs on SGI
hardware), but for Linux the kernel version isn't particularly
important.

Examples of returned values:
   linux-i586
   linux-alpha (?)
   solaris-2.6-sun4u
   irix-5.3
   irix64-6.2

Windows will return one of:
   win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
   win-ia64 (64bit Windows on Itanium)
   win32 (all others - specifically, sys.platform is returned)

For other non-POSIX platforms, currently just returns 'sys.platform'.

Definition at line 579 of file sysconfig.py.

00579 
00580 def get_platform():
00581     """Return a string that identifies the current platform.
00582 
00583     This is used mainly to distinguish platform-specific build directories and
00584     platform-specific built distributions.  Typically includes the OS name
00585     and version and the architecture (as supplied by 'os.uname()'),
00586     although the exact information included depends on the OS; eg. for IRIX
00587     the architecture isn't particularly important (IRIX only runs on SGI
00588     hardware), but for Linux the kernel version isn't particularly
00589     important.
00590 
00591     Examples of returned values:
00592        linux-i586
00593        linux-alpha (?)
00594        solaris-2.6-sun4u
00595        irix-5.3
00596        irix64-6.2
00597 
00598     Windows will return one of:
00599        win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
00600        win-ia64 (64bit Windows on Itanium)
00601        win32 (all others - specifically, sys.platform is returned)
00602 
00603     For other non-POSIX platforms, currently just returns 'sys.platform'.
00604     """
00605     import re
00606     if os.name == 'nt':
00607         # sniff sys.version for architecture.
00608         prefix = " bit ("
00609         i = sys.version.find(prefix)
00610         if i == -1:
00611             return sys.platform
00612         j = sys.version.find(")", i)
00613         look = sys.version[i+len(prefix):j].lower()
00614         if look == 'amd64':
00615             return 'win-amd64'
00616         if look == 'itanium':
00617             return 'win-ia64'
00618         return sys.platform
00619 
00620     if os.name != "posix" or not hasattr(os, 'uname'):
00621         # XXX what about the architecture? NT is Intel or Alpha,
00622         # Mac OS is M68k or PPC, etc.
00623         return sys.platform
00624 
00625     # Try to distinguish various flavours of Unix
00626     osname, host, release, version, machine = os.uname()
00627 
00628     # Convert the OS name to lowercase, remove '/' characters
00629     # (to accommodate BSD/OS), and translate spaces (for "Power Macintosh")
00630     osname = osname.lower().replace('/', '')
00631     machine = machine.replace(' ', '_')
00632     machine = machine.replace('/', '-')
00633 
00634     if osname[:5] == "linux":
00635         # At least on Linux/Intel, 'machine' is the processor --
00636         # i386, etc.
00637         # XXX what about Alpha, SPARC, etc?
00638         return  "%s-%s" % (osname, machine)
00639     elif osname[:5] == "sunos":
00640         if release[0] >= "5":           # SunOS 5 == Solaris 2
00641             osname = "solaris"
00642             release = "%d.%s" % (int(release[0]) - 3, release[2:])
00643         # fall through to standard osname-release-machine representation
00644     elif osname[:4] == "irix":              # could be "irix64"!
00645         return "%s-%s" % (osname, release)
00646     elif osname[:3] == "aix":
00647         return "%s-%s.%s" % (osname, version, release)
00648     elif osname[:6] == "cygwin":
00649         osname = "cygwin"
00650         rel_re = re.compile (r'[\d.]+')
00651         m = rel_re.match(release)
00652         if m:
00653             release = m.group()
00654     elif osname[:6] == "darwin":
00655         #
00656         # For our purposes, we'll assume that the system version from
00657         # distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set
00658         # to. This makes the compatibility story a bit more sane because the
00659         # machine is going to compile and link as if it were
00660         # MACOSX_DEPLOYMENT_TARGET.
00661         #
00662         cfgvars = get_config_vars()
00663         macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET')
00664 
00665         if 1:
00666             # Always calculate the release of the running machine,
00667             # needed to determine if we can build fat binaries or not.
00668 
00669             macrelease = macver
00670             # Get the system version. Reading this plist is a documented
00671             # way to get the system version (see the documentation for
00672             # the Gestalt Manager)
00673             try:
00674                 f = open('/System/Library/CoreServices/SystemVersion.plist')
00675             except IOError:
00676                 # We're on a plain darwin box, fall back to the default
00677                 # behaviour.
00678                 pass
00679             else:
00680                 try:
00681                     m = re.search(
00682                             r'<key>ProductUserVisibleVersion</key>\s*' +
00683                             r'<string>(.*?)</string>', f.read())
00684                     if m is not None:
00685                         macrelease = '.'.join(m.group(1).split('.')[:2])
00686                     # else: fall back to the default behaviour
00687                 finally:
00688                     f.close()
00689 
00690         if not macver:
00691             macver = macrelease
00692 
00693         if macver:
00694             release = macver
00695             osname = "macosx"
00696 
00697             if (macrelease + '.') >= '10.4.' and \
00698                     '-arch' in get_config_vars().get('CFLAGS', '').strip():
00699                 # The universal build will build fat binaries, but not on
00700                 # systems before 10.4
00701                 #
00702                 # Try to detect 4-way universal builds, those have machine-type
00703                 # 'universal' instead of 'fat'.
00704 
00705                 machine = 'fat'
00706                 cflags = get_config_vars().get('CFLAGS')
00707 
00708                 archs = re.findall('-arch\s+(\S+)', cflags)
00709                 archs = tuple(sorted(set(archs)))
00710 
00711                 if len(archs) == 1:
00712                     machine = archs[0]
00713                 elif archs == ('i386', 'ppc'):
00714                     machine = 'fat'
00715                 elif archs == ('i386', 'x86_64'):
00716                     machine = 'intel'
00717                 elif archs == ('i386', 'ppc', 'x86_64'):
00718                     machine = 'fat3'
00719                 elif archs == ('ppc64', 'x86_64'):
00720                     machine = 'fat64'
00721                 elif archs == ('i386', 'ppc', 'ppc64', 'x86_64'):
00722                     machine = 'universal'
00723                 else:
00724                     raise ValueError(
00725                        "Don't know machine value for archs=%r"%(archs,))
00726 
00727             elif machine == 'i386':
00728                 # On OSX the machine type returned by uname is always the
00729                 # 32-bit variant, even if the executable architecture is
00730                 # the 64-bit variant
00731                 if sys.maxsize >= 2**32:
00732                     machine = 'x86_64'
00733 
00734             elif machine in ('PowerPC', 'Power_Macintosh'):
00735                 # Pick a sane name for the PPC architecture.
00736                 # See 'i386' case
00737                 if sys.maxsize >= 2**32:
00738                     machine = 'ppc64'
00739                 else:
00740                     machine = 'ppc'
00741 
00742     return "%s-%s-%s" % (osname, release, machine)
00743 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 744 of file sysconfig.py.

00744 
00745 def get_python_version():
00746     return _PY_VERSION_SHORT

Here is the caller graph for this function:

Return a tuple containing the schemes names.

Definition at line 412 of file sysconfig.py.

00412 
00413 def get_scheme_names():
00414     """Return a tuple containing the schemes names."""
00415     schemes = list(_INSTALL_SCHEMES.keys())
00416     schemes.sort()
00417     return tuple(schemes)

Here is the caller graph for this function:

Definition at line 135 of file sysconfig.py.

00135 
00136 def is_python_build():
00137     for fn in ("Setup.dist", "Setup.local"):
00138         if os.path.isfile(os.path.join(_PROJECT_BASE, "Modules", fn)):
00139             return True
00140     return False

Here is the caller graph for this function:

def sysconfig.parse_config_h (   fp,
  vars = None 
)
Parse a config.h-style file.

A dictionary containing name/value pairs is returned.  If an
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.

Definition at line 372 of file sysconfig.py.

00372 
00373 def parse_config_h(fp, vars=None):
00374     """Parse a config.h-style file.
00375 
00376     A dictionary containing name/value pairs is returned.  If an
00377     optional dictionary is passed in as the second argument, it is
00378     used instead of a new dictionary.
00379     """
00380     import re
00381     if vars is None:
00382         vars = {}
00383     define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
00384     undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
00385 
00386     while True:
00387         line = fp.readline()
00388         if not line:
00389             break
00390         m = define_rx.match(line)
00391         if m:
00392             n, v = m.group(1, 2)
00393             try: v = int(v)
00394             except ValueError: pass
00395             vars[n] = v
00396         else:
00397             m = undef_rx.match(line)
00398             if m:
00399                 vars[m.group(1)] = 0
00400     return vars

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 [
00002     'get_config_h_filename',
00003     'get_config_var',
00004     'get_config_vars',
00005     'get_makefile_filename',
00006     'get_path',
00007     'get_path_names',
00008     'get_paths',
00009     'get_platform',
00010     'get_python_version',
00011     'get_scheme_names',
00012     'parse_config_h',
00013     ]

Definition at line 8 of file sysconfig.py.

Definition at line 110 of file sysconfig.py.

Definition at line 109 of file sysconfig.py.

Definition at line 22 of file sysconfig.py.

Definition at line 108 of file sysconfig.py.

tuple sysconfig._PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable))

Definition at line 120 of file sysconfig.py.

Definition at line 105 of file sysconfig.py.

Definition at line 106 of file sysconfig.py.

Definition at line 107 of file sysconfig.py.

Definition at line 141 of file sysconfig.py.

Initial value:
00001 ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
00002                 'scripts', 'data')

Definition at line 103 of file sysconfig.py.

Definition at line 111 of file sysconfig.py.