c97186c8b4
Fixed the scripts that comment out the matplotlib magic. It was commenting out all of the magics - the first one, and ones in markdown cells. It should only comment out the ones in code cells, and leave the first one.
30 lines
937 B
Python
30 lines
937 B
Python
import os, sys, io
|
|
|
|
print(sys.argv[1])
|
|
infile = open(sys.argv[1], encoding="utf8")
|
|
data = infile.read()
|
|
infile.close()
|
|
outfile = open(sys.argv[1], "w", encoding="utf8")
|
|
|
|
buf = io.StringIO(data)
|
|
first_inline = False
|
|
is_code_cell = False
|
|
for line in buf:
|
|
# can't comment out first inline that is always in the first cell
|
|
if '"cell_type":' in line:
|
|
is_code_cell = '"code"' in line
|
|
|
|
if is_code_cell:
|
|
if '%matplotlib inline' in line:
|
|
if first_inline:
|
|
line = line.replace("%matplotlib inline", "#%matplotlib inline")
|
|
first_inline = True
|
|
|
|
line = line.replace("%matplotlib notebook", "#%matplotlib notebook")
|
|
line = line.replace("time.sleep", "#time.sleep")
|
|
line = line.replace("fig.canvas.draw", "#fig.canvas.draw")
|
|
line = line.replace("plt.gcf().canvas.draw", "#plt.gcf().canvas.draw")
|
|
outfile.write(line)
|
|
|
|
outfile.close()
|