docstr: Walk the list of source files in 'sources', looking for Cython
  source files (.pyx and .py).  Run Cython on all that are
  found, and return a modified 'sources' list with Cython source
  files replaced by the generated C (or C++) files.
docstr_tok: ["Walk","the","list","of","source","files","in","'sources","'",",","looking","for","Cython","source","files","(",".pyx","and",".py",")",".","Run","Cython","on","all","that","are","found",",","and","return","a","modified","'sources","'","list","with","Cython","source","files","replaced","by","the","generated","C","(","or","C++",")","files","."]
code: def cython_sources(self, sources, extension):
      """
      Walk the list of source files in 'sources', looking for Cython
      source files (.pyx and .py).  Run Cython on all that are
      found, and return a modified 'sources' list with Cython source
      files replaced by the generated C (or C++) files.
      """
      try:
          from Cython.Compiler.Main import (
              CompilationOptions,
              default_options as cython_default_options,
              compile as cython_compile,
          )
          from Cython.Compiler.Errors import PyrexError
      except ImportError:
          e = sys.exc_info()[1]
          print("failed to import Cython: %s" % e)
          raise DistutilsPlatformError(
              "Cython does not appear to be installed"
          )
  
      new_sources = []
      cython_sources = []
      cython_targets = {}
  
      # Setup create_list and cplus from the extension options if
      # Cython.Distutils.extension.Extension is used, otherwise just
      # use what was parsed from the command-line or the configuration file.
      # cplus will also be set to true is extension.language is equal to
      # 'C++' or 'c++'.
      # try:
      #    create_listing = self.cython_create_listing or \
      #                        extension.cython_create_listing
      #    cplus = self.cython_cplus or \
      #                extension.cython_cplus or \
      #                (extension.language != None and \
      #                    extension.language.lower() == 'c++')
      # except AttributeError:
      #    create_listing = self.cython_create_listing
      #    cplus = self.cython_cplus or \
      #                (extension.language != None and \
      #                    extension.language.lower() == 'c++')
  
      create_listing = self.cython_create_listing or getattr(
          extension, "cython_create_listing", 0
      )
      line_directives = self.cython_line_directives or getattr(
          extension, "cython_line_directives", 0
      )
      no_c_in_traceback = self.no_c_in_traceback or getattr(
          extension, "no_c_in_traceback", 0
      )
      cplus = (
          self.cython_cplus
          or getattr(extension, "cython_cplus", 0)
          or (
              extension.language and extension.language.lower() == "c++"
          )
      )
      cython_gen_pxi = self.cython_gen_pxi or getattr(
          extension, "cython_gen_pxi", 0
      )
      cython_gdb = self.cython_gdb or getattr(
          extension, "cython_gdb", False
      )
      cython_compile_time_env = self.cython_compile_time_env or getattr(
          extension, "cython_compile_time_env", None
      )
  
      # Set up the include_path for the Cython compiler:
      #    1.    Start with the command line option.
      #    2.    Add in any (unique) paths from the extension
      #        cython_include_dirs (if Cython.Distutils.extension is used).
      #    3.    Add in any (unique) paths from the extension include_dirs
      includes = self.cython_include_dirs
      try:
          for i in extension.cython_include_dirs:
              if not i in includes:
                  includes.append(i)
      except AttributeError:
          pass
  
      # In case extension.include_dirs is a generator, evaluate it and keep
      # result
      extension.include_dirs = list(extension.include_dirs)
      for i in extension.include_dirs:
          if not i in includes:
              includes.append(i)
  
      # Set up Cython compiler directives:
      #    1. Start with the command line option.
      #    2. Add in any (unique) entries from the extension
      #         cython_directives (if Cython.Distutils.extension is used).
      directives = self.cython_directives
      if hasattr(extension, "cython_directives"):
          directives.update(extension.cython_directives)
  
      # Set the target_ext to '.c'.  Cython will change this to '.cpp' if
      # needed.
      if cplus:
          target_ext = ".cpp"
      else:
          target_ext = ".c"
  
      # Decide whether to drop the generated C files into the temp dir
      # or the source tree.
  
      if not self.inplace and (
          self.cython_c_in_temp
          or getattr(extension, "cython_c_in_temp", 0)
      ):
          target_dir = os.path.join(self.build_temp, "pyrex")
          for package_name in extension.name.split(".")[:-1]:
              target_dir = os.path.join(target_dir, package_name)
      else:
          target_dir = None
  
      newest_dependency = None
      for source in sources:
          (base, ext) = os.path.splitext(os.path.basename(source))
          if ext == ".py":
              # FIXME: we might want to special case this some more
              ext = ".pyx"
          if ext == ".pyx":  # Cython source file
              output_dir = target_dir or os.path.dirname(source)
              new_sources.append(
                  os.path.join(output_dir, base + target_ext)
              )
              cython_sources.append(source)
              cython_targets[source] = new_sources[-1]
          elif ext == ".pxi" or ext == ".pxd":
              if newest_dependency is None or newer(
                  source, newest_dependency
              ):
                  newest_dependency = source
          else:
              new_sources.append(source)
  
      if not cython_sources:
          return new_sources
  
      module_name = extension.name
  
      for source in cython_sources:
          target = cython_targets[source]
          depends = [source] + list(extension.depends or ())
          if source[-4:].lower() == ".pyx" and os.path.isfile(
              source[:-3] + "pxd"
          ):
              depends += [source[:-3] + "pxd"]
          rebuild = self.force or newer_group(depends, target, "newer")
          if not rebuild and newest_dependency is not None:
              rebuild = newer(newest_dependency, target)
          if rebuild:
              log.info("cythoning %s to %s", source, target)
              self.mkpath(os.path.dirname(target))
              if self.inplace:
                  output_dir = os.curdir
              else:
                  output_dir = self.build_lib
              options = CompilationOptions(
                  cython_default_options,
                  use_listing_file=create_listing,
                  include_path=includes,
                  compiler_directives=directives,
                  output_file=target,
                  cplus=cplus,
                  emit_linenums=line_directives,
                  c_line_in_traceback=not no_c_in_traceback,
                  generate_pxi=cython_gen_pxi,
                  output_dir=output_dir,
                  gdb_debug=cython_gdb,
                  compile_time_env=cython_compile_time_env,
              )
              result = cython_compile(
                  source, options=options, full_module_name=module_name
              )
          else:
              log.info(
                  "skipping '%s' Cython extension (up-to-date)", target
              )
  
      return new_sources
  
imports: import inspect
  import sys
  import os
  from distutils.errors import DistutilsPlatformError
  from distutils.dep_util import newer, newer_group
  from distutils import log
  from distutils.command import build_ext
  from distutils import sysconfig
  import warnings
label_desc: Use image node_id 7 for calling the old_build_ext obj's underlying member method code with example usage: obj.cython_sources(sources, extension) and returns: new_sources, new_sources