Sandbox has source not found for dateutil
Describe the Bug
If you put this code in the sandbox:
from dateutil.relativedelta import relativedelta
print(relativedelta(days=1))
Then you get the error:
ERROR sandbox.py:1:1-49: Stubs for `dateutil.relativedelta` are bundled with Pyrefly but the source files for the package are not found. [[missing-source-for-stubs](https://pyrefly.org/en/docs/error-kinds/#missing-source-for-stubs)]
Does this make sense in the sandbox? If you then run it you get a failure:
The module 'python-dateutil' is included in the Pyodide distribution, but it is not installed.
Should we install it into Pyodide?
Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEmqALjAK5PSGUxTMQBuMTDyao6EGsVyUmdbrw6DhUUQB1064pQjomACnl8lI1Hsak4AXgCMASlsgANCHbQ4JcohABiOgFUOKAgmUjowVnQAYw5cdDh1dWEwMOkaZgB9dFYabBhKPXxEcV1bOgBaAD46OCZKRHU6RrkYJlZKdDDVEAA5bNy6umB8AF8u9ScQMm4wKFJCJlooCl8ABVJp2eqMHAI6SNjIAHM2vljCdV8AZRgYOgALJiZiOEQAelepmBm56UPXmHQr0wuEicFe%2B3QRxOMUBKUodFQ-FQ0FQ2FgewOEGOlFOHVwxBh7k0pCYd1iZUElDgEFidEsdC6AGZCNYAExjdAgYbOVDRAQwABi0BgFDQWDwRDIXKAA
(Only applicable for extension issues) IDE Information
No response
hello @ndmitchell , can i work on it, been contributing to sandbox will have a look at it!
Certainly, have assigned you @AryanBagade
Hi @ndmitchell!
The fix:
Two approaches - which one do you prefer?
Option 1 (Simple - 1 line):
await py.loadPackage('python-dateutil');
Option 2 (Using micropip):
await py.loadPackage('micropip');
await py.runPythonAsync(`
import micropip
await micropip.install('python-dateutil')
`);
Also I'm unable to test locally due to SRI integrity check failures on Pyodide packages in the dev environment, but i believe the package fetching logic should be correct.
Which approach would you prefer? Or is there a different solution you'd recommend?
Instead, the general advice is to use micropip.install() for everything except in the following cases where pyodide.loadPackage() might be more appropriate: to load micropip itself, when you are optimizing for size, do not want to install the micropip package, and do not need to install packages from PyPI with dependency resolution.
https://pyodide.org/en/stable/usage/loading-packages.html
Seems like the latter is preferable.
I'm more curious about how you plan to detect what packages the user needs, since we can't/shouldn't pre-install all the typeshed packages on sandbox load, that would take way too long
@ndmitchell @yangdanny97 I'm unable to fully verify the fix locally due to SRI, i believe it will be tested and will work in ci production, also you can make changes to the code as well i made a pr with try catch debug setup