Commit 99b483d0 authored by Romain Casati's avatar Romain Casati
Browse files

Generating one notebook webapp for each language.

parent ace65753
all: build
dummy := $(shell pip3 install --upgrade basthon-kernel)
languages := $(shell python3 -m basthon-kernel --languages)
python3 clean --all
rm -rf notebook/static/basthon-kernel/ notebook/version notebook/static/*/js/main.min.js
rm -rf notebook/static/basthon-kernel/ notebook/version notebook/static/*/js/main*.min.js
echo $$(date -d @$$(git log -1 --format="%at") +%Y/%m/%d_%H:%M:%S)_kernel_$$(pip3 show basthon-kernel | grep Version | cut -f2 -d' ') > notebook/version
pip3 install --upgrade basthon-kernel
mkdir -p notebook/static/basthon-kernel/
cd notebook/static/basthon-kernel/ && python3 -m basthon-kernel --install && cd -
......@@ -17,7 +19,15 @@ install-kernel: _install-kernel version
build: clean install-kernel
python3 build
for f in version custom api/ kernelspecs/ examples/; do cp -r notebook/$$f build/lib/notebook/; done
python3 build/lib/notebook/index.html
mv build/lib/notebook/ build/lib/base/
mkdir build/lib/notebook/
for lang in $(languages); do \
rsync -a --delete build/lib/base/ build/lib/notebook/$$lang ; \
python3 $$lang build/lib/notebook/$$lang/index.html ; \
rsync -a build/lib/notebook/python3/ build/lib/notebook/
rsync -a build/lib/notebook/python3/ build/lib/notebook/python/
rsync -a build/lib/notebook/javascript/ build/lib/notebook/js/
tar --exclude="*.htaccess" -czf basthon-notebook.tgz -C build/lib/notebook/ .
......@@ -3,13 +3,24 @@ import time
import sys
language = sys.argv[1]
# diplayed language name
language_name = {'python3': 'Python 3',
'javascript': 'Javascript',
'sql': 'SQL'}.get(language, language)
output = sys.argv[2]
env = Environment(
index = env.get_template('index.template.html')
index = index.render(BASTHON_CACHE_BUSTING_TIMESTAMP=int(time.time()))
index = index.render(BASTHON_CACHE_BUSTING_TIMESTAMP=int(time.time()),
with open(sys.argv[1], 'w') as f:
with open(output, 'w') as f:
......@@ -553,7 +553,7 @@ dir="ltr">
<script src="static/components/text-encoding/lib/encoding.js?v={{BASTHON_CACHE_BUSTING_TIMESTAMP}}" charset="utf-8"></script>
<script src="static/notebook/js/main.min.js?v={{BASTHON_CACHE_BUSTING_TIMESTAMP}}" type="text/javascript" charset="utf-8"></script>
<script src="static/notebook/js/main-{{BASTHON_LANGUAGE}}.min.js?v={{BASTHON_CACHE_BUSTING_TIMESTAMP}}" type="text/javascript" charset="utf-8"></script>
\ No newline at end of file
......@@ -25,6 +25,9 @@ from fnmatch import fnmatch
from glob import glob
from concurrent.futures import ThreadPoolExecutor as ThreadPool
from subprocess import check_call
import subprocess
languages =['python3', '-m', 'basthon-kernel', '--languages'], capture_output=True).stdout.decode().split('\n')
if sys.platform == 'win32':
from subprocess import list2cmdline
......@@ -126,7 +129,12 @@ def find_package_data():
# for verification purposes, explicitly add main.min.js
# so that installation will fail if they are missing
for app in ['auth', 'edit', 'notebook', 'terminal', 'tree']:
static_data.append(pjoin('static', app, 'js', 'main.min.js'))
# [Basthon]
if app == 'notebook':
for lang in languages:
static_data.append(pjoin('static', app, 'js', f'main-{lang}.min.js'))
static_data.append(pjoin('static', app, 'js', 'main.min.js'))
components = pjoin("static", "components")
# select the components we actually need to install
......@@ -507,7 +515,14 @@ class CompileJS(Command):
self.force = bool(self.force)
apps = ['notebook', 'tree', 'edit', 'terminal', 'auth']
targets = [ pjoin(static, app, 'js', 'main.min.js') for app in apps ]
# [Basthon]
targets = []
for app in apps:
if app == 'notebook':
for lang in languages:
targets.append(pjoin(static, app, 'js', f'main-{lang}.min.js'))
targets.append(pjoin(static, app, 'js', 'main.min.js'))
def sources(self, name):
"""Generator yielding .js sources that an application depends on"""
......@@ -540,8 +555,22 @@ class CompileJS(Command):
return True
return False
def build_main_notebook(self, name):
""" Specific build_main for notebook (build with languages). """
for lang in languages:
target = pjoin(static, name, 'js', f'main-{lang}.min.js')
if not self.should_run(name, target):"%s up to date" % target)
return"Rebuilding %s" % target)
run(['node', 'tools/build-main.js', name, lang])
def build_main(self, name):
"""Build main.min.js"""
# [Basthon]
if name == 'notebook':
return self.build_main_notebook(name)
target = pjoin(static, name, 'js', 'main.min.js')
if not self.should_run(name, target):
......@@ -4,10 +4,12 @@
var rjs = require('requirejs').optimize;
var name = process.argv[2];
var language = process.argv[3];
var output = 'main' + (language ? `-${language}` : '') + '.min.js';
var rjs_config = {
name: name + '/js/main',
out: './notebook/static/' + name + '/js/main.min.js',
out: `./notebook/static/${name}/js/${output}`,
baseUrl: 'notebook/static',
preserveLicenseComments: false, // license comments conflict with sourcemap generation
generateSourceMaps: true,
......@@ -32,7 +34,7 @@ var rjs_config = {
bundles: { 'basthon-kernel/basthon_base': ['BasthonBase'],
'basthon-kernel/basthon_goodies': ['BasthonGoodies'],
'basthon-kernel/basthon_python': ['Basthon']},
[`basthon-kernel/basthon_${language}`]: ['Basthon']},
map: { // for backward compatibility
"*": {
"jqueryui": "jquery-ui",
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