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`.
Followup to pyscript#1232. Closes pyscript#1226.
Use node to make a manifest of the src/python dir and then use an esbuild
plugin to resolve an import called `pyscript_python_package.esbuild_injected.json`
to an object indicating the directories and files in the package folder.
This object is then used to govern runtime installation of the package.
* removed unnecessary getAttribute
* removed unnecessary shadow and ShadowDOM in general, as it was never used
* dropped redundant constructor
* removed unnecessary usage of the label element
* fixed redundant always-same buttons IDs
* Fix tests running on osx + remove auto-gen where doesnt make sense
* Linting
* Adds a changelog
* [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>
* Unvendor toml package
* Fix many ESlint errors
For mysterious reasons, these errors appear on my branch #1262 even
though they are not related to changes there. The eslint config seems
a bit unstable.
Anyways this fixes them.
* Put back Record
* Fix typescript compilation
* Fix lints
* Try @iarna/toml instead
* Fix import
* Use @ltd/j-toml
* Update test
* Use toml-j0.4
* Some changes
* Fix toml import
* Try adding eslint gha job
* Add forgotten checkout action
* Force CI to run
* Blah
* Fix
* Revert changes to github workflow
* Fix lints
* wget toml-j0.4 type definitions
* Add toml-j types workaround to eslint workflow
* Apply formatter
* Use @hoodmane/toml-j0.4
* Import from @hoodmane/toml-j0.4
The path logic here assumes that the tests are being run from inside
the pyscriptjs directory. It is better to compute releative to `Path(__file__)`
so that it does not depend on the working directory
* Apply prettier to css, js, html, md, ts, and yml
As a followup I will add prettier to the .pre-commit config.
This patch is 100% generated by prettier.
I used a forked version of prettier that understands the
py-script tag.
See https://github.com/hoodmane/pyscript-prettier-precommit
for more info.
* Apply old pre-commit
* Revert some problems
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Revert some changes
* More changes
* Fix pre-commit
* [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>
* split interpreter class
* add new files
* add newlines
* disable eslint for run
* remove usage of interpreter from unit test
* delete fakeinterpreter class
* fix unit tests
* add comments
* remove interpreter.ts and pyodide.ts files
* suggested changes