From c36a044a03cba4c5c27943651ee524c9da9ab504 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Fri, 14 Sep 2018 14:30:17 +0200 Subject: [PATCH 1/3] Store version information in src/pyodide.py --- Makefile | 4 ++++ src/pyodide.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 6d6eff5ec..7274f4df0 100644 --- a/Makefile +++ b/Makefile @@ -160,6 +160,10 @@ root/.built: \ cp src/_testcapi.py root/lib/python$(PYMINOR) cp src/pystone.py root/lib/python$(PYMINOR) 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; \ + fi ( \ cd root/lib/python$(PYMINOR); \ rm -fr `cat ../../../remove_modules.txt`; \ diff --git a/src/pyodide.py b/src/pyodide.py index d1635f63e..099d9487c 100644 --- a/src/pyodide.py +++ b/src/pyodide.py @@ -7,6 +7,8 @@ from js import XMLHttpRequest import ast import io +__version__ = '0.1.0' + def open_url(url): """ From d574047a4d051d090ebef6bb4c3778706a6f1341 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Fri, 14 Sep 2018 14:47:54 +0200 Subject: [PATCH 2/3] Tag commits deployed on Circle CI and store artefacts in build --- .circleci/config.yml | 6 +++--- .circleci/deploy.sh | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index efbf0bb75..73ffd7575 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -77,6 +77,9 @@ jobs: - ./pyodide-env - ./firefox + - store_artifacts: + path: /home/circleci/repo/build/ + test-firefox: <<: *defaults steps: @@ -111,9 +114,6 @@ jobs: export PATH=$PWD/firefox:$PATH pytest test -v -k chrome - - store_artifacts: - path: /home/circleci/repo/build/ - deploy: machine: enabled: true diff --git a/.circleci/deploy.sh b/.circleci/deploy.sh index 0596ae6c4..a541007c7 100755 --- a/.circleci/deploy.sh +++ b/.circleci/deploy.sh @@ -7,7 +7,11 @@ git checkout --orphan tmp git add * git config --global user.email "deploybot@nowhere.com" git config --global user.name "Deploybot" -git commit -m "Deployed from Circle-CI $CIRCLE_BUILD_NUM" +git commit -m << END +Deployed from Circle-CI $CIRCLE_BUILD_NUM" + +Version $(git describe --tags --always) +END git checkout master git reset --hard tmp git push origin -f master From 59de8d4a6dd53126989d0675c7072bef90476969 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Fri, 14 Sep 2018 16:58:02 +0200 Subject: [PATCH 3/3] 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