From 47852f457e415bcfa338c6de686f4d6962f75a52 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 11:47:36 +0200 Subject: [PATCH 1/9] added time mock --- include/pyjs/pre_js/init.js | 25 ++++++++++++++++--------- tests/tests/test_pyjs.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/pyjs/pre_js/init.js b/include/pyjs/pre_js/init.js index 13948c2..96f530e 100644 --- a/include/pyjs/pre_js/init.js +++ b/include/pyjs/pre_js/init.js @@ -176,15 +176,22 @@ _add_resolve_done_callback Module._is_initialized = true -// Module.exec(` -// import sys -// import sysconfig -// side_path = "${side_path}" -// from pathlib import Path -// Path(side_path).mkdir(parents=True, exist_ok=True) -// if True and side_path not in sys.path: -// sys.path.append(side_path) -// `) + // make sure time.sleep is working + Module.exec(` +import time +def _mock_time_sleep(): + def sleep(seconds): + """Delay execution for a given number of seconds. The argument may be + a floating point number for subsecond precision. + """ + start = now = time.time() + while now - start < seconds: + now = time.time() + + time.sleep = sleep +_mock_time_sleep() +del _mock_time_sleep +`) return p diff --git a/tests/tests/test_pyjs.py b/tests/tests/test_pyjs.py index 66b90aa..faa0df9 100644 --- a/tests/tests/test_pyjs.py +++ b/tests/tests/test_pyjs.py @@ -554,3 +554,17 @@ def test_int_container(): js_obj = jsf() py_obj = pyjs.to_py(js_obj) assert py_obj + + + +def test_sleep(): + import time + start = time.time() + time.sleep(2) + end = time.time() + + assert end - start >= 2 + + # probably we can also do more precise tests + # but lets keept it simple for now + assert end - start < 2.1 \ No newline at end of file From afbd1ffc4611f8cdf4fabf959a0f50b1c716947f Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 12:01:34 +0200 Subject: [PATCH 2/9] fixing ci --- .github/workflows/main.yml | 3 --- environment-dev.yml | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index faff507..eb83fba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,9 +48,6 @@ jobs: run: | micromamba activate pyjs-wasm - python -m pip install git+https://github.com/emscripten-forge/empack@rootpack --no-deps --ignore-installed - python -m pip install git+https://github.com/DerThorsten/pyjs-code-runner@relocate_env --no-deps --ignore-installed - emsdk activate ${{matrix.emsdk_ver}} source $CONDA_EMSDK_DIR/emsdk_env.sh diff --git a/environment-dev.yml b/environment-dev.yml index 4c5f69f..f035c59 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -8,8 +8,8 @@ dependencies: - yarn - click - emsdk >=3.1.11 - - empack >=1.1.0 + - empack >=3.0.1 - microsoft::playwright - ninja - nodejs >= 18.7.0 - - pyjs_code_runner == 1.1.0 \ No newline at end of file + - pyjs_code_runner >= 2.0.1 \ No newline at end of file From 9701033247ee290a728620a1d7479e85ff9964bc Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 12:17:02 +0200 Subject: [PATCH 3/9] added exceptiongroup backport --- environment-dev.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/environment-dev.yml b/environment-dev.yml index f035c59..095ef3d 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -12,4 +12,5 @@ dependencies: - microsoft::playwright - ninja - nodejs >= 18.7.0 - - pyjs_code_runner >= 2.0.1 \ No newline at end of file + - pyjs_code_runner >= 2.0.1 + - exceptiongroup \ No newline at end of file From 7bb1d7ec45b3def66c42645b1c68105002ff76a0 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 12:20:10 +0200 Subject: [PATCH 4/9] remove emsdk --- .github/workflows/main.yml | 5 ----- environment-dev.yml | 1 - 2 files changed, 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eb83fba..0fb2c82 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,11 +39,6 @@ jobs: run: | playwright install - - name: Setup emsdk - run: | - micromamba activate pyjs-wasm - emsdk install ${{matrix.emsdk_ver}} - - name: Build pyjs run: | micromamba activate pyjs-wasm diff --git a/environment-dev.yml b/environment-dev.yml index 095ef3d..e66a827 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -7,7 +7,6 @@ dependencies: - python=3.10 - yarn - click - - emsdk >=3.1.11 - empack >=3.0.1 - microsoft::playwright - ninja From be937e4131848d3f23ad436e60326285d5d1b74a Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 12:24:48 +0200 Subject: [PATCH 5/9] re-adding emsdk --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0fb2c82..eb83fba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,6 +39,11 @@ jobs: run: | playwright install + - name: Setup emsdk + run: | + micromamba activate pyjs-wasm + emsdk install ${{matrix.emsdk_ver}} + - name: Build pyjs run: | micromamba activate pyjs-wasm From db120839adb30dce8b7ed9aa335659680dd3b5cb Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 12:32:32 +0200 Subject: [PATCH 6/9] re-adding emsdk --- environment-dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment-dev.yml b/environment-dev.yml index e66a827..a73c37b 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -8,6 +8,7 @@ dependencies: - yarn - click - empack >=3.0.1 + - emsdk >=3.1.11 - microsoft::playwright - ninja - nodejs >= 18.7.0 From 267b8b5457aed744049c4465060273df6ee2fa21 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 13:06:38 +0200 Subject: [PATCH 7/9] re-adding emsdk --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eb83fba..51a58cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,7 +56,7 @@ jobs: -c https://repo.mamba.pm/emscripten-forge \ -c https://repo.mamba.pm/conda-forge \ --yes \ - python pybind11 nlohmann_json pybind11_json numpy pytest bzip2 sqlite zlib libffi + python pybind11 nlohmann_json pybind11_json numpy pytest bzip2 sqlite zlib libffi exceptiongroup mkdir build @@ -91,7 +91,7 @@ jobs: -c https://repo.mamba.pm/emscripten-forge \ -c https://repo.mamba.pm/conda-forge \ --yes \ - python pytest numpy + python pytest numpy exceptiongroup - name: Test in browser-main @@ -130,7 +130,7 @@ jobs: -c https://repo.mamba.pm/emscripten-forge \ -c https://repo.mamba.pm/conda-forge \ --yes \ - python pytest + python pytest exceptiongroup - name: Test in browser-main-no-numpy run: | From 54ffc801f17d6c185f9f8941f2a26a7671824eee Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 13:58:22 +0200 Subject: [PATCH 8/9] donwgrading pytest --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 51a58cb..fd3a26b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,7 +56,7 @@ jobs: -c https://repo.mamba.pm/emscripten-forge \ -c https://repo.mamba.pm/conda-forge \ --yes \ - python pybind11 nlohmann_json pybind11_json numpy pytest bzip2 sqlite zlib libffi exceptiongroup + python pybind11 nlohmann_json pybind11_json numpy "pytest==7.1.1" bzip2 sqlite zlib libffi exceptiongroup mkdir build @@ -91,7 +91,7 @@ jobs: -c https://repo.mamba.pm/emscripten-forge \ -c https://repo.mamba.pm/conda-forge \ --yes \ - python pytest numpy exceptiongroup + python "pytest==7.1.1" numpy exceptiongroup - name: Test in browser-main From 8ea350bf5170f44fe525a141e7dd2f673d25d027 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 6 Jul 2023 14:22:59 +0200 Subject: [PATCH 9/9] donwgrading pytest -- a missing one --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fd3a26b..cd2ba29 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -130,7 +130,7 @@ jobs: -c https://repo.mamba.pm/emscripten-forge \ -c https://repo.mamba.pm/conda-forge \ --yes \ - python pytest exceptiongroup + python "pytest==7.1.1" exceptiongroup - name: Test in browser-main-no-numpy run: |