From 6b5ecdc7e1ce57ff355d1c5620e6e0cd414c81b9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 May 2016 20:17:36 +0530 Subject: [PATCH] Add the mathjax version to the compiled js --- .gitignore | 1 + setup/install.py | 2 +- setup/mathjax.py | 2 ++ src/calibre/utils/rapydscript.py | 10 ++++++++-- src/pyj/read_book/ui.pyj | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 4f363562c9..62017e5d57 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ resources/user-manual-translation-stats.json resources/content-server/index-generated.html resources/content-server/locales.zip resources/content-server/mathjax.zip.xz +resources/content-server/mathjax.version resources/mozilla-ca-certs.pem icons/icns/*.iconset setup/installer/windows/calibre/build.log diff --git a/setup/install.py b/setup/install.py index 6f197bcc76..16011453cc 100644 --- a/setup/install.py +++ b/setup/install.py @@ -327,7 +327,7 @@ class Bootstrap(Command): description = 'Bootstrap a fresh checkout of calibre from git to a state where it can be installed. Requires various development tools/libraries/headers' TRANSLATIONS_REPO = 'https://github.com/kovidgoyal/calibre-translations.git' - sub_commands = 'cacerts build iso639 iso3166 translations gui resources mathjax'.split() + sub_commands = 'cacerts build iso639 iso3166 translations gui mathjax resources'.split() def pre_sub_commands(self, opts): tdir = self.j(self.d(self.SRC), 'translations') diff --git a/setup/mathjax.py b/setup/mathjax.py index 3c2350d169..0de5119a42 100644 --- a/setup/mathjax.py +++ b/setup/mathjax.py @@ -82,3 +82,5 @@ class MathJax(Command): t.seek(0) with open(self.j(self.RESOURCES, 'content-server', 'mathjax.zip.xz'), 'wb') as f: compress(t, f, level=9) + with open(self.j(self.RESOURCES, 'content-server', 'mathjax.version'), 'wb') as f: + f.write(zf.comment) diff --git a/src/calibre/utils/rapydscript.py b/src/calibre/utils/rapydscript.py index 040b36f3af..799dd18006 100644 --- a/src/calibre/utils/rapydscript.py +++ b/src/calibre/utils/rapydscript.py @@ -110,10 +110,16 @@ def compile_srv(): rb = os.path.join(base, 'src', 'calibre', 'srv', 'render_book.py') with lopen(rb, 'rb') as f: rv = str(int(re.search(br'^RENDER_VERSION\s+=\s+(\d+)', f.read(), re.M).group(1))) + try: + mathjax_version = P('content-server/mathjax.version', data=True, allow_user_override=False).decode('utf-8') + except EnvironmentError as e: + if e.errno != errno.ENOENT: + raise + mathjax_version = '0' base = P('content-server', allow_user_override=False) fname = os.path.join(rapydscript_dir, 'srv.pyj') with lopen(fname, 'rb') as f: - js = compile_pyj(f.read(), fname).replace('__RENDER_VERSION__', rv).encode('utf-8') + js = compile_pyj(f.read(), fname).replace('__RENDER_VERSION__', rv).replace('__MATHJAX_VERSION__', mathjax_version).encode('utf-8') with lopen(os.path.join(base, 'index.html'), 'rb') as f: html = f.read().replace(b'RESET_STYLES', reset, 1).replace(b'ICONS', icons, 1).replace(b'MAIN_JS', js, 1) with lopen(os.path.join(base, 'index-generated.html'), 'wb') as f: @@ -311,7 +317,7 @@ def main(args=sys.argv): description='RapydScript compiler and REPL. If passed input on stdin, it is compiled and written to stdout. Otherwise a REPL is started.') parser.add_argument('--version', action='version', version='Using RapydScript compiler version: '+ver) - parser.add_argument('--show-js', action='store_true', help='Have the REPL output compiled javascript before executing it') + parser.add_argument('--show-js', action='store_true', help='Have the REPL output the compiled javascript before executing it') parser.add_argument('--libdir', help='Where to look for imported modules') parser.add_argument('--omit-baselib', action='store_true', default=False, help='Omit the RapydScript base library') parser.add_argument('--no-private-scope', action='store_true', default=False, help='Do not wrap the output in its own private scope') diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index 6865518f27..432edc826e 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -14,6 +14,7 @@ from read_book.db import create_db from read_book.view import View RENDER_VERSION = __RENDER_VERSION__ +MATHJAX_VERSION = "__MATHJAX_VERSION__" class ReadUI: