From 59de8d4a6dd53126989d0675c7072bef90476969 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Fri, 14 Sep 2018 16:58:02 +0200 Subject: [PATCH] Expose version information in javascript --- .circleci/deploy.sh | 2 +- Makefile | 3 ++- src/main.c | 2 +- src/runpython.c | 9 +++++++++ src/runpython.h | 3 +++ test/test_python.py | 17 ++++++++++++++++- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.circleci/deploy.sh b/.circleci/deploy.sh index a541007c7..06bf44f6c 100755 --- a/.circleci/deploy.sh +++ b/.circleci/deploy.sh @@ -8,7 +8,7 @@ git add * git config --global user.email "deploybot@nowhere.com" git config --global user.name "Deploybot" git commit -m << END -Deployed from Circle-CI $CIRCLE_BUILD_NUM" +Deployed from Circle-CI $CIRCLE_BUILD_NUM Version $(git describe --tags --always) END diff --git a/Makefile b/Makefile index 7274f4df0..5ffd2f2ca 100644 --- a/Makefile +++ b/Makefile @@ -162,7 +162,8 @@ root/.built: \ cp src/pyodide.py root/lib/python$(PYMINOR)/site-packages if command -v git > /dev/null 2>&1 \ && git describe --tags > /dev/null 2>&1; then \ - sed -i "s/__version__ =.*/__version__ = '$(shell git describe --tags)'/g" root/lib/python$(PYMINOR)/site-packages/pyodide.py; \ + sed -i "s/__version__ =.*/__version__ = '$(shell git describe --tags)'/g" \ + root/lib/python$(PYMINOR)/site-packages/pyodide.py; \ fi ( \ cd root/lib/python$(PYMINOR); \ diff --git a/src/main.c b/src/main.c index 9a3327826..a418c2cd7 100644 --- a/src/main.c +++ b/src/main.c @@ -48,7 +48,7 @@ main(int argc, char** argv) if (js2python_init() || JsImport_init() || JsProxy_init() || pyimport_init() || pyproxy_init() || python2js_init() || - runpython_init_js() || runpython_init_py()) { + runpython_init_js() || runpython_init_py() || runpython_finalize_js()) { return 1; } diff --git a/src/runpython.c b/src/runpython.c index 9594775c5..269f86c40 100644 --- a/src/runpython.c +++ b/src/runpython.c @@ -68,3 +68,12 @@ runpython_init_py() Py_DECREF(d); return 0; } + +EM_JS(int, runpython_finalize_js, (), { + Module.version = function() + { + Module.runPython("import pyodide"); + return Module.runPython("pyodide.__version__"); + }; + return 0; +}); diff --git a/src/runpython.h b/src/runpython.h index 344dd35fd..0d2ae6e8a 100644 --- a/src/runpython.h +++ b/src/runpython.h @@ -10,4 +10,7 @@ runpython_init_js(); int runpython_init_py(); +int +runpython_finalize_js(); + #endif /* RUNPYTHON_H */ diff --git a/test/test_python.py b/test/test_python.py index aa87a0623..90ab9f8b3 100644 --- a/test/test_python.py +++ b/test/test_python.py @@ -2,7 +2,6 @@ import os from pathlib import Path import time - import pytest @@ -391,3 +390,19 @@ def test_load_package_after_convert_string(selenium): selenium.load_package('kiwisolver') selenium.run( "import kiwisolver") + + +def test_version_info(selenium): + from distutils.version import LooseVersion + + version_py_str = selenium.run(""" + import pyodide + + pyodide.__version__ + """) + version_py = LooseVersion(version_py_str) + assert version_py > LooseVersion('0.0.1') + + version_js_str = selenium.run_js("return pyodide.version()") + version_js = LooseVersion(version_js_str) + assert version_py == version_js