debug.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. Contains debug writer.
  3. """
  4. from pprint import pprint
  5. from .base import WriterBase
  6. # -----------------------------------------------------------------------------
  7. # Copyright (c) 2013, the IPython Development Team.
  8. #
  9. # Distributed under the terms of the Modified BSD License.
  10. #
  11. # The full license is in the file COPYING.txt, distributed with this software.
  12. # -----------------------------------------------------------------------------
  13. # -----------------------------------------------------------------------------
  14. # Imports
  15. # -----------------------------------------------------------------------------
  16. # -----------------------------------------------------------------------------
  17. # Classes
  18. # -----------------------------------------------------------------------------
  19. class DebugWriter(WriterBase):
  20. """Consumes output from nbconvert export...() methods and writes useful
  21. debugging information to the stdout. The information includes a list of
  22. resources that were extracted from the notebook(s) during export."""
  23. def write(self, output, resources, notebook_name="notebook", **kw):
  24. """
  25. Consume and write Jinja output.
  26. See base for more...
  27. """
  28. if isinstance(resources["outputs"], dict):
  29. print("outputs extracted from %s" % notebook_name)
  30. print("-" * 80)
  31. pprint(resources["outputs"], indent=2, width=70) # noqa: T203
  32. else:
  33. print("no outputs extracted from %s" % notebook_name)
  34. print("=" * 80)