Skip to content

Drop requests-wasm-polyfill? #782

Closed

Description

@jtpio

Looking at the latest release of urllib3: https://github.com/urllib3/urllib3/releases/tag/2.2.0

It looks like we might be able to drop requests-wasm-polyfill, since they now seem to be supporting emscripten (not just Pyodide) as an environment, and requests depends on urllib3.

cc @DerThorsten who may also have some insights on this.

Activity

  1. jtpio commented on Jan 31, 2024

    @jtpio
    MemberAuthor

    Trying this locally quickly, maybe this would first require to package brotli?

    image

    Using this test environment.yml:

    name: xeus-python-kernel
    channels:
      - https://repo.mamba.pm/emscripten-forge
      - conda-forge
    dependencies:
      - xeus-python
      - requests
      - urllib3 >=2.2.0
  2. jtpio commented on Jan 31, 2024

    @jtpio
    MemberAuthor

    Trying this locally quickly, maybe this would first require to package brotli?

    So we seem to have brotli packaged here already: https://github.com/emscripten-forge/recipes/tree/main/recipes/recipes_emscripten/brotli

  3. self-assigned this
    on Feb 1, 2024
  4. martinRenou commented on Feb 2, 2024

    @martinRenou
    Member

    Now pysocks is causing issues:

    ├─ urllib3 [1.24.3|1.26.16|...|2.2.0] would require
    │  └─ pysocks >=1.5.6,<2.0,!=1.5.7  but there are no viable options
    │     ├─ pysocks 1.7.1 would require
    │     │  └─ __win, which is missing on the system;
    │     └─ pysocks 1.7.1 would require
    │        └─ __unix, which is missing on the system;

    I'll look into it

  5. martinRenou commented on Feb 2, 2024

    @martinRenou
    Member

    It seems also some versions of urllib3 are pulling brotlipy, it's unclear to me what's the difference with brotli-python, we may want to package that too at some point

  6. martinRenou commented on Feb 2, 2024

    @martinRenou
    Member

    There is no way to make it optional.

    The issue with the pysocks feedstock is that it's implementing a trick to prevent using selectors allowing the package to be noarch.

    I believe we should either get rid of this trick or provide our own recipe. I'll go with with a custom recipe for now and open an issue on the upstream feedstock.

  7. jtpio commented on Feb 2, 2024

    @jtpio
    MemberAuthor

    I believe we should either get rid of this trick or provide our own recipe. I'll go with with a custom recipe for now and open an issue on the upstream feedstock.

    Yeah that sounds like the simplest approach for now 👍

  8. DerThorsten commented on Feb 2, 2024

    @DerThorsten
    Contributor

    Looking at the latest release of urllib3: https://github.com/urllib3/urllib3/releases/tag/2.2.0

    It looks like we might be able to drop requests-wasm-polyfill, since they now seem to be supporting emscripten (not just Pyodide) as an environment, and requests depends on urllib3.

    cc @DerThorsten who may also have some insights on this.

    but this still means pyodide? https://github.com/urllib3/urllib3/blob/23f2287eb526d9384dddeedb6f6345e263bb9b86/src/urllib3/contrib/emscripten/fetch.py#L35 or am I missing something?

  9. DerThorsten commented on Feb 2, 2024

    @DerThorsten
    Contributor

    we could reimplement that part of the pyodide API with pyjs I believe

  10. martinRenou commented on Feb 2, 2024

    @martinRenou
    Member

    we could reimplement that part of the pyodide API with pyjs I believe

    I have mixed feelings about this.

    It could be nice to converge a bit, instead of putting pyodide in core places we could put lower level libraries. Like having those JsArray, JsException,JsProxy,to_js, APIs in a common place for pyodide and emscripten-forge, then use this in urllib3.

  11. DerThorsten commented on Feb 2, 2024

    @DerThorsten
    Contributor

    we could reimplement that part of the pyodide API with pyjs I believe

    I have mixed feelings about this.

    It could be nice to converge a bit, instead of putting pyodide in core places we could put lower level libraries. Like having those JsArray, JsException,JsProxy,to_js, APIs in a common place for pyodide and emscripten-forge, then use this in urllib3.

    I think this way round this does not work. JsArray, JsException,JsProxy,to_js are implemented with pyodide / pyjs so you cannot just put them somewhere and let pyodide / pyjs consume them.

    There should be some absolute minimal API (ie not the full pyodide API, maybe just a subset) which can be implemented by pyodide / pyjs, and some way to use your custom implementation instead of pyodide.

    Anyhow, most things used in urlib exist in pyjs in a very similar fashion.

  12. martinRenou commented on Feb 2, 2024

    @martinRenou
    Member

    We can switch from an requests-wasm-polyfill to a pyodide-polyfill for now then.

  13. martinRenou commented on Feb 2, 2024

    @martinRenou
    Member

    Now getting this when installing requests in an emscripten-forge environment and trying to import it:

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    Cell In[1], line 1
    ----> 1 import requests
    
    File /lib/python3.11/site-packages/requests/__init__.py:43
          6 """
          7 Requests HTTP Library
          8 ~~~~~~~~~~~~~~~~~~~~~
       (...)
         38 :license: Apache 2.0, see LICENSE for more details.
         39 """
         41 import warnings
    ---> 43 import urllib3
         45 from .exceptions import RequestsDependencyWarning
         47 try:
    
    File /lib/python3.11/site-packages/urllib3/__init__.py:209
        193     return _DEFAULT_POOL.request(
        194         method,
        195         url,
       (...)
        204         json=json,
        205     )
        208 if sys.platform == "emscripten":
    --> 209     from .contrib.emscripten import inject_into_urllib3  # noqa: 401
        211     inject_into_urllib3()
    
    File /lib/python3.11/site-packages/urllib3/contrib/emscripten/__init__.py:6
          3 import urllib3.connection
          5 from ...connectionpool import HTTPConnectionPool, HTTPSConnectionPool
    ----> 6 from .connection import EmscriptenHTTPConnection, EmscriptenHTTPSConnection
          9 def inject_into_urllib3() -> None:
         10     # override connection classes to use emscripten specific classes
         11     # n.b. mypy complains about the overriding of classes below
         12     # if it isn't ignored
         13     HTTPConnectionPool.ConnectionCls = EmscriptenHTTPConnection
    
    File /lib/python3.11/site-packages/urllib3/contrib/emscripten/connection.py:17
         15 from ...util.timeout import _DEFAULT_TIMEOUT, _TYPE_TIMEOUT
         16 from ...util.url import Url
    ---> 17 from .fetch import _RequestError, _TimeoutError, send_request, send_streaming_request
         18 from .request import EmscriptenRequest
         19 from .response import EmscriptenHttpResponseWrapper, EmscriptenResponse
    
    File /lib/python3.11/site-packages/urllib3/contrib/emscripten/fetch.py:34
         31 from importlib.resources import files
         32 from typing import TYPE_CHECKING, Any
    ---> 34 import js  # type: ignore[import]
         35 from pyodide.ffi import JsArray, JsException, JsProxy, to_js  # type: ignore[import]
         37 if TYPE_CHECKING:
    
    ModuleNotFoundError: No module named 'js'
    

    So we're on the right track I guess. Just need js and pyodide-polyfill.

  14. DerThorsten commented on Feb 2, 2024

    @DerThorsten
    Contributor

    js is the module of pyodide wrapping the global scope of JavaScript (ie globalThis / window) fyi

  15. martinRenou commented on Feb 2, 2024

    @martinRenou
    Member

    Ok. I'll see if I can work something out.

  16. DerThorsten commented on Feb 2, 2024

    @DerThorsten
    Contributor

    pyjs.js is more or less the same

  17. jtpio commented on Feb 2, 2024

    @jtpio
    MemberAuthor

    Like having those JsArray, JsException,JsProxy,to_js, APIs in a common place for pyodide and emscripten-forge, then use this in urllib3.

    Yeah this was the motivation for opening pyodide/pyodide#3793.

  18. martinRenou commented on Feb 6, 2024

    @martinRenou
    Member

    Some progress made:

    Once those are complete, we can safely remove the requests-wasm-polyfill and close this

  19. jtpio commented on Feb 6, 2024

    @jtpio
    MemberAuthor

    Nice progress, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions