Commit Graph

2043 Commits

Author SHA1 Message Date
Hood Chatham 2513a89616
Update Emscripten binary wheels to include Emscripten platform tags (#2610) 2022-05-25 08:39:33 +02:00
Hood Chatham a525c54d66
MAINT Use ordinary asyncio.gather in micropip tests (#2611) 2022-05-24 20:29:04 -07:00
Henry Schreiner 693ee011c4
fix(types): removing implicit generics (#2595)
* fix(types): removing implicit generics

* fix(types): address feedback
2022-05-24 19:06:31 -07:00
Hood Chatham 5595eb1305
Fix uname to report emscripten version accurately (#2608)
This is needed for the normal Python packaging system to accurately determine the platform tag for wheels for #2591.
This has been fixed upstream: https://github.com/emscripten-core/emscripten/pull/17026
2022-05-24 15:25:25 -07:00
Hood Chatham 96b162facb
MAINT Some changes from micropip-binary-wheels (#2607) 2022-05-24 14:54:59 -07:00
Hood Chatham 088d6716b8
MAINT Refactor run_in_pyodide (#2606) 2022-05-24 13:34:28 -07:00
Hood Chatham 01d0bd2526
MAINT Remove outdated chrome 89 xfails (#2603) 2022-05-24 12:22:47 -07:00
Roman Yurchak 04bca26b7e
pyodide_build: set python_requires=>3.10 (#2604) 2022-05-24 09:49:53 -07:00
Hood Chatham 843dc39d7d
Fix pyfetch when there is a cors error (#2598) 2022-05-24 10:15:37 +02:00
Hood Chatham 59d8ab241d
MAINT split test_testing into three files (#2601) 2022-05-23 19:45:25 -07:00
Hood Chatham 6efe7c356f
ENH Add `micropip.freeze` (#2581)
This adds a function `micropip.freeze()` which creates a `packages.json`
lock file which includes all packages that were loaded by micropip in the
current Pyodide session. This can be used in subsequent sessions to load
the same set of packages with `pyodide.loadPackage`.

For example in our repl:

```py
from js.console import log
import micropip
await micropip.install("sphinx-version-warning") # Installs 19 wheels from pypi
log(micropip.freeze())
```
Then opening the browser console, we can copy the JSON and make a new 
`packages.json` file out of it. (Our repl will just say "<Long output truncated>"
but the browser console truncates it and provides tools to make it easy to copy.) 
Reloading the page with the new `packages.json`, `versionwarning` will autoload:
```py
import versionwarning # Automatically loads 19 wheels from PyPI
```
We detected that `versionwarning` is an export provided by the `sphinx-version-warning`
package via the `top_level.txt` file. This file is part of the `egg-info` spec but isn't
mentioned anywhere in the `dist-info` spec. But wheels seem to include it nonetheless.
2022-05-23 14:10:33 -07:00
Henry Schreiner bbbaa09393
fix(types): explicit reexport & strict equality (#2596)
Enable precommit flags `no_implicit_reexport` and `strict_equality`
2022-05-23 13:24:21 -07:00
Hood Chatham e824643de5
MAINT Add support for testing extras to `mock_fetch` fixture (#2593)
This PR adds support for extras to the `mock_fetch` fixture. A simple example would be as follows:
```python
@pytest.mark.asyncio
async def test_extras(mock_fetch: mock_fetch_cls, mock_importlib):
    mock_fetch.add_pkg_version("reportlab")
    mock_fetch.add_pkg_version("beagle-vote", extras={"pdf" : ["reportlab"]})

    await micropip.install("beagle-vote[pdf]")

    pkg_list = micropip.list()
    assert "reportlab" in pkg_list
```
This test does not pass #2535 but hopefully it will pass on branch #2584.
2022-05-22 21:16:23 -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
Henry Schreiner eb4f7d9fd9
refactor: use .path & type build (#2583) 2022-05-20 08:27:02 +02:00
Kyle Cutler 7d3c724665
Export PATH and ERRNO_CODES from Emscripten (#2582)
BrowserFS can mount custom filesystems into Emscripten. 
However it requires the PATH and ERRNO_CODES exports from
Emscripten in addition to FS.

This exports `PATH` and `ERRNO_CODES` from `Module` into the `pyodide`
Javascript API so they can be used with BrowserFS.
2022-05-19 11:02:52 -07:00
Gyeongjae Choi 829023c9af
MAINT Remove outdated commands in Makefile (#2576) 2022-05-19 15:09:24 +09:00
Hood Chatham 7fc1c2da8e
FIX Fix feature detection when `obj.constructor` is undefined (#2520)
Currently the following code fails:
```py
from js import eval
eval("Object.create(null)")
```
with:
```py
Traceback (most recent call last):
  File "<console>", line 1, in <module>
JsException: TypeError: Cannot read properties of undefined (reading 'name')
```
This fixes it.
2022-05-18 22:19:37 -07:00
Ben Jeffery 35db93ea06
Remove uneeded numpy install in tskit build (#2579)
As suggested at #2506 (comment)
2022-05-18 19:04:04 -07:00
Hood Chatham 727ff55402 Late addition of ryanking13's edits to #2494 2022-05-18 18:27:40 -07:00
Hood Chatham 84049f255d
Improve docs on running packages (#2494) 2022-05-18 18:22:47 -07:00
Hood Chatham f2d80e0843
ENH Use `dist-info` + `importlib.metadata` to store and retrieve package metadata (#2572)
This switches to using the file system to store the information about packages
and using importlib.metadata to retrieve it.
This has two related benefits:

    We don't have to separately maintain our own separate state about what
    we've installed.

    We are guaranteed to agree with the Python stdlib about whether or not a
    package is installed, and if so which version is installed. Since the state is
    maintained in only one place, there is no chance of it diverging.

According to the packaging specs, if the package is from a url we should put
that into a file here:
packaging.python.org/en/latest/specifications/direct-url/#direct-url
Other than that, we should set the INSTALLER to pyodide.loadPackage
if the package was loaded with pyodide.loadPackage either directly or
indirectly via micropip. Otherwise set INSTALLER to micropip. That
way we can maintain the current behavior of micropip.list:

    if direct_url.json is present, then source is the url in direct_url.json
    otherwise, set source to pyodide if INSTALLER is pyodide.loadPackage
    and set it to micropip if INSTALLER is micropip.

Oddly enough, the packaging specs suggest no place to put the source
index, so it seems that according to the specs if a package was installed
by name from some custom index, this info should not be recorded.
2022-05-18 14:37:34 -07:00
Hood Chatham 54f3f0f193
Add pyodide_build create_xbuildenv and install_xbuildenv (#2550)
This adds pyodide_build command create_xbuildenv which creates a
crossbuild environment (from a copy of Pyodide where scipy has been
build) and install_xbuildenv which installs the cross build environment
into a fresh copy of Pyodide.

I successfully installed the xbuild environment into a fresh checkout of
Pyodide then built statsmodels and scikit-learn in isolation, without 
building the Python interpreter, numpy, or scipy. I dumped the generated
wheels into a copy of Pyodide downloaded from CI, and was able to import
and use them as normal.

The size of the xbuild environment is 1.5 megabytes, of which 1.2 megabytes
is Python headers.

In a subsequent PR, we can update the CI to automatically upload these
to aws s3 and then install the environment from there.
2022-05-17 22:04:18 -07:00
Gyeongjae Choi 6376f1bdb5
PKG Bump scikit-learn to 1.1.0 (#2574) 2022-05-17 21:57:05 -07:00
Gyeongjae Choi ad0064e2c4
BLD Install libraries to centralized directory (#2551) 2022-05-18 13:14:16 +09:00
Hood Chatham c6f6166ef2
micropip Fix async race condition (#2569)
It's possible that while we were awaiting on `_get_pypi_json`, some other branch
of the resolver already installed a different version of the same wheel. We need
to check a second time for whether the constraint is satisfied between when we
get the `pypi` metadata and when we put the information into `transaction.locked`
or else we might accidentally install the same wheel twice.
2022-05-17 12:34:37 -07:00
Ben Jeffery 4417005e2c
PKG Add msprime and deps including libgsl (#2548)
msprime is a widely used genetic simulation tool.
2022-05-17 12:31:43 -07:00
Roman Yurchak e2b22a84c3
Add FAQ when micropip fails to find a pure python wheel (#2558)
Closes #2557:
Users keep reporting issues about micropip not finding a pure python wheel
e.g. latest in pyscript/pyscript#297 so it appears the the current message is
not explicit enough.

We should explain in more detail,
* what is happening and why
* what the user can do about it and possibly point them to the issue tracker.
2022-05-17 11:07:36 -07:00
Hood Chatham 1ff5d32afd
MAINT micropip Move wheel-related methods into WheelInfo class (#2568)
More micropip maintenance.
* `_parse_wheel_url` ==> static method `WheelInfo.from_url`
* `_extract_wheel` ==> `WheelInfo.extract`
* `_validate_wheel` ==> `WheelInfo.validate`
* `_install_wheel` ==> `WheelInfo.install`
* Parts of `Transaction.add_wheel` were extracted into new methods
`WheelInfo.download` and `WheelInfo.requires`.
2022-05-16 19:58:53 -07:00
Hood Chatham 4c80429827
Fix ordering in micropip add_requirement (#2563)
Steps for `add_requirement`:

1. Convert `req` from a string to a Requirement if necessary
2. If `req.marker` is present, check whether `req.marker` matches `ctx`, if not we don't need it.
3. Check if `req` is already installed
4. Check if `req` is available from `packages.json`
5. Check if `req` is available from pypi

For some reason we had step 4 occurring before steps 2 and 3. This puts them in the correct order.
2022-05-16 19:12:30 -07:00
Hood Chatham 5353170373
MAINT Move testing compatibility stubs from _micropip into separate files (#2566)
This improves readability and gets the testing junk out of the top of `_micropip.py`.
2022-05-16 18:32:53 -07:00
Hood Chatham c4cc40673f
MAINT micropip: move most methods from `PackageManager` to `Transaction` and remove `PackageManager` (#2565)
This is more reorganization of `micropip` to try to make the logic easier to follow.
I turned `INSTALLED_PACKAGES` into a global variable. I turned `_install` into
a top level function definition and merged it with `install` rather than a class method.
The other methods of `PackageManager` turned into `Transaction` methods. I also 
removed `PackageManager` entirely.
2022-05-16 18:10:14 -07:00
Hood Chatham 71629d8667 Fix merge I messed up 2022-05-16 14:05:00 -07:00
Gyeongjae Choi ec80351b7b
Improve micropip error message when no package is found (#2562)
Show better error message when fetching metadata from PyPI fails.
Previously it just showed "Failed to Fetch"
2022-05-16 14:03:32 -07:00
Hood Chatham a99f9ef172
MAINT Consolidate `ctx` and `fetch_extra_kwargs` into `Transaction` (#2564)
This is more cleanup in micropip. I moved `ctx` and `fetch_extra_kwargs` into `Transaction`
properties so that we don't have to pass them through everywhere as separate arguments.
I also switch to creating the `Transaction` in `install` so that we don't have to pass the arguments 
down into `gather_requirements` separately.
2022-05-16 14:01:30 -07:00
echorand (Amit Saha) b0f7feb210
ENH Verifying checksum when loading packages in browser (#2513)
This PR does the following to complete #2431:

    * Calculate the Subresource integrity hash from the sha256 as explained here:
    https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
    As the document explains, it is a base64 encoded string of the "binary" hash, 
    not the data returned by hexdigest() method.
    * Implement the verification of the checksum when loading packages

This ignores the verification for NodeJS environment as the node-fetch module
doesn't support the integrity option. Node 17.5.0 has added the fetch API as
experimental, it would be prudent to come back and fix this when we are ready
to use that version.
2022-05-16 13:41:01 -07:00
Hood Chatham dc29ae6541
Better typechecking for micropip (#2561) 2022-05-16 13:50:57 +09:00
Hood Chatham 663459e26b
Canonicalize requirement names in micropip (#2560) 2022-05-14 20:39:54 -06:00
Roman Yurchak 3b74dcbfcf
DOC update FAQ instruction for detecting Emscripten runtime (#2552) 2022-05-13 15:39:50 +09:00
Lester Fan 0fbbeb319e
Add browser API wrappers (#2456)
Adds Python wrappers for setTimeout, clearTimeout, setInterval, clearInterval, 
addEventListener and removeEventListener as described in #2430.
2022-05-12 20:10:10 -07:00
Ryan May 91fd7dbe89
Fix building CPython on macos (Fixes #2360) (#2554)
Updates the Makefile to avoid separating the source command from the build.
2022-05-12 15:50:01 -07:00
Hood Chatham 89da31caa2
Fix garbage collection of once_callable (#2401)
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com
2022-05-11 22:09:45 -06:00
Gyeongjae Choi 8cfd9911af
ENH Add `pre` option in micropip.install (#2542) 2022-05-11 21:35:06 -06:00
Hood Chatham e732cb9dd7
meta.yaml keys for cross-build environment (#2536)
This moves unisolation into a package key. `cross-build-env: true` means the package
is part of the cross build environment and should be unisolated. `cross-build-files`
gives a list of files that should be copied from the built copy of the package into the host
copy of the package.

This will allow us to construct a cross build environment automatically as part of building
packages. If we have these files and the Python include directory, this is sufficient for 
cross-building binary packages.
2022-05-11 20:31:16 -07:00
jmdyck 5dcdf95e0f
index.rst: fix typo (#2543)
help ==> helps
2022-05-11 06:59:19 -07:00
Hood Chatham 93a714e3fd
Fix python2js cache mechanism when used with dict_converter (#2533) 2022-05-10 21:16:42 -07:00
Wei Ji 8ee129a8f6
Add xarray (#2538) 2022-05-10 21:16:21 -07:00
Ben Jeffery ce14e6306e
PKG Add tskit 0.4.1 and deps (#2506) 2022-05-11 11:36:33 +09:00
Gyeongjae Choi 3ed6d29e89
FIX Fix micropip version comparison with prerelease version (#2532) 2022-05-10 09:19:39 -06:00