code: def _add_py_module(dist, ffi, module_name):
      from distutils.dir_util import mkpath
      from setuptools.command.build_py import build_py
      from setuptools.command.build_ext import build_ext
      from distutils import log
      from cffi import recompiler
  
      def generate_mod(py_file):
          log.info("generating cffi module %r" % py_file)
          mkpath(os.path.dirname(py_file))
          updated = recompiler.make_py_source(ffi, module_name, py_file)
          if not updated:
              log.info("already up-to-date")
  
      base_class = dist.cmdclass.get("build_py", build_py)
  
      class build_py_make_mod(base_class):
          def run(self):
              base_class.run(self)
              module_path = module_name.split(".")
              module_path[-1] += ".py"
              generate_mod(os.path.join(self.build_lib, *module_path))
  
          def get_source_files(self):
              # This is called from 'setup.py sdist' only.  Exclude
              # the generate .py module in this case.
              saved_py_modules = self.py_modules
              try:
                  if saved_py_modules:
                      self.py_modules = [
                          m
                          for m in saved_py_modules
                          if m != module_name
                      ]
                  return base_class.get_source_files(self)
              finally:
                  self.py_modules = saved_py_modules
  
      dist.cmdclass["build_py"] = build_py_make_mod
  
      # distutils and setuptools have no notion I could find of a
      # generated python module.  If we don't add module_name to
      # dist.py_modules, then things mostly work but there are some
      # combination of options (--root and --record) that will miss
      # the module.  So we add it here, which gives a few apparently
      # harmless warnings about not finding the file outside the
      # build directory.
      # Then we need to hack more in get_source_files(); see above.
      if dist.py_modules is None:
          dist.py_modules = []
      dist.py_modules.append(module_name)
  
      # the following is only for "build_ext -i"
      base_class_2 = dist.cmdclass.get("build_ext", build_ext)
  
      class build_ext_make_mod(base_class_2):
          def run(self):
              base_class_2.run(self)
              if self.inplace:
                  # from get_ext_fullpath() in distutils/command/build_ext.py
                  module_path = module_name.split(".")
                  package = ".".join(module_path[:-1])
                  build_py = self.get_finalized_command("build_py")
                  package_dir = build_py.get_package_dir(package)
                  file_name = module_path[-1] + ".py"
                  generate_mod(os.path.join(package_dir, file_name))
  
      dist.cmdclass["build_ext"] = build_ext_make_mod
  
file_path: catboost/contrib/python/cffi/py2/cffi/setuptools_ext.py
imports: import os
  import sys
label_desc: Use image node_id 6 for calling a global function with example usage: _add_py_module(dist, ffi, module_name) and returns: base_class