Currently if the result from pyExec is a PyProxy, it gets destroyed.
This switches to using `to_js` to handle this (it is better to use
than an explicit `create_proxy` since it automatically decides whether
to create a proxy or not).
I also added `destroyIfProxy` which checks if something is a `PyProxy`
and then destroys it. Each use of `pyExec` needs to call `destroyIfProxy`
on the result after it is done with it.
* Add 'xterm' attribute in py-config using new validation
* Use screen reader mode
* Add `xtermReady` promise to allow users to away xterm.js init
* Guard against initializing a tag twice
* Add tests and doc
* 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
* remove PyWidget and py-register-widget
* refactor py-list as Plugin
* add newline
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix eslint
* handle case if src not supplied
* move inside if
* - Remove src attribute for py-list
- Re-implement as a Python plugin
- Remove pylist.py from examples directory
- Remove PyListPlugin as one of the default ones
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* move PyItem and PyList classes to the plugin
* clean up PyListTemplate and PyItemTemplate from pyscript module
* fix linting
* use PyList instead of PyListTemplate instead
* fix example for todo-pylist
* re-enable and improve test
* move py-list plugin to examples
* fix py-list plugin link
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Before this PR, the following test passed:
def test_pyscript_hello(self):
self.pyscript_run(
"""
<script type="py">
raise Exception("hello")
</script>
""")
What happens is that we intercept the Python exception and display a nice banner on the DOM, but the test itself passes. This is error prone: if we have Python exceptions on the page, the test should fail by default, and we should have a way to silence it in case those exceptions are expected.
This PR treats Python errors as we treat JS errors: unhandled exceptions cause the test to fail, but you can silence them by calling self.check_py_errors(), exactly as you can call self.check_js_errors().
* test for no cors headers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix tests
* suggested changes
* disable directly
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add error message
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* improve test
* improve error message
* remove py-config tag from cors test
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add new _event_handling.py file with @when decorator
* @when decorate is in pyscript package namespace/_all__
* Write tests in new test_event_handling.py
* Add docs for @when decorator
------------
Co-authored-by: Mariana Meireles <marian.meireles@gmail.com>
The goal of this MR is to unobtrusively allow the usage of `<script type="py">`, `<script type="pyscript">` or `<script type="py-script">` tags instead of `<py-script>` for all those case where the layout in custom elements get parsed and breaks users' expectations (including our SVG based tests).
* always same listener, for easy removal and reduce RAM
* avoid duplicated entries for smaller library outcome
* use XPath to crawl all attributes names instead of CSS
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>
* Add `validateConfigParameter` and `validateConfigParameterFromArray` functions to validate user-provided parameters from py-config
* Add units tests for `validateConfigParameter` and `validateConfigParameterFromArray`
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add docs to repl with attr src
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix path errors on Windows systems
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix path errors on Windows systems
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@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>
Switch to using the new version of synclink with support for same thread syncify (and also correct types).
Uses syncify to replace one use of `_unwrapped_remote`.
* remove pys-on* and py-on* attributes
* update changelog
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix eslint
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Previously, if the message appeared on the console immediately before the call to self.wait_for_console(), the call would hang forever until the timeout. Now, it returns immediately.
- `wait_for_pyscript` now logs the time actually taken for waiting
- `wait_for_pyscript` takes a `timeout` argument so that we can tweak it on a test-by-test basis
* load code from the attr src of py-repl
* load code from the attr src of py-repl
* load code from the attr src of py-repl
* load code from the attr src of py-repl
* [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>
Resolves pyscript#1313 and pyscript#1314. On top of pyscript#1318.
The point of these tests is to define the execution order of Tasks
that are scheduled in <py-script> tags: first all the py-script tags
are executed and their related lifecycle events. Once all of this
is done, we schedule any enqueued tasks.
To delay the execution of these tasks, we use a custom event loop for
pyExec with this defer behavior. Until schedule_deferred_tasks is called,
we defer tasks started by user code. schedule_deferred_tasks starts all
deferred user tasks and switches to immediately scheduling any further
user tasks.
Turns off:
- no-explicit-any (we need to handle any return values from runPython)
- no-unsafe-assignment (noisy and pointless)
And resolves all but two remaining ones. The last two lints regard access to private Pyodide variables and so:
- they are not easy to work around without an upstream Pyodide patch
- they should trigger linter and require explicit override
This is some refactoring I did on the way towards resolving pyscript#1313.
I added a new _run_pyscript Python function which executes the code
inside a context manager that sets the display target. We can then
return a JS object wrapper directly from Python.
I moved the "installation" of the pyscript module to loadInterpreter,
and pyimport pyscript_py there and give it a type. This avoids a bunch
of creating and deleting of proxies for pyscript_py and allows us to
give it a type once and for all.
I also did some minor logic cleanup in a few places.
* Deprecate py-mount attribute, with comments as to when it was deprecated
* Add changelog entry for deprecation
* Fix 'unused' examples that used py-mount (handtrack and mario)
This is a first step towards loading more stuff simultaneously rather
than sequentially.
The functional part of this is pretty small: call `calculateFetchPaths` and
then `Promise.all(fetchPaths.map(loadFileFromURL));`. I also transposed the
return type of `calculateFetchPaths` since it's more convenient to consume
this way.
I redid the logic in `calculateFetchPaths` a bit. I renamed `src/plugins/fetch.ts`
to `calculateFetchPaths.ts` since the file performs no fetching. I also
renamed `loadFromFile` to `loadFileFromURL`.