This PR re-enables tests on `worker`s. Highlights: * by default, each test is run twice: the main thread version uses `<script type="py">`, the worker version automatically turn the tags into `<script type="py" worker>` * you can tweak the settings per-class by using the `@with_execution_thread` decorator. In particular, `@with_execution_thread(None)` is for those tests which don't care about it (e.g., `test_py_config.py`) * inside each class, there might be some test which should be run only in the main thread (because it doesn't make sense to test it in a worker). For those, I introduced the `@only_main` decorator * we might introduce `@only_worker` in the future, if needed * `@skip_worker` is for those tests which currently pass on main but not on workers. These are meant to be temporary, and eventually they should all be fixed During the process, I tweaked/improved/fixed/deleted some of the existing tests. Some of them were at risk of being flaky and I made them more robust, others depended on some very precise implementation detail, and I made them more generic (for example, `test_image_renders_correctly` relied on pillow to render an image with a very specific string of bytes, and it broke due to the recent upgrade to pyodide 0.24.1) I also renamed all the skip messages to start with `NEXT`, so that they are easier to grep.
@pyscript/core
We have moved and renamed previous core module as polyscript, which is the base module used in here to build up PyScript Next, now hosted in this folder.
Documentation
Please read core documentation to know more about this project.
Development
Clone this repository then run npm install within its folder.
Use npm run build to create all artifacts and dist files.
Use npm run server to test locally, via the http://localhost:8080/test/ url, smoke tests or to test manually anything you'd like to check.
Artifacts
There are two main artifacts in this project:
- stdlib and its content, where
src/stdlib/pyscript.jsexposes as object literal all the Python content within the folder (recursively) - plugins and its content, where
src/plugins.jsexposes all available dynamic imports, able to instrument the bundler to create files a part within the dist/ folder, so that by default core remains as small as possible
Accordingly, whenever a file contains this warning at its first line, please do not change such file directly before submitting a merge request, as that file will be overwritten at the next npm run build command, either here or in CI:
// ⚠️ This file is an artifact: DO NOT MODIFY
Running tests
Before running the tests, we need to create a tests environment first. To do so run the following command from the root folder of the project:
make setup
This will create a tests environment [in the root of the project, named ./env]and install all the dependencies needed to run the tests.
After the command has completed and the tests environment has been created, you can run the integration tests with the following command:
make test-integration
pyscript python package
The pyscript package available in Python lives in the folder src/stdlib/pyscript/.
All Python files will be embedded automatically whenever npm run build happens and reflected into the src/stdlib/pyscript.js file.
It is core responsibility to ensure those files will be available through the Filesystem in either the main thread, or any worker.
JS plugins
While community or third party plugins don't need to be part of this repository and can be added just importing @pyscript/core as module, there are a few plugins that we would like to make available by default and these are considered core plugins.
To add a core plugin to this project you can define your plugin entry-point and name in the src/plugins folder (see the error.js example) and create, if necessary, a folder with the same name where extra files or dependencies can be added.
The build command will bring plugins by name as artifact so that the bundler can create ad-hoc files within the dist/ folder.