cartopy icon indicating copy to clipboard operation
cartopy copied to clipboard

Replace urllib.request with urllib3 to support WebAssembly

Open rpwagner opened this issue 9 months ago • 1 comments

As discussed in #2514, urllib.request is not supported in WebAssembly. This replaces urllib.request where needed with urllib3 which does work with WebAssembly. I've tried to keep the code changes to a minimum and to reuse existing semantic patterns.

The linter did introduce new lines in one of the imports. I found it odd but left it in place.

Rationale

This enables the use of Cartopy is Pyodide and JupyterLite. Without it, downloading of shape files, etc., fail. See #2514.

Implications

I've run the unit tests and nothing new fails. It's also been tested in JupyterLite and works. There is a chance that the download code path hasn't been fully tested and something may still need to be changed to support urllib3.

This also introduces a new dependency, even though urllib3 is widely available. It is also an existing package in Pyodide.

rpwagner avatar Mar 29 '25 02:03 rpwagner

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Mar 29 '25 02:03 CLAassistant

Is this PR still active? I am running into the same problem and would love to see a solution.

MMesch avatar Dec 18 '25 15:12 MMesch

It is still open, but needs a champion that is interested in merging it in. I'm not in favor of it because it adds a new dependency that seems somewhat unncessary except for a WASM environment, but I won't block if someone else thinks this is the way to go.

See the comment here and the thread for workarounds/suggestions on how to approach this: https://github.com/SciTools/cartopy/issues/2514#issuecomment-2763101149

greglucas avatar Dec 18 '25 17:12 greglucas

The workaround is reasonably easy and works for me. Thanks for pointing to it.

On the other hand, "except for a WASM environment" seems like a very good reason to me. Especially considering that WASM is a pretty universal standard these days rapidly gaining popularity through platforms such as JupyterLite. But I'm not neutral.

MMesch avatar Dec 18 '25 18:12 MMesch

Still needs the CLA to be signed, no opinion on the dependency myself.

QuLogic avatar Dec 19 '25 03:12 QuLogic