Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible jsimport take two #1146

Merged
merged 19 commits into from
Jan 17, 2021
Merged

Conversation

hoodmane
Copy link
Member

@hoodmane hoodmane commented Jan 16, 2021

Now that the tricky #461 / #788 bug complex has been resolved, there is a much easier implementation for "flexible js import". This PR resolves #960.

I added two new APIS to the pyodide-js module: pyodide.registerPackage(name, object) and pyodide.unregisterPackage(name). pyodide.registerPackage adds a new javascript object to the import path, while pyodide.unregisterPackage will remove the javascript object from the import path (though if the object has already been imported, it must also be removed from sys.modules as well to actually remove it).

@hoodmane hoodmane force-pushed the flexible-jsimport-2 branch from 7a70b80 to 6ba0d26 Compare January 16, 2021 18:31
@hoodmane hoodmane mentioned this pull request Jan 16, 2021
@hoodmane hoodmane changed the title Flexible jsimport take 2 Flexible jsimport take two Jan 16, 2021
Copy link
Contributor

@dalcde dalcde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a huge fan of a python-based implementation. I've left a few minor comments.

src/pyodide-py/pyodide/_importhooks.py Outdated Show resolved Hide resolved
src/pyodide-py/pyodide/_importhooks.py Outdated Show resolved Hide resolved
src/tests/test_jsproxy.py Outdated Show resolved Hide resolved
@dalcde
Copy link
Contributor

dalcde commented Jan 17, 2021

I think this is good to go after some documentation and changelog. (also, your description in the OP refers to the old names of the new API)

@hoodmane
Copy link
Member Author

I think this is good to go after some documentation and changelog.

So for docs registerJsModule / unregisterJsModule need to go in Js API, register_js_module and unregister_js_module need to go in Python API. Do you think I should add anything about these in the "FAQ" or other sections?

your description in the OP refers to the old names of the new API

I edited the description, thanks.

@dalcde
Copy link
Contributor

dalcde commented Jan 17, 2021

An FAQ entry would be nice, I think. "How do I create custom python packages from javascript"

@hoodmane
Copy link
Member Author

Okay, I added some docs. Let me know if you have any complaints.
Before the next release it would probably be good to do some maintenance on the docs.

@dalcde dalcde merged commit 7374be5 into pyodide:master Jan 17, 2021
@hoodmane hoodmane deleted the flexible-jsimport-2 branch January 17, 2021 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurable "import js"
2 participants