Commit 0adca1a2 authored by Romain Casati's avatar Romain Casati
Browse files

Kernelspecs and Untitled.ipynb specifics to loaded language.

parent b7e0014c
......@@ -23,7 +23,7 @@ build: clean install-kernel
mkdir build/lib/notebook/
for lang in $(languages); do \
rsync -a --delete build/lib/base/ build/lib/notebook/$$lang ; \
python3 index_renderer.py $$lang build/lib/notebook/$$lang/index.html ; \
python3 basthon_renderer.py $$lang build/lib/notebook/$$lang/ ; \
done
rsync -a build/lib/notebook/python3/ build/lib/notebook/
rsync -a build/lib/notebook/python3/ build/lib/notebook/python/
......
from jinja2 import Environment, FileSystemLoader, select_autoescape
import time
import sys
from pathlib import Path
language = sys.argv[1]
......@@ -8,19 +9,37 @@ language = sys.argv[1]
language_name = {'python3': 'Python 3',
'javascript': 'Javascript',
'sql': 'SQL'}.get(language, language)
language_simple = language if language != 'python3' else 'python'
language_codemirror = language if language != 'python3' else 'ipython'
output = sys.argv[2]
output_dir = Path(sys.argv[2])
macros = {'BASTHON_CACHE_BUSTING_TIMESTAMP': int(time.time()),
'BASTHON_LANGUAGE': language,
'BASTHON_LANGUAGE_NAME': language_name,
'BASTHON_LANGUAGE_SIMPLE': language_simple,
'BASTHON_LANGUAGE_CODEMIRROR': language_codemirror}
# rendering index.html
env = Environment(
loader=FileSystemLoader('notebook'),
autoescape=select_autoescape(['html'])
)
index = env.get_template('index.template.html')
index = index.render(BASTHON_CACHE_BUSTING_TIMESTAMP=int(time.time()),
BASTHON_LANGUAGE=language,
BASTHON_LANGUAGE_NAME=language_name)
index = index.render(**macros)
with open(output, 'w') as f:
with open(output_dir / 'index.html', 'w') as f:
f.write(index)
# rendering Untitled.ipynb
env = Environment(
loader=FileSystemLoader('notebook/api/contents')
)
ipynb = env.get_template('Untitled.template.ipynb')
ipynb = ipynb.render(**macros)
with open(output_dir / 'api' / 'contents' / 'Untitled.ipynb', 'w') as f:
f.write(ipynb)
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"name": "Untitled.ipynb",
"path": "Untitled.ipynb"
}
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": []
}
],
"metadata": {
"kernelspec": {
"display_name": "{{BASTHON_LANGUAGE_NAME}}",
"language": "{{BASTHON_LANGUAGE_SIMPLE}}",
"name": "{{BASTHON_LANGUAGE}}"
},
"language_info": {
"codemirror_mode": {
"name": "{{BASTHON_LANGUAGE_CODEMIRROR}}",
"version": 3
},
"name": "{{BASTHON_LANGUAGE_SIMPLE}}",
"nbconvert_exporter": "{{BASTHON_LANGUAGE_SIMPLE}}"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"name": "Untitled.ipynb",
"path": "Untitled.ipynb"
}
{"default": "python3", "kernelspecs": {"python3": {"name": "python3", "spec": {"argv": ["/usr/bin/python3", "-m", "ipykernel_launcher", "-f", "{connection_file}"], "env": {}, "display_name": "Python 3", "language": "python", "interrupt_mode": "signal", "metadata": {}}, "resources": {"logo-64x64": "kernelspecs/python3/logo-64x64.png", "logo-32x32": "kernelspecs/python3/logo-32x32.png"}}}}
\ No newline at end of file
{
"default": "python3",
"kernelspecs": {
"python3": {
"name": "python3",
"spec": {"argv": ["/usr/bin/python3", "-m", "ipykernel_launcher", "-f", "{connection_file}"],
"env": {},
"display_name": "Python 3",
"language": "python",
"interrupt_mode": "signal",
"metadata": {}
},
"resources": {
"logo-64x64": "kernelspecs/python3/logo-64x64.png",
"logo-32x32": "kernelspecs/python3/logo-32x32.png"
}
},
"javascript": {
"name": "javascript",
"spec": {"argv": [],
"env": {},
"display_name": "Javascript",
"language": "javascript",
"interrupt_mode": "signal",
"metadata": {}
},
"resources": {
"logo-64x64": "kernelspecs/javascript/logo-64x64.png",
"logo-32x32": "kernelspecs/javascript/logo-32x32.png"
}
},
"sql": {
"name": "sql",
"spec": {"argv": [],
"env": {},
"display_name": "SQL",
"language": "sql",
"interrupt_mode": "signal",
"metadata": {}
},
"resources": {
"logo-64x64": "kernelspecs/sql/logo-64x64.png",
"logo-32x32": "kernelspecs/sql/logo-32x32.png"
}
}
}
}
{
"argv": [
"/usr/bin/nodejs",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Javascript",
"language": "javascipt"
}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 630 630">
<rect width="630" height="630" fill="#f7df1e"/>
<path d="m423.2 492.19c12.69 20.72 29.2 35.95 58.4 35.95 24.53 0 40.2-12.26 40.2-29.2 0-20.3-16.1-27.49-43.1-39.3l-14.8-6.35c-42.72-18.2-71.1-41-71.1-89.2 0-44.4 33.83-78.2 86.7-78.2 37.64 0 64.7 13.1 84.2 47.4l-46.1 29.6c-10.15-18.2-21.1-25.37-38.1-25.37-17.34 0-28.33 11-28.33 25.37 0 17.76 11 24.95 36.4 35.95l14.8 6.34c50.3 21.57 78.7 43.56 78.7 93 0 53.3-41.87 82.5-98.1 82.5-54.98 0-90.5-26.2-107.88-60.54zm-209.13 5.13c9.3 16.5 17.76 30.45 38.1 30.45 19.45 0 31.72-7.61 31.72-37.2v-201.3h59.2v202.1c0 61.3-35.94 89.2-88.4 89.2-47.4 0-74.85-24.53-88.81-54.075z"/>
</svg>
\ No newline at end of file
{
"argv": [
"/usr/bin/sql",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "SQL",
"language": "sql"
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="265"
height="265"
id="svg2985"
xml:space="preserve"
sodipodi:docname="logo.svg"
inkscape:version="1.0.2 (e86c870879, 2021-01-15)"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1366"
inkscape:window-height="704"
id="namedview16"
showgrid="false"
fit-margin-top="0"
fit-margin-left="5"
fit-margin-right="5"
fit-margin-bottom="0"
inkscape:zoom="0.83343169"
inkscape:cx="16.945278"
inkscape:cy="170.91006"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1"
inkscape:current-layer="svg2985" /><title
id="title2998">SQLite</title><metadata
id="metadata2991"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title>SQLite</dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs2989"><linearGradient
x1="0"
y1="0"
x2="1"
y2="0"
id="linearGradient3027"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-4.02e-6,-91.8907,-91.8907,4.02e-6,85.8809,161.434)"
spreadMethod="pad"><stop
id="stop3029"
style="stop-color:#97d9f6;stop-opacity:1"
offset="0" /><stop
id="stop3031"
style="stop-color:#0f80cc;stop-opacity:1"
offset="0.92024499" /><stop
id="stop3033"
style="stop-color:#0f80cc;stop-opacity:1"
offset="1" /></linearGradient><linearGradient
x1="-15.614694"
y1="-9.1082983"
x2="-6.7410073"
y2="-9.1082983"
id="linearGradient5421"
xlink:href="#linearGradient3027"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-4.02e-7,-9.18907,-9.18907,4.02e-7,8.58809,16.1434)"
spreadMethod="pad" /><linearGradient
x1="-15.614694"
y1="-9.1082983"
x2="-6.7410073"
y2="-9.1082983"
id="linearGradient2995"
xlink:href="#linearGradient3027"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-5.025e-7,11.486337,-11.486337,-5.025e-7,-30.839638,202.18698)"
spreadMethod="pad" /></defs><path
d="m 28.625,177.90533 c -4.8225,0 -8.74375,1.4275 -11.75,4.28125 -3.00625,2.85625 -4.53125,6.60014 -4.53125,11.18751 0,2.37738 0.37875,4.545 1.125,6.53125 0.74625,1.99025 1.9075,3.834 3.46875,5.5 1.56125,1.6675 4.68625,3.93263 9.34375,6.8125 5.715,3.48887 9.455,6.32037 11.25,8.53124 1.79625,2.209 2.6875,4.524 2.6875,6.9375 0,3.2315 -1.06375,5.811 -3.25,7.75 -2.19,1.93988 -5.11875,2.90625 -8.75,2.90625 -3.83,0 -7.16625,-1.35012 -10.03125,-4.03125 -2.865,-2.685 -4.31125,-6.23637 -4.34375,-10.6875 H 12.0625 v 16.15625 h 1.78125 c 0.54375,-1.52988 1.29625,-2.3125 2.28125,-2.3125 0.47375,0 1.58375,0.32675 3.3125,0.9375 4.20625,1.49662 7.66,2.21875 10.375,2.21875 4.67875,0 8.6725,-1.63862 11.999999,-4.96875 3.3225,-3.32862 5,-7.34375 5,-12.03125 0,-3.63475 -1.1075,-6.86863 -3.28125,-9.68749 -2.173749,-2.82225 -6.401249,-6.10501 -12.718749,-9.875 -5.43625,-3.26614 -8.965,-5.92625 -10.59375,-8 -1.63125,-2.07076 -2.46875,-4.36137 -2.46875,-6.875 0,-2.71876 0.99875,-4.90251 2.96875,-6.53126 1.97,-1.63 4.55125,-2.4375 7.78125,-2.4375 3.635,0 6.665,1.07875 9.0625,3.25 2.395,2.175 3.78,5.189 4.187499,9.06251 h 1.78125 v -14.00001 h -1.65625 c -0.2025,0.71375 -0.389999,1.17 -0.562499,1.375 -0.1675,0.20375 -0.49,0.3125 -0.96875,0.3125 -0.57625,0 -1.60375,-0.2425 -3.0625,-0.71875 -3.125,-1.0525 -6.00625,-1.59375 -8.65625,-1.59375 z m 58.218749,0 c -5.87625,0 -11.21125,1.385 -16.03125,4.15625 -4.8275,2.76625 -8.64875,6.6075 -11.46875,11.50001 -2.81875,4.89212 -4.21875,10.08786 -4.21875,15.625 0,7.43899 2.435,14.06636 7.34375,19.87499 4.91125,5.80513 10.79625,9.42238 17.625,10.8125 1.56125,0.8135 3.795,2.9135 6.71875,6.3125 3.295,3.83587 6.0825,6.6025 8.375,8.25 2.29,1.64837 4.7625,2.8565 7.375001,3.65625 2.615,0.79638 5.4425,1.1875 8.5,1.1875 3.7025,0 7.0175,-0.6435 9.9375,-1.96875 l -0.65625,-1.625 c -1.695,0.61138 -3.5025,0.90625 -5.40625,0.90625 -2.58375,0 -5.195,-0.852 -7.8125,-2.5625 -2.61375,-1.71475 -5.8825,-4.98637 -9.781251,-9.8125 -1.8325,-2.3125 -3.0975,-3.7715 -3.8125,-4.34375 7.471251,-1.459 13.615001,-5.08 18.406251,-10.875 4.79,-5.7925 7.1875,-12.40336 7.1875,-19.81249 0,-8.79739 -3.13,-16.19088 -9.34375,-22.21876 -6.21875,-6.0285 -13.866251,-9.0625 -22.937501,-9.0625 z m 36.343751,0 0.0937,1.90625 c 3.9125,0 6.10375,1.1525 6.59375,3.46875 0.1825,0.82875 0.26625,2.359 0.28125,4.5625 l -0.0312,42.15625 c -0.0325,3.1485 -0.48125,5.15875 -1.34375,6.03125 -0.86375,0.86625 -2.32375,1.40875 -4.4375,1.625 l -0.0937,1.90625 h 39 l 1,-9.5625 h -1.78125 c -0.50875,2.605 -1.675,4.47113 -3.53125,5.53125 -1.86125,1.06787 -5.1525,1.59375 -9.90625,1.59375 h -3.6875 c -4.2775,0 -6.7525,-1.54638 -7.40625,-4.65625 -0.135,-0.61525 -0.18125,-1.27488 -0.1875,-2 l 0.15625,-42.625 c -10e-4,-3.1435 0.39625,-5.25 1.21875,-6.28125 0.83125,-1.0275 2.33,-1.6025 4.5,-1.75 l -0.0937,-1.90625 H 123.1876 Z m -35.718751,2.3125 c 6.6275,0 12.03875,2.61025 16.218751,7.875 4.17875,5.26664 6.25,12.48488 6.25,21.62501 0,8.66111 -2.10125,15.59612 -6.3125,20.81249 -4.211251,5.21475 -9.816251,7.8125 -16.781251,7.8125 -6.69125,0 -12.1175,-2.67875 -16.28125,-8.0625 -4.16,-5.38375 -6.21875,-12.3735 -6.21875,-20.96874 0,-8.8325 2.08375,-15.90288 6.28125,-21.18751 4.195,-5.279 9.8125,-7.90625 16.84375,-7.90625 z m 89.687501,9.06251 c -0.95125,0 -1.67625,0.32125 -2.21875,0.96875 -0.555,0.64499 -0.725,1.42624 -0.53125,2.375 0.1875,0.92037 0.70625,1.727 1.53125,2.40625 0.82,0.67861 1.705,1.03125 2.65625,1.03125 0.92,0 1.62125,-0.35262 2.125,-1.03125 0.50375,-0.67925 0.6575,-1.48588 0.46875,-2.40625 -0.19375,-0.94876 -0.695,-1.73001 -1.46875,-2.375 -0.7825,-0.6475 -1.6425,-0.96875 -2.5625,-0.96875 z m 25.71875,6.46875 c -1.61625,6.21774 -5.12,9.58249 -10.5,10.125 l 0.0625,1.78125 h 6.28125 l -0.125,21.06249 c 0.01,3.601 0.12,5.9985 0.375,7.21875 0.61875,2.92138 2.52625,4.40625 5.71875,4.40625 4.61875,0 9.46375,-2.8135 14.53125,-8.4375 l -1.53125,-1.3125 c -3.65875,3.70363 -6.89375,5.5625 -9.71875,5.5625 -1.73625,0 -2.8125,-0.9985 -3.21875,-2.96875 -0.11125,-0.4785 -0.15625,-1.03762 -0.15625,-1.6875 l 0.0625,-23.84374 H 214.25 l -0.0937,-2.84375 h -9.46875 v -9.0625 h -1.8125 z m 37.09375,7.9375 c -5.36625,0 -9.73125,2.605 -13.125,7.78125 -3.37625,5.185 -4.42125,10.92961 -3.09375,17.24999 0.78125,3.70212 2.3375,6.57138 4.71875,8.59375 2.3775,2.0215 5.39375,3.03125 9,3.03125 3.3575,0 8.0325,-0.85012 10,-2.5625 1.9725,-1.71138 3.79,-4.48388 5.46875,-8.28125 l -1.34375,-1.40625 c -2.6775,4.92625 -8.08125,7.40625 -12.15625,7.40625 -5.6025,0 -9.03375,-3.07375 -10.3125,-9.1875 -0.16625,-0.78038 -0.29,-1.61875 -0.375,-2.5 6.665,-1.05525 11.71625,-2.92388 15.125,-5.625 3.40625,-2.70261 6.82625,-5.56737 6.1875,-8.59374 -0.38,-1.79838 -1.31375,-3.21238 -2.75,-4.28125 -1.455,-1.06837 -5.2325,-1.625 -7.34375,-1.625 z m -58.65625,0.21875 -11.5625,2.65625 v 2.0625 l 4,-0.5 c 1.9375,0 3.0775,0.87738 3.4375,2.625 0.12125,0.58488 0.1975,1.40625 0.21875,2.4375 l -0.125,18.90624 c -0.0325,2.61625 -0.3225,4.13712 -0.90625,4.59375 -0.58875,0.4575 -2.14125,0.6875 -4.65625,0.6875 l -0.0625,1.78125 H 190 l -0.0312,-1.78125 c -2.54875,0 -4.20125,-0.20112 -4.9375,-0.59375 -0.72375,-0.39012 -1.2225,-1.10012 -1.4375,-2.1875 -0.16625,-0.78363 -0.23875,-2.13387 -0.25,-4 l 0.0625,-26.68749 h -2.09375 z m 55.71875,3.5 c 1.11625,0 2.195,0.43112 3.28125,1.28125 1.07125,0.84713 1.72375,1.78912 1.9375,2.8125 1.04625,5.02638 -3.41,8.50136 -13.4375,10.43749 -0.28625,-3.66512 0.34875,-6.99224 1.96875,-9.99999 1.6075,-3.00488 3.70125,-4.53125 6.25,-4.53125 z"
id="SQLite"
style="fill:#003b57;fill-opacity:1;fill-rule:nonzero;stroke:none" /><g
id="g844"
transform="translate(51.603772,-4.000002)"><path
d="M 121.6315,17.03623 H 22.1255 C 15.4565,17.03623 10,22.49373 10,29.16248 v 109.7365 c 0,6.66837 5.4565,12.125 12.1255,12.125 H 87.66275 C 86.918884,118.41477 98.054499,55.130402 121.6315,17.03623 Z"
id="solid-background"
style="fill:#0f80cc;fill-opacity:1;fill-rule:nonzero;stroke:none" /><path
d="m 118.0165,20.57373 h -95.891 c -4.735375,0 -8.588875,3.8525 -8.588875,8.58875 v 101.73013 c 21.71725,-8.335 54.31221,-15.5269 76.849585,-15.20027 4.52893,-23.680901 17.83941,-70.090424 27.63029,-95.11861 z"
id="gradient-background"
style="fill:url(#linearGradient2995);fill-opacity:1;fill-rule:nonzero;stroke:none" /><path
d="m 144.8415,13.44498 c -6.815,-6.0775 -15.06625,-3.63625 -23.21,3.59125 -1.20875,1.07375 -2.415,2.265 -3.615,3.5375 -13.93125,14.77875 -26.8625,42.15375 -30.88,63.06 1.565,3.17375 2.7875,7.22375 3.5925,10.3175 0.20625,0.79375 0.3925,1.53875 0.54125,2.1725 0.35375,1.499875 0.54375,2.4725 0.54375,2.4725 0,0 -0.125,-0.472625 -0.6375,-1.95875 -0.0975,-0.285 -0.20625,-0.59625 -0.335,-0.9625 -0.055,-0.15125 -0.13125,-0.335 -0.215,-0.53125 -0.90875,-2.1125 -3.4225,-6.57125 -4.52875,-8.5125 -0.94625,2.79125 -1.7825,5.4025 -2.4825,7.765 3.19375,5.8435 5.14,15.85775 5.14,15.85775 0,0 -0.16875,-0.649 -0.97125,-2.91412 -0.7125,-2.00338 -4.26125,-8.22113 -5.101875,-9.674755 -1.438,5.308505 -2.009375,8.892505 -1.494125,9.765125 1.000375,1.69088 1.953125,4.60838 2.78975,7.83488 1.89,7.26862 3.20375,16.11725 3.20375,16.11725 0,0 0.0425,0.58637 0.11375,1.48875 -0.2625,6.104 -0.105,12.43262 0.3675,18.15287 0.62625,7.57225 1.805,14.07713 3.3075,17.5585 l 1.02,-0.55612 c -2.20625,-6.85888 -3.1025,-15.84763 -2.71,-26.21388 0.59375,-15.84512 4.24,-34.95362 10.9775,-54.87 11.3825,-30.065 27.175,-54.1875 41.62875,-65.7075 -13.17375,11.8975 -31.00375,50.40875 -36.34125,64.67 -5.97625,15.97 -10.21125,30.95638 -12.76375,45.31475 4.40375,-13.46087 18.6425,-19.247 18.6425,-19.247 0,0 6.98375,-8.61287 15.145,-20.91775 -4.88875,1.115 -12.91625,3.02375 -15.605,4.15375 -3.96625,1.66375 -5.035,2.23125 -5.035,2.23125 0,0 12.8475,-7.82375 23.87,-11.36625 15.15875,-23.875 31.67375,-57.7925 15.0425,-72.62875"
id="feather"
style="fill:#003b57;fill-opacity:1;fill-rule:nonzero;stroke:none" /></g></svg>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment