Skip to content

Commit 9f9fd56

Browse files
committed
fix tutorial exporter to work with greek letters
1 parent 2048c6c commit 9f9fd56

File tree

3 files changed

+15
-43
lines changed

3 files changed

+15
-43
lines changed

docs/tutorial/closer_look_at_plot_pos.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@
154154
},
155155
"outputs": [],
156156
"source": [
157-
"w_opts = {'label': 'Weibull (a=0, b=0)', 'marker': 'o', 'markeredgecolor': 'b'}\n",
158-
"c_opts = {'label': 'Cunnane (a=0.4, b=0.4)', 'marker': 's', 'markeredgecolor': 'g'}\n",
157+
"w_opts = {'label': 'Weibull (α=0, β=0)', 'marker': 'o', 'markeredgecolor': 'b'}\n",
158+
"c_opts = {'label': 'Cunnane (α=0.4, β=0.4)', 'marker': 's', 'markeredgecolor': 'g'}\n",
159159
"\n",
160160
"common_opts = {\n",
161161
" 'markerfacecolor': 'none',\n",
@@ -198,7 +198,7 @@
198198
},
199199
"outputs": [],
200200
"source": [
201-
"h_opts = {'label': 'Hazen (a=0.5, b=0.5)', 'marker': '^', 'markeredgecolor': 'r'}\n",
201+
"h_opts = {'label': 'Hazen (α=0.5, β=0.5)', 'marker': '^', 'markeredgecolor': 'r'}\n",
202202
"fig, (ax1, ax2) = pyplot.subplots(figsize=(10, 8), ncols=2, sharex=True, sharey=False)\n",
203203
"\n",
204204
"for dist, ax in zip([None, weibull], [ax1, ax2]):\n",

docs/tutorial/getting_started.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@
208208
"\n",
209209
"beta1 = stats.beta(a=3, b=2)\n",
210210
"ax2.set_xscale('prob', dist=beta1)\n",
211-
"ax2.set_xlabel('Beta probability scale (a=3, b=2)')\n",
211+
"ax2.set_xlabel('Beta probability scale (α=3, β=2)')\n",
212212
"\n",
213213
"beta2 = stats.beta(a=2, b=7)\n",
214214
"ax3.set_xscale('prob', dist=beta2)\n",
215-
"ax3.set_xlabel('Beta probability scale (a=2, b=7)')\n",
215+
"ax3.set_xlabel('Beta probability scale (α=2, β=7)')\n",
216216
"\n",
217217
"ax4.set_xticks(ax1.get_xticks()[12:-12])\n",
218218
"ax4.set_xlabel('Linear scale (for reference)')\n",

docs/tutorial/make.py

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,33 @@
22
import glob
33

44
import nbformat
5-
from nbconvert import RSTExporter, preprocessors
5+
from nbconvert import RSTExporter
6+
from nbconvert.preprocessors import ExecutePreprocessor
67

78

8-
def cache(nbfile):
9+
def convert(nbfile):
910
basename, _ = os.path.splitext(nbfile)
10-
bakfile = basename + '.bak'
11-
with open(nbfile, 'r') as nb, open(bakfile, 'w') as bak:
12-
bak.write(nb.read())
13-
return bakfile
14-
1511

16-
def process(nbfile, processor):
1712
meta = {'metadata': {'path': '.'}}
18-
with open(nbfile, 'r') as nbf:
19-
nbook = nbformat.read(nbf, as_version=4)
20-
21-
runner = processor(timeout=600, kernel_name='probscale')
22-
runner.preprocess(nbook, meta)
23-
24-
with open(nbfile, 'w') as nbf:
25-
nbformat.write(nbook, nbf)
13+
with open(nbfile, 'r', encoding='utf-8') as nbf:
14+
nbdata = nbformat.read(nbf, as_version=4, encoding='utf-8')
2615

16+
runner = ExecutePreprocessor(timeout=600, kernel_name='probscale')
17+
runner.preprocess(nbdata, meta)
2718

28-
def convert(nbfile):
29-
basename, _ = os.path.splitext(nbfile)
3019
img_folder = basename + '_files'
31-
os.makedirs(img_folder, exist_ok=True)
32-
print("\tconverting " + nbfile)
33-
34-
with open(nbfile, 'r') as nb:
35-
nbdata = nbformat.reads(nb.read(), as_version=4)
36-
37-
rst = RSTExporter()
38-
body_raw, images = rst.from_notebook_node(nbdata)
20+
body_raw, images = RSTExporter().from_notebook_node(nbdata)
3921
body_final = body_raw.replace('.. image:: ', '.. image:: {}/'.format(img_folder))
4022

41-
with open(basename + '.rst', 'w') as rst_out:
23+
with open(basename + '.rst', 'w', encoding='utf-8') as rst_out:
4224
rst_out.write(body_final)
4325

4426
for img_name, img_data in images['outputs'].items():
4527
img_path = os.path.join(img_folder, img_name)
4628
with open(img_path, 'wb') as img:
47-
print('\twriting ' + img_path)
4829
img.write(img_data)
4930

5031

5132
if __name__ == '__main__':
5233
for nbfile in glob.glob('*.ipynb'):
53-
bak = cache(nbfile)
54-
success = False
55-
try:
56-
process(nbfile, preprocessors.ExecutePreprocessor)
57-
convert(nbfile)
58-
success = True
59-
finally:
60-
process(nbfile, preprocessors.ClearOutputPreprocessor)
61-
if success:
62-
os.remove(bak)
34+
convert(nbfile)

0 commit comments

Comments
 (0)