generator for sequence of code blocks to run
()
| 2792 | dname = os.path.dirname(fname) |
| 2793 | |
| 2794 | def get_cells(): |
| 2795 | """generator for sequence of code blocks to run""" |
| 2796 | if fname.endswith('.ipynb'): |
| 2797 | from nbformat import read |
| 2798 | nb = read(fname, as_version=4) |
| 2799 | if not nb.cells: |
| 2800 | return |
| 2801 | for cell in nb.cells: |
| 2802 | if cell.cell_type == 'code': |
| 2803 | yield cell.source |
| 2804 | else: |
| 2805 | with open(fname) as f: |
| 2806 | yield f.read() |
| 2807 | |
| 2808 | with prepended_to_syspath(dname): |
| 2809 | try: |