From d239839e074758f924fcbf30db9f8b08c09c9fda Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Sat, 15 Sep 2018 22:01:20 +0200 Subject: [PATCH 1/4] Build js translation at build time. Make sure they are included in sdist/wheel. --- .travis.yml | 2 +- package.json | 3 ++- setup.py | 2 ++ setupbase.py | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e16c5a8d4..34a11f29c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ before_install: - node --version - npm --version - npm upgrade -g npm - - npm install + - npm install -g po2json@0.4.5 - | if [[ $GROUP == js* ]]; then npm install -g casperjs@1.1.3 phantomjs-prebuilt@2.1.7 diff --git a/package.json b/package.json index 1cf8a1848..062978e8a 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "devDependencies": { "bower": "*", "less": "~2", - "requirejs": "^2.1.17" + "requirejs": "^2.1.17", + "po2json": "^0.4.5" }, "dependencies": {} } diff --git a/setup.py b/setup.py index 6d60391db..b58e847f2 100755 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ from setupbase import ( check_package_data_first, CompileCSS, CompileJS, + CompileBackendTranslation, Bower, JavascriptVersion, css_js_prerelease, @@ -131,6 +132,7 @@ setup_args['cmdclass'] = { 'sdist' : css_js_prerelease(sdist, strict=True), 'develop': css_js_prerelease(develop), 'css' : CompileCSS, + 'backendtranslations': CompileBackendTranslation, 'js' : CompileJS, 'jsdeps' : Bower, 'jsversion' : JavascriptVersion, diff --git a/setupbase.py b/setupbase.py index d362eadc0..5ef888d2c 100644 --- a/setupbase.py +++ b/setupbase.py @@ -337,6 +337,30 @@ def run(cmd, *args, **kwargs): kwargs['shell'] = (sys.platform == 'win32') return check_call(cmd, *args, **kwargs) +class CompileBackendTranslation(Command): + description = "compile the .po files into .mo files, that contain the translations." + + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + + def run(self): + paths = glob('notebook/i18n/??_??') + for p in paths: + LANG = p.split('/')[-1] + for component in ['notebook', 'nbui']: + run(['pybabel', 'compile', + '-D', component, + '-f', + '-l', LANG, + '-i', pjoin('notebook', 'i18n', LANG, 'LC_MESSAGES', component+'.po'), + '-o', pjoin('notebook', 'i18n', LANG, 'LC_MESSAGES', component+'.mo') + ]) class Bower(Command): description = "fetch static client-side components with bower" @@ -467,7 +491,7 @@ class CompileCSS(Command): class CompileJS(Command): - """Rebuild Notebook Javascript main.min.js files + """Rebuild Notebook Javascript main.min.js files and translation files. Calls require via build-main.js """ @@ -526,12 +550,22 @@ class CompileJS(Command): log.info("Rebuilding %s" % target) run(['node', 'tools/build-main.js', name]) + def build_jstranslation(self, trd): + lang = trd.split('/')[2] + run(['po2json', '-p', '-F', + '-f', 'jed1.x', + '-d', 'nbjs', + pjoin('notebook', 'i18n', lang ,'LC_MESSAGES', 'nbjs.po'), + pjoin('notebook', 'i18n', lang, 'LC_MESSAGES', 'nbjs.json') + ]) + def run(self): self.run_command('jsdeps') env = os.environ.copy() env['PATH'] = npm_path pool = ThreadPool() pool.map(self.build_main, self.apps) + pool.map(self.build_jstranslation, glob('notebook/i18n/??_??')) # update package data in case this created new files update_package_data(self.distribution) @@ -586,6 +620,7 @@ def css_js_prerelease(command, strict=False): try: self.distribution.run_command('js') self.distribution.run_command('css') + self.distribution.run_command('backendtranslations') except Exception as e: # refresh missing missing = [ t for t in targets if not os.path.exists(t) ] From 07126ca8a5ab58ae015f3828737fc263ea7ab9a5 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Sun, 16 Sep 2018 18:12:41 +0200 Subject: [PATCH 2/4] one more try --- setupbase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setupbase.py b/setupbase.py index 5ef888d2c..972ed24d6 100644 --- a/setupbase.py +++ b/setupbase.py @@ -352,7 +352,7 @@ class CompileBackendTranslation(Command): def run(self): paths = glob('notebook/i18n/??_??') for p in paths: - LANG = p.split('/')[-1] + LANG = p[-5:] for component in ['notebook', 'nbui']: run(['pybabel', 'compile', '-D', component, @@ -551,7 +551,7 @@ class CompileJS(Command): run(['node', 'tools/build-main.js', name]) def build_jstranslation(self, trd): - lang = trd.split('/')[2] + lang = trd[-5:] run(['po2json', '-p', '-F', '-f', 'jed1.x', '-d', 'nbjs', From 52ca0d64caba1c9e579d52bc03bc2a65b18beee7 Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 17 Sep 2018 10:05:11 +0200 Subject: [PATCH 3/4] fix installation, invocation of po2json - no global installation - invoke with node --- .travis.yml | 2 +- setupbase.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34a11f29c..e16c5a8d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ before_install: - node --version - npm --version - npm upgrade -g npm - - npm install -g po2json@0.4.5 + - npm install - | if [[ $GROUP == js* ]]; then npm install -g casperjs@1.1.3 phantomjs-prebuilt@2.1.7 diff --git a/setupbase.py b/setupbase.py index 972ed24d6..1b1549c54 100644 --- a/setupbase.py +++ b/setupbase.py @@ -539,11 +539,11 @@ class CompileJS(Command): print(source, target) return True return False - + def build_main(self, name): """Build main.min.js""" target = pjoin(static, name, 'js', 'main.min.js') - + if not self.should_run(name, target): log.info("%s up to date" % target) return @@ -552,12 +552,14 @@ class CompileJS(Command): def build_jstranslation(self, trd): lang = trd[-5:] - run(['po2json', '-p', '-F', - '-f', 'jed1.x', - '-d', 'nbjs', - pjoin('notebook', 'i18n', lang ,'LC_MESSAGES', 'nbjs.po'), - pjoin('notebook', 'i18n', lang, 'LC_MESSAGES', 'nbjs.json') - ]) + run([ + pjoin('node_modules', '.bin', 'po2json'), + '-p', '-F', + '-f', 'jed1.x', + '-d', 'nbjs', + pjoin('notebook', 'i18n', lang, 'LC_MESSAGES', 'nbjs.po'), + pjoin('notebook', 'i18n', lang, 'LC_MESSAGES', 'nbjs.json'), + ]) def run(self): self.run_command('jsdeps') From e78f438e5aefd3d344ce6a95cac983a60edbcc9f Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 17 Sep 2018 10:34:48 +0200 Subject: [PATCH 4/4] invoke setup.py build on appveyor for better output --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index c513c6f83..3f58159ad 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,6 +20,7 @@ install: - cmd: conda config --add channels conda-forge #- cmd: conda update --yes --quiet conda - cmd: conda install -y pyzmq tornado jupyter_client nbformat nbconvert ipykernel pip nodejs nose + - cmd: python setup.py build - cmd: pip install .[test] test_script: