code: def debug_mro_failure(name, bases):
      graph = build_linearization_graph(name, bases)
      cycles = sorted(nx.cycles.simple_cycles(graph), key=len)
      cycle = cycles[0]
  
      if os.environ.get("DRAW_MRO_FAILURES"):
          output_file = name + ".dot"
      else:
          output_file = None
  
      # Return a nicely formatted error describing the cycle.
      lines = [
          "Cycle found when trying to compute MRO for {}:\n".format(
              name
          )
      ]
      for source, dest in list(zip(cycle, cycle[1:])) + [
          (cycle[-1], cycle[0])
      ]:
          label = verbosify_label(
              graph.get_edge_data(source, dest)["label"]
          )
          lines.append(
              "{} comes before {}: cause={}".format(source, dest, label)
          )
  
      # Either graphviz graph and tell the user where it went, or tell people how
      # to enable that feature.
      lines.append("")
      if output_file is None:
          lines.append(
              "Set the DRAW_MRO_FAILURES environment variable to"
              " render a GraphViz graph of this cycle."
          )
      else:
          try:
              nx.write_dot(graph.subgraph(cycle), output_file)
              subprocess.check_call(
                  ["dot", "-T", "svg", "-O", output_file]
              )
              lines.append(
                  "GraphViz rendering written to "
                  + output_file
                  + ".svg"
              )
          except Exception as e:
              lines.append(
                  "Failed to write GraphViz graph. Error was {}".format(
                      e
                  )
              )
  
      return "\n".join(lines)
  
file_path: zipline/zipline/testing/debug.py
imports: import os
  import subprocess
  import networkx
label_desc: Use image node_id 1 for calling a global function with example usage: debug_mro_failure(name, bases) and returns: str