parameters: (filename, include_roots)
docstring: Comment out #include directives that include a nonexistent file
  
      Keyword arguments:
      filename -- file to search for includes
      include_roots -- list of search paths for includes
docstring_summary: Comment out #include directives that include a nonexistent file
docstring_tokens: Comment out #include directives that include a nonexistent file
function: def comment_out_invalid_includes(filename, include_roots):
      """Comment out #include directives that include a nonexistent file
  
      Keyword arguments:
      filename -- file to search for includes
      include_roots -- list of search paths for includes
      """
      # Read header
      with open(filename) as f:
          old_contents = f.read()
  
      new_contents = ""
      pos = 0
      for match in re.finditer(r"#include \"([^\"]+)\"", old_contents):
          include = match.group(1)
  
          # Write contents from before this match
          new_contents += old_contents[pos:match.span()[0]]
  
          # Comment out #include if the file doesn't exist in current directory or
          # include root
          if not os.path.exists(os.path.join(
                  os.path.dirname(filename), include)) and not any(
                      os.path.exists(os.path.join(include_root, include))
                      for include_root in include_roots):
              new_contents += "// "
  
          new_contents += match.group()
          pos = match.span()[1]
  
      # Write rest of file if it wasn't all processed
      if pos < len(old_contents):
          new_contents += old_contents[pos:]
  
      # Write modified file back out
      if old_contents != new_contents:
          with open(filename, "w") as f:
              f.write(new_contents)
function_tokens: def comment_out_invalid_includes ( filename , include_roots ) : # Read header with open ( filename ) as f : old_contents = f . read ( ) new_contents = "" pos = 0 for match in re . finditer ( r"#include \"([^\"]+)\"" , old_contents ) : include = match . group ( 1 ) # Write contents from before this match new_contents += old_contents [ pos : match . span ( ) [ 0 ] ] # Comment out #include if the file doesn't exist in current directory or # include root if not os . path . exists ( os . path . join ( os . path . dirname ( filename ) , include ) ) and not any ( os . path . exists ( os . path . join ( include_root , include ) ) for include_root in include_roots ) : new_contents += "// " new_contents += match . group ( ) pos = match . span ( ) [ 1 ] # Write rest of file if it wasn't all processed if pos < len ( old_contents ) : new_contents += old_contents [ pos : ] # Write modified file back out if old_contents != new_contents : with open ( filename , "w" ) as f : f . write ( new_contents )