Skip to content

Commit c65fc16

Browse files
committed
fixes #24
1 parent bcf94db commit c65fc16

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.1.6 — 13 Jul 2022
4+
5+
- Notebook kernel is changed to match the current course.
6+
7+
38
## 0.1.5 — 18 May 2022
49

510
- Improved the appearance of feedback messages, and added emojis.

kosu/customize.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ def hide_toolbar(notebook):
110110
return notebook
111111

112112

113+
def change_kernel(notebook, kernel):
114+
"""
115+
Vanillafy the kernelspec.
116+
"""
117+
new_kernelspec = {
118+
"display_name": f"{kernel}",
119+
"language": "python",
120+
"name": f"{kernel}",
121+
}
122+
notebook['metadata']['kernelspec'].update(new_kernelspec)
123+
return notebook
124+
125+
113126
def process_notebook(infile,
114127
outfile,
115128
clear_input=False, # Don't touch the input file.
@@ -120,6 +133,7 @@ def process_notebook(infile,
120133
hidecode=True,
121134
demo=False, # If demo, remove exercises and enable demos.
122135
data_url_stem=None,
136+
kernel=None,
123137
):
124138
"""
125139
Loads an 'ipynb' file as a dict and performs cleaning tasks
@@ -147,6 +161,9 @@ def process_notebook(infile,
147161
if hidecode:
148162
notebook = hide_code(notebook)
149163

164+
if kernel is not None:
165+
notebook = change_kernel(notebook, kernel)
166+
150167
notebook = hide_toolbar(notebook)
151168

152169
text = json.dumps(notebook)

kosu/kosu.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def build_course(course, clean, zip, upload, clobber):
307307
if upload:
308308
success = upload_zip(zipped)
309309
if success:
310-
click.secho(f"⬆️ Uploaded {zipped}", fg="green")
310+
click.secho(f"⬆️ Uploaded {zipped}", fg="green")
311311
link = f"https://{KOSU['s3-bucket']}.s3.amazonaws.com/"
312312
link += f"{course}.zip"
313313
click.secho(f"🔗 File link: {link}", fg="green")
@@ -342,13 +342,14 @@ def build_notebooks(path, config):
342342
all_items = [f for items in config['curriculum'].values() for f in items]
343343
notebooks = list(filter(lambda item: '.ipynb' in item, all_items))
344344
notebooks += config.get('extras', list())
345+
kernel = config.get('environment', config['course']).lower()
345346
images_to_copy = []
346347
data_urls_to_check = []
347348
click.secho('📔 Processing notebooks ', fg="cyan", nl=False)
348349
for notebook in notebooks:
349350
infile = pathlib.Path(KOSU['notebooks-source']) / notebook
350351
outfile = nb_path / notebook
351-
images, data_urls = process_notebook(infile, outfile)
352+
images, data_urls = process_notebook(infile, outfile, kernel=kernel)
352353
images_to_copy.extend(images)
353354
data_urls_to_check.extend(data_urls)
354355
shutil.copyfile(infile, m_path / notebook)
@@ -359,7 +360,7 @@ def build_notebooks(path, config):
359360
for notebook in notebooks:
360361
infile = pathlib.Path(KOSU['notebooks-source']) / notebook
361362
outfile = demo_path / notebook
362-
images, data_urls = process_notebook(infile, outfile, demo=True)
363+
images, data_urls = process_notebook(infile, outfile, demo=True, kernel=kernel)
363364
images_to_copy.extend(images)
364365
data_urls_to_check.extend(data_urls)
365366
shutil.copyfile(infile, m_path / notebook)

0 commit comments

Comments
 (0)