()
Generate the Python module containing build-time variables.
Generate the Python module containing build-time variables.
Generate the Python module containing build - time variables .
def _generate_posix_vars():
    """Generate the Python module containing build-time variables."""
    import pprint
    vars = {}
    # load the installed Makefile:
    makefile = _get_makefile_filename()
    try:
        _parse_makefile(makefile, vars)
    except IOError, e:
        msg = "invalid Python installation: unable to open %s" % makefile
        if hasattr(e, "strerror"):
            msg = msg + " (%s)" % e.strerror
        raise IOError(msg)

    # load the installed pyconfig.h:
    config_h = get_config_h_filename()
    try:
        with open(config_h) as f:
            parse_config_h(f, vars)
    except IOError, e:
        msg = "invalid Python installation: unable to open %s" % config_h
        if hasattr(e, "strerror"):
            msg = msg + " (%s)" % e.strerror
        raise IOError(msg)

    # On AIX, there are wrong paths to the linker scripts in the Makefile
    # -- these paths are relative to the Python source, but when installed
    # the scripts are in another directory.
    if _PYTHON_BUILD:
        vars['LDSHARED'] = vars['BLDSHARED']

    # There's a chicken-and-egg situation on OS X with regards to the
    # _sysconfigdata module after the changes introduced by #15298:
    # get_config_vars() is called by get_platform() as part of the
    # `make pybuilddir.txt` target -- which is a precursor to the
    # _sysconfigdata.py module being constructed.  Unfortunately,
    # get_config_vars() eventually calls _init_posix(), which attempts
    # to import _sysconfigdata, which we won't have built yet.  In order
    # for _init_posix() to work, if we're on Darwin, just mock up the
    # _sysconfigdata module manually and populate it with the build vars.
    # This is more than sufficient for ensuring the subsequent call to
    # get_platform() succeeds.
    name = '_sysconfigdata'
    if 'darwin' in sys.platform:
        import imp
        module = imp.new_module(name)
        module.build_time_vars = vars
        sys.modules[name] = module

    pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3])
    if hasattr(sys, "gettotalrefcount"):
        pybuilddir += '-pydebug'
    try:
        os.makedirs(pybuilddir)
    except OSError:
        pass
    destfile = os.path.join(pybuilddir, name + '.py')

    with open(destfile, 'wb') as f:
        f.write('# system configuration generated and used by'
                ' the sysconfig module\n')
        f.write('build_time_vars = ')
        pprint.pprint(vars, stream=f)

    # Create file used for sys.path fixup -- see Modules/getpath.c
    with open('pybuilddir.txt', 'w') as f:
        f.write(pybuilddir)
def _generate_posix_vars ( ) : import pprint vars = { } # load the installed Makefile: makefile = _get_makefile_filename ( ) try : _parse_makefile ( makefile , vars ) except IOError , e : msg = "invalid Python installation: unable to open %s" % makefile if hasattr ( e , "strerror" ) : msg = msg + " (%s)" % e . strerror raise IOError ( msg ) # load the installed pyconfig.h: config_h = get_config_h_filename ( ) try : with open ( config_h ) as f : parse_config_h ( f , vars ) except IOError , e : msg = "invalid Python installation: unable to open %s" % config_h if hasattr ( e , "strerror" ) : msg = msg + " (%s)" % e . strerror raise IOError ( msg ) # On AIX, there are wrong paths to the linker scripts in the Makefile # -- these paths are relative to the Python source, but when installed # the scripts are in another directory. if _PYTHON_BUILD : vars [ 'LDSHARED' ] = vars [ 'BLDSHARED' ] # There's a chicken-and-egg situation on OS X with regards to the # _sysconfigdata module after the changes introduced by #15298: # get_config_vars() is called by get_platform() as part of the # `make pybuilddir.txt` target -- which is a precursor to the # _sysconfigdata.py module being constructed.  Unfortunately, # get_config_vars() eventually calls _init_posix(), which attempts # to import _sysconfigdata, which we won't have built yet.  In order # for _init_posix() to work, if we're on Darwin, just mock up the # _sysconfigdata module manually and populate it with the build vars. # This is more than sufficient for ensuring the subsequent call to # get_platform() succeeds. name = '_sysconfigdata' if 'darwin' in sys . platform : import imp module = imp . new_module ( name ) module . build_time_vars = vars sys . modules [ name ] = module pybuilddir = 'build/lib.%s-%s' % ( get_platform ( ) , sys . version [ : 3 ] ) if hasattr ( sys , "gettotalrefcount" ) : pybuilddir += '-pydebug' try : os . makedirs ( pybuilddir ) except OSError : pass destfile = os . path . join ( pybuilddir , name + '.py' ) with open ( destfile , 'wb' ) as f : f . write ( '# system configuration generated and used by' ' the sysconfig module\n' ) f . write ( 'build_time_vars = ' ) pprint . pprint ( vars , stream = f ) # Create file used for sys.path fixup -- see Modules/getpath.c with open ( 'pybuilddir.txt' , 'w' ) as f : f . write ( pybuilddir )