#NEWLINE# def write_stub( self , output_dir , ext , compile = False ) : #NEWLINE# #INDENT# log . info ( 'writing stub loader for %s to %s' , ext . _full_name , output_dir ) #NEWLINE# stub_file = ( os . path . join ( output_dir , * ext . _full_name . split ( '.' ) ) + '.py' ) #NEWLINE# if ( compile and os . path . exists ( stub_file ) ) : #NEWLINE# #INDENT# raise DistutilsError ( ( stub_file + ' already exists! Please delete.' ) ) #NEWLINE# #UNINDENT# if ( not self . dry_run ) : #NEWLINE# #INDENT# f = open ( stub_file , 'w' ) #NEWLINE# f . write ( '\n' . join ( [ 'def __bootstrap__():' , '   global __bootstrap__, __file__, __loader__' , ( '   import sys, os, pkg_resources, imp' + if_dl ( ', dl' ) ) , ( '   __file__ = pkg_resources.resource_filename(__name__,%r)' % os . path . basename ( f . _file_name ) ) , '   del __bootstrap__' , "   if '__loader__' in globals():" , '       del __loader__' , if_dl ( '   old_flags = sys.getdlopenflags()' ) , '   old_dir = os.getcwd()' , '   try:' , '     os.chdir(os.path.dirname(__file__))' , if_dl ( '     sys.setdlopenflags(dl.RTLD_NOW)' ) , '     imp.load_dynamic(__name__,__file__)' , '   finally:' , if_dl ( '     sys.setdlopenflags(old_flags)' ) , '     os.chdir(old_dir)' , '__bootstrap__()' , '' ] ) ) #NEWLINE# f . close ( ) #NEWLINE# #UNINDENT# if compile : #NEWLINE# #INDENT# from distutils.util import byte_compile #NEWLINE# byte_compile ( [ stub_file ] , optimize = 0 , force = True , dry_run = self . dry_run ) #NEWLINE# optimize = self . get_finalized_command ( 'install_lib' ) . optimize #NEWLINE# if ( optimize > 0 ) : #NEWLINE# #INDENT# byte_compile ( [ stub_file ] , optimize = optimize , force = True , dry_run = self . dry_run ) #NEWLINE# #UNINDENT# if ( os . path . exists ( stub_file ) and ( not self . dry_run ) ) : #NEWLINE# #INDENT# os . unlink ( stub_file )