* Upgrade to Pyodide 0.23.2
* Update changelog
* Use @param decorator to fix kmeans examlpe
* Separate zz_example tests to run sequentially
* Remove pytest.raises from pyscript_src_not_found test, use check_js_errors instead
* Add 'check_js_errors' to wait_for_pyscript
This PR adds support for optionally running pyodide in a web worker:
- add a new option config.execution_thread, which can be `main` or `worker`. The default is `main`
- improve the test machinery so that we run all tests twice, once for `main` and once for `worker`
- add a new esbuild target which builds the code for the worker
The support for workers is not complete and many features are still missing: there are 71 tests which are marked as `@skip_worker`, but we can fix them in subsequent PRs.
The vast majority of tests fail because js.document is unavailable: for it to run transparently, we need the "auto-syncify" feature of synclink.
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Co-authored-by: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com>
In the future this should help us leak fewer names into the pyscript
namespace.
Rather than assigning to the pyscript module from JavaScript, we
mount a separate private JS module with the extra names needed by
PyScript. I moved a bit more interpeter intialization into
remote_interpreter.
I added a deprecation warning for `pyscript.js`: the proper way to
access `js` is `import js`.
---------
Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
* upgrade to pyodide 0.22.1
* pin bokeh in panel examples
* fix typo
* fix tests by using custom bokeh wheel
* fix bokeh interactive test
* adhere to new loadPackage API
* Fake server 404 support
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 404 test
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix test
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* test fix
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* add test and example files
* update config to include python plugins in build
* add markdown plugin
* remove full pyscript execution from pyodide
* move loading of pyscript.py from pyodide loagInterpreter to main setupVirtualEnv and add function to create python CE plugins
* add plugin class to pyscript.py
* add missing import
* fix plugin path
* add fetchPythonPlugins to PyScriptApp
* remove old comments
* fix test
* add support for python plugins beyond custom elements and add app to python namespace in main
* inject reference to PyScript app onto python plugins
* add example hook onto markdown plugin
* change plugin events logs
* remove unused PyPlugin
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix type import
* add docstring to fetchPythonPlugins
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* rename addPythonPlugin method
* address PR comment
* call python plugins on hooks after the interpreted is ready
* add test for event hooks and split the test in 2 separate plugins to isolte type of plugins tests
* change python plugins initialization and registration, to inject the app from app itself instead of on the plugins themselves
* handle case when plugin cannot load due to missing plugin attribute
* add test for fail scenario when a plugin module does not have a plugin attribute
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add deprecation warning for pyscript objects loaded in global namespace
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove all from global scope
* remove create_custom_element from global scope
* rename create_custom_element to define_custom_element
* rename attributes in define_custom_element and add docstrings
* better handle connect event output
* add warning to py_markdown plugin
* remove debugging logs
* improve tests
* remove debugging log
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove unused import
* add executable shebang
* add pyodide mock module
* fmt and lint
* Update to pyodide.ffi.create_proxy per pyodide v21 api change
* Mock pyodide as package instead of mdoule
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add __init__ to pyodide package
* Update pyscriptjs/src/plugin.ts
fix logger name
Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
* fix pyodide import but handling the diff in their API change
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* oops, conflict resolution blooper
* Fix failing integration tests
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jeff Glass <glass.jeffrey@gmail.com>
Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
Co-authored-by: FabioRosado <fabiorosado@outlook.com>
* Revert to runPython instead of await runPythonAsync
* "Implicit Coroutines" are no longer permitted in py-script tags
* Tests added for the above
* xfail test_importmap (See #938)
This PR move codes from main.ts into two new plugins:
- splashscreen (formerly known as py-loader)
- importmap
The old setting config.autoclose_loader is still supported but deprecated; the new setting is config.splashscreen.autoclose.
Moreover, it does a small refactoring around UserError: now UserErrors are correctly caught even if they are raised from within afterRuntimeLoad.
* Raise error if we get a non 200 status from fetch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add custom exception
* Add check for TypeError as well
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* implement proposal
* update docs and replace py-env
* more docs
* suggested proposal
* update docs
* add to_file parameter
* remove comment from Makefile
* suggested improvements
* move tests from basic to py_config
* retain leading slash from the first path
Until now, we didn't have a nice way to check that we expect a specific JS error in the web page.
This PR improves check_js_errors() so that now you can pass a list of error messages that you expect.
It is tricky because we need to handle (and test!) all various combinations of cases:
- errors expected and found / expected but not found
- unexpected errors found / not found
Moreover, JS exceptions now are logged in the special category console.js_error, which means that the printed text is also available using e.g. self.console.js_error.text or self.console.all.text. However, this should never be required and it's preferred to use self.check_js_errors to check for exceptions. This fixes#795 .
Finally, use the new logic to improve test_no_implicit_target.
* Add display impl, remove outputManage, print and console.log defaults to terminal
* Fixing tests
* Lint
* Erase unecessary code, add cuter CSS formating for errors, fix problems around REPL output
* Add fix to repl2 and lint
* lint
* Allow for list of display, fix elif to else
* Add better global option
* test work
* xfails
* (antocuni, mariana): let's try to start again with TDD methodology: write the minimum test and code for a simple display()
* (antocuni, mariana): this test works out of the box
* WIP: this test is broken, mariana is going to fix it
* add a failing test
* Add ability to deal with targets
* Add append arg and append tests
* Add multiple values to display
* Small adjustments to tests. I noticed I wasn;t running all at some point
* add display test
* Add console tests
* Add async tests
* Fix repl tests
* Fixing merging issues
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Address antocuni's review
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fixing more tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* linting
* Improve repl tests
* Change my test so codespell is hapy with it
* Test: change test_runtime_config to use json instead of toml to see if stops failing on CI
* kill this file: it is a merge artifact since it was renamed into test_py_config.py on the main branch
* Change test execution order and add async tests to async test file
Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This is a follow-up of PR #806 and it's a big step forward towards solving issue #763.
The basic idea is that at this stage I want to streamline the execution logic
and make it as linear and easy to read/understand as possible. The diff is
relatively big, but for the most part is just "shuffling code around".
Svelte stores:
the idea is to eventually kill of them, so that we can remove the dependency
on svelte but also to avoid relying on so much global state, which makes
things more complicated and error-prone (e.g., we have several issues related
to using runtime when it's not ready yet).
I killed addInitializer, addPostInitializer and the corresponding svelte
stores tada. They are no longer needed since the relevant code is called
directly from main.ts.
I started to kill the usage of the runtimeLoaded svelte store: instead of
relying on a global variable, I want to arrive at the point in which the
runtime is passed as a parameter in all places where it's needed: pyscript.ts
is now free of global state, but I couldn't kill it yet because it's used
heavily by base.ts and pyrepl.ts. I will do it in another PR.
Other misc changes:
I added sanity checks (and corresponding tests!) which complain if you specify
0 or multiple runtimes. Currently we support having one and only one, so there
is no point to pretend otherwise
I modified the messages displayed by the loader, to be more informative from
the user point of view.
This PR is the first step to improve and rationalize the life-cycle of a pyscript app along the lines of what I described in #763 .
It is not a complete solution, more PRs will follow.
Highlights:
- py-config is no longer a web component: the old code relied on PyConfig.connectedCallback to do some logic, but then if no <py-config> tag was present, we had to introduce a dummy one with the sole goal of activating the callback. Now the logic is much more linear.
- the new pyconfig.ts only contains the code which is needed to parse the config; I also moved some relevant code from utils.ts because it didn't really belong to it
- the old PyConfig class did much more than dealing with the config: in particular, it contained the code to initialize the env and the runtime. Now this logic has been moved directly into main.ts, inside the new PyScriptApp class. I plan to refactor the initialization code in further PRs
- the current code relies too much on global state and global variables, they are everywhere. This PR is a first step to solve the problem by introducing a PyScriptApp class, which will hold all the mutable state of the page. Currently only config is stored there, but eventually I will migrate more state to it, until we will have only one global singleton, globalApp
- thanks to what I described above, I could kill the appConfig svelte store: one less store to kill :).