Repository navigation
Added lazy_py_modules - #95
Conversation
|
@JeffersGlass I am not sure where you comment ended up (email only or removed) but this is about loading Python modules within the running interpreter, otherwise not possible as from Python code, if I am not mistaken, there's no way to otherwise lazy load from the network or Pyodide wheels modules outside the static, pre-defined, config.toml or .json ... I hope this is clear and it answered your question. |
ntoll
left a comment
There was a problem hiding this comment.
I don't see @JeffersGlass's question that you reference @WebReflection. :-/ I assume you've answered to Jeff's satisfaction.
This looks like a good first step because:
- It's a small change.
- It works with both MicroPython and Pyodide.
- You have to be explicit when using it (i.e. default behaviour of PyScript doesn't change).
Next steps (if required):
- Lazy loading of JS modules in a similar fashion.
- Lazy loading of our built-in PyScript "stuff"
pydomandpywebspring to mind.
We should ensure this is documented too. 👍
|
@ntoll about this:
to be honest, JS modules in workers are already lazy loaded, the dance is made synchronous by the implementation, like everything else is in workers, but on top of that, For |
|
btw ...
good point, I was thinking this should be documented in PyScript once it lands but it's actually a Polyscript feature worth documenting in here too ... I will do if I have time, and before merging it. |
33c2688 to
9dd22ac
Compare
|
I've added minimal docs around |
This MR would like to enable/allow our users to eventually lazily load modules as opposite of having these pre-fetched and already available via the config.
It exposes a
polyscript.lazy_py_modules(...packages)callback that's going to be awaited so that modules can land on the current session lazily, as opposite of on bootstrap.The idea is to forward this to the terminal or any other PyScript related session so that an asnc method could always lazily load a module avoiding slow bootstrap when a module is needed only in certain occasions.
I don't know if this is desirable but we already had some user asking for this, and internally neither Pyodide nor MicroPython allow to reach the
loadModuleorpyimportinternally, for what I could test, so this uses the exposed JS API so that modules can land later on.please see the test file attached
/cc @ntoll @JeffersGlass