Commit Graph

108 Commits

Author SHA1 Message Date
Hood Chatham 481e99070d
chore: fix pre-commit errors (#4466) 2024-02-01 15:31:20 -08:00
Hood Chatham 3e6d17147b Fix typo 2024-01-31 11:20:47 -08:00
Hood Chatham 2eb834b32d
Update conftest.py for pluggy 1.1 (#4448)
pluggy >=1.1 makes really annoying warnings if the original wrapper hooks raise errors
telling us to use the new style wrapper. This follows their advice to get rid of the warnings.
2024-01-31 11:18:57 -08:00
Hood Chatham b8287e42d9
chore: Update pre-commit (#4440)
I also reordered prettier to come last since it's the slowest. I switched from
using black to ruff-format which says its defaults are nearly the same as black.
2024-01-28 13:20:08 -08:00
Hood Chatham 1396c8c07a
Make pyimport able to return module attributes (#4395)
Before this PR, `pyimport` can be used like: `pyimport("package")` or `pyimport("package.module")` but `pyimport("package.attribute")` fails. This updates `pyimport` to also work to get package attributes.

I also updated the docs for pyimport.
2024-01-24 15:19:02 -08:00
Hood Chatham 2cdca2ea47
MAINT Make doctests run; run some doctests in pyodide (#4280)
This uses pyodide/pytest-pyodide#117 to run doctests in
Pyodide. I also turned on and fixed various doctests that were not working for
unrelated reasons
2023-11-18 16:17:30 -08:00
Gyeongjae Choi 747270b1f7
TST Reuse single safari webdriver during the test (#4270)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-11-07 13:08:18 +01:00
Hood Chatham c648fbc61b
Use JsVal instead of JsRef (nr. 8) (#4262)
This is close to finishing the refactor. I removed the last few uses of the
Hiwire JS APIs from the PyProxy Buffer apis. I reworked all of the
JsProxy_create family to use JsVal everywhere. I removed most of the remaining
logic from hiwire.c. The only remaining places where JsRef is used are in struct
fields where it is needed.
2023-10-31 12:40:50 -07:00
Hood Chatham 6117d7c90d Stack switching (#3210)
Uses the JS Promise integration stack switching API to allow blocking for JavaScript promises and
`PyodideFuture` objects. It's a bit complicated...
This doesn't include support for reentrant switching, currently doing that will corrupt the Python VM.
2023-10-21 09:20:09 -07:00
Hood Chatham f28d8c9efc Revert JSPI Changes
This reverts commits:
9ed5e839ff
8861b317a6
b2c47ae766
ab8dc2eac6
3bcc527c92
2505d4d6a3
2023-09-14 07:26:46 -07:00
Hood Chatham 3bcc527c92 Stack switching (#3210)
Uses the JS Promise integration stack switching API to allow blocking for JavaScript promises and
`PyodideFuture` objects. It's a bit complicated...
This doesn't include support for reentrant switching, currently doing that will corrupt the Python VM.
2023-09-13 16:25:24 -07:00
Hood Chatham a8f2409426
ENH Add `loadPyodide` `packages` option for loading packages during bootstrap (#4100)
For improved loading performance.
2023-08-29 13:43:07 +02:00
Hood Chatham 5cead3963d
FIX Handle EAGAIN when writing as well as when reading (#4090) 2023-08-28 13:13:57 +02:00
Hood Chatham 1a844d0c96
PERF Add a hiwire stack and use it in python2js (#4072) 2023-08-22 16:01:48 +02:00
Hood Chatham e19621d483
ENH Rework streams handling (#4035)
This fixes a number problems with the old stream handling:

1. Not possible to set a custom errno (necessary for proper interrupt
   handling and possibly for other things)

2. Inefficient: in a lot of cases we have data in one buffer and we need
   it placed into a different buffer, but we have to implement a function
   that gets one byte out of the source buffer and then call it repeatedly
   to move one byte at a time to the target buffer.

3. Ease of implementation: in many cases we already have perfectly good
   buffer manipulation APIs, so if we have direct access to the true source
   or target buffer we can just use these. See: the node IO code, which got
   much simpler.

This is backwards compatible, so you can still use the old input mechanism
or use buffered or raw output. But it adds a new method of directly implementing
read/write. For simplicity, we insure that the source/destination buffers are
always `Uint8Array` views that point to exactly the region that is meant to be
read/written.

The old mechanisms are faster than before and can correctly support keyboard
interrupts. Other than that I think the original behavior is unchanged. I added a
lot more test coverage to ensure backwards compatibility since there was pretty
anemic coverage before.

I think the read/write APIs are mostly pretty simple to use, with the exception
that someone might forget to return the number of bytes read. JavaScript's ordinary
behavior coerces the `undefined` to a 0, which leads to an infinite loop where the
filesystem repeatedly asks to read/write the same data since it sees no progress.
I added a check that writes an error message to the console and sets EIO when undefined
is returned so the infinite loop is prevented and the problem is explained.
2023-08-21 08:41:44 +02:00
Hood Chatham 6e687819d2
PERF Improve internal PyProxy attribute access (#4014)
We've received user feedback recently that Python => JS calls are a bit slow when
the arguments are proxied (from @DerThorsten and @laffra). Profiling showed
that 90% of the time was being spent in destroying the pyproxies. The line profiles
showed that every time we accessed `pyproxy.$$` it was very slow. The problem is
that these accesses go through a slow path in the `PyProxy` traps for `get`. Switching
to using a `Symbol` for access hits a fast path for the `get` trap.

This patch was enough to bring the time spent in destroy_proxy down from 90% to 6%
of the runtime for the following profile:
```py
from pyodide.ffi import create_proxy
from pyodide.code import run_js
from timeit import timeit
n = 100000

jsf = run_js("() => {}")
a = object()

timeit("jsf(a, a, a, a)", number=n, globals={"jsf": jsf, "a": a}) / n * 1e6
```
2023-08-10 15:00:04 +02:00
Martoxa 60e74f3e84
DOC Add docstring for pyfetch (#4008)
[skip ci]
2023-07-24 15:02:17 +02:00
maksbialas ccb5addd26
DOC Add docstrings for open_url, CodeRunner, JsProxy (#4007)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-07-22 16:29:35 +02:00
Gyeongjae Choi dddfa820f9
Remove deprecated methods (#3677)
Remove deprecated methods before releasing 0.23 following the [deprecation timeline](https://github.com/pyodide/pyodide/blob/main/docs/project/deprecation-timeline.md)
2023-03-27 10:48:33 +09:00
Christian Clauss 57f36ac6f8
Ruff is now compatible with Python pattern matching (#3650) 2023-03-13 22:45:06 +01:00
Gyeongjae Choi edf175f013
TST Run package tests in Safari (#3095) 2022-09-14 09:13:53 +09:00
Gyeongjae Choi 0333d1fa36
CI Fix pytest runtime option syntax (#3084) 2022-09-08 22:39:42 +09:00
Gyeongjae Choi 6964672556
Fix incorrect package name of ruamel.yaml (#3036) 2022-08-30 16:25:13 +09:00
Gyeongjae Choi fcfbdccd24
Fix package import test (#2942) 2022-08-08 11:24:34 +09:00
Gyeongjae Choi 512d2bd950
MAINT Rename pytest_pyodide wrappers 2022-08-03 13:34:25 +09:00
Roman Yurchak c85e00806b
MAINT Switch to pytest-pyodide (#2893)
Co-authored-by: ryanking13 <def6488@gmail.com>
2022-07-31 19:00:45 +09:00
Gyeongjae Choi 21b592a6d2
TST Fix test skip check (#2915) 2022-07-29 08:54:36 +09:00
Gyeongjae Choi dc31bc8f3e
Set initialization script for pyodide-test-runner (#2889) 2022-07-22 11:59:51 +09:00
Gyeongjae Choi 1fc2fc4256
CI Split up package test jobs (#2852)
This PR splits package test in CI so that no-numpy-dependents packages can be tested earlier. In detail, pytest will now save test results into its cache directory, and if --skip-passed option is given, it will skip previously successful tests.
2022-07-11 09:52:38 +09:00
Gyeongjae Choi 7d7b7e899d
TST Make `pyodide-test-runner` installable (#2742) 2022-07-04 09:07:01 +02:00
Gyeongjae Choi 74a89826ce
TST Add Playwright for an auxiliary testing framework (#2091) 2022-05-31 08:17:47 +09:00
Hood Chatham 1eab80ea40
MAINT Add pytest.mark.xfail_browsers and use it to reduce boilerplate (#2616)
Use a decorator to indicate which browsers we want to xfail test. 
This works for `run_in_pyodide` as well as normal tests.
2022-05-25 13:34:40 -07:00
Hood Chatham 60b9344b56
MAINT Improvements to micropip test mocks (#2589)
Various improvements to `test_micropip`. The main feature is a new fixture
`mock_fetch` with an `add_pkg` method that takes a package name, a map
from version to requirements, and a choice of platform. This should
hopefully make writing more tests a lot easier (which is good because
we could use more micropip test coverage but we are limited by the
difficulty of writing good tests).

This also adds a fixture to create distinct dummy package names and
enables `@pytest.mark.asyncio` to handle the async calls rather than
using `asyncio.get_event_loop.run_until_complete`.
2022-05-21 21:11:30 -07:00
Henry Schreiner e31bb554e4
chore: complete more incomplete types (#2590)
* chore: add some incomplete types
* chore: modernize pyproject.toml

Adding more incomplete types. About 2/3 of the way through being
able to turn on the strictness flag for it.
2022-05-21 13:35:02 -07:00
Hood Chatham ecaab15c12
Pytest rewrites for run_in_pyodide (#2510) 2022-05-08 18:43:26 -07:00
Hood Chatham 919bd556d3 Revert "Try to fix contest"
This reverts commit a4fe91df04.
2022-05-08 08:51:35 -07:00
Hood Chatham a4fe91df04 Try to fix contest 2022-05-08 08:48:09 -07:00
Gyeongjae Choi b20b43bd66
MAINT Split conftest.py into modules (#2418) 2022-05-08 16:52:08 +09:00
Gyeongjae Choi 6900afdc5b
PKG Add opencv-python, ffmpeg and libwebp (#2305)
* Add opencv-python

* Update comment

* Add JPEG, PNG, WEBP, ZLIB support

* Add tests for image processing

* Add more core modules

* Disable opencl

* Replace lena with baboon and add more tests

* Add file system support

* Add ffmpeg

* Add more tests

* Disable pthread in ffmpeg

* Disable canonical input processing mode in node test

* Update changelog

* Remove import test

* Allow more time in the first test

* Split out libwebp

* Fix node test

* Use a seperate CI job for opencv-python

* Fix generator

* Update changelog

* Remove protobuf package

* Try to fix CI workspace conflict

* Fix CI

* Use another CI job for generating unified packages.json

* Try to fix CI

* Fix CI again

* Disable verbose build

* Prevent from building opencv-python twice

* Persist only build artifacts

* Sepearate Cmake args into a script

* Try to reuse build packages job

* Fix CI

* Fix typo

* Fix merge conflict

* Use large resource class for package build

* Do not upload unwanted artifacts

* Do not upload unwanted artifacts
2022-04-19 09:24:47 +09:00
Hood Chatham e5a46e520a
Fix npm package (#2394)
Various fixes to improve the npm package.

Switch to publishing the dist folder, fix indexURL for node, 
fix node commonJS import and ES6 import only publish core 
Pyodide interpreter to npm, download and cache other wheels 
on first use.
2022-04-17 21:10:03 -07:00
Hood Chatham 50af355e8c
Rename 'build' directory to 'dist' (#2387)
dist is both more accurate (the 'build' directory is normally where you do the build,
and normally consists of intermediate build artifacts no one cares about). dist also
occurs less frequently in the code base: after this change \bbuild\b has 466 matches,
whereas \bdist\b has 101 matches. build has 1072 matches whereas dist has 362.
2022-04-11 16:01:40 -07:00
Gyeongjae Choi bd8f8c094d
TST Enable some skipped or xfailed tests (#2368) 2022-04-08 15:54:29 +02:00
Hood Chatham eb8afb00c2
Update libffi commit (#2350)
All libffi tests pass now. The only failing ctypes test is test_callback_too_many_args which doesn't segfault anymore, it only soft fails. Planning to submit a PR to cpython that fixes test_callback_too_many_args.
See also:
bugs.python.org/issue47208
https://github.com/emscripten-core/emscripten/pull/16658
2022-04-04 21:18:20 -07:00
Hood Chatham 844cc24fe0
Merge together unpack_buffer and unpack_buffer_archive (#2307)
When I added unpack_buffer_archive, in code review people said
it was redundant with unpack_buffer and they should be merged.
I said merging was too annoying. They were right. This merges
the functions together into a function with a 38 line docstring
and a 18 line implementation.
2022-03-24 18:31:18 -07:00
Hood Chatham 7f908beb4c
ENH Calculate indexURL from error stack trace (#2292)
If no indexURL is provided, we throw and catch an error and
then use ErrorStackParser to calculate where pyodide.js has
been loaded from. Resolves #2290.

Question: But getting the URL from error stack trace is well... really
hacky. Can't we use
[`document.currentScript`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript)
or
[`import.meta.url`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta)
instead?
Answer: `document.currentScript` works for the browser main thread.
`import.meta` works for es6 modules. In a classic webworker, I think there
is no approach that works. Also we would need some third approach for node
when loading a commonjs module using `require`. On the other hand, this
stack trace approach works for every case without any feature detection
code.
2022-03-20 22:44:54 -07:00
Henry Schreiner 4f8b0a0344
chore: more pre-commit checking (#2257) 2022-03-07 21:51:20 -08:00
LeoPsidom 8798e1f2fd
Use ESM import in module type webworker (#2220)
Co-authored-by: root <root@ip-172-31-32-133.us-east-2.compute.internal>
2022-03-02 00:31:41 -08:00
Henry Schreiner 8d00451142
chore: enable the rest of flake8 & bugbear (#2216) 2022-02-27 12:39:53 -05:00
Henry Schreiner 8385df36a4
tests: enabling mypy on untyped defs (#2204) 2022-02-23 17:10:53 -05:00
Henry Schreiner 66856a7427
MAINT isort (#2200) 2022-02-21 23:27:03 +01:00