code: def write_stub(self, output_dir, ext, compile=False):
      log.info(
          "writing stub loader for %s to %s", ext._full_name, output_dir
      )
      stub_file = (
          os.path.join(output_dir, *ext._full_name.split(".")) + ".py"
      )
      if compile and os.path.exists(stub_file):
          raise DistutilsError(
              stub_file + " already exists! Please delete."
          )
      if not self.dry_run:
          f = open(stub_file, "w")
          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(ext._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__()",
                      "",  # terminal \n
                  ]
              )
          )
          f.close()
      if compile:
          from distutils.util import byte_compile
  
          byte_compile(
              [stub_file], optimize=0, force=True, dry_run=self.dry_run
          )
          optimize = self.get_finalized_command("install_lib").optimize
          if optimize > 0:
              byte_compile(
                  [stub_file],
                  optimize=optimize,
                  force=True,
                  dry_run=self.dry_run,
              )
          if os.path.exists(stub_file) and not self.dry_run:
              os.unlink(stub_file)
  
imports: import os
  import sys
  import itertools
  from distutils.command.build_ext import build_ext
  from distutils.file_util import copy_file
  from distutils.ccompiler import new_compiler
  from distutils.sysconfig import customize_compiler, get_config_var
  from distutils.errors import DistutilsError
  from distutils import log
  from setuptools.extension import Library
  from setuptools.extern import six
  from distutils.sysconfig import _config_vars
label_desc: Use image node_id 13 for calling the build_ext obj's underlying member method code with example usage: obj.write_stub(output_dir, ext, compile) without return types