Skip to content

Allow fetching plugins from URL #1065

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

Merged
merged 18 commits into from
Jan 11, 2023
Merged

Conversation

FabioRosado
Copy link
Contributor

@FabioRosado FabioRosado commented Dec 21, 2022

This PR adds the possibility to fetch javascript plugins from an URL and import it as a module.

As part of this, I reworked the robustFetch since I realised that fetch will throw a TypeError when trying to fetch from bad URLs like http://blah.blah and don't return a response. Robust fetch now throws a fetch error if fetch throws the TypeError.

It also killed the old handleFetchError since the error message is now being thrown in the robustFetch.

FetchErrors will now inherit from UserError, which will create the banner for us, so we don't have to do things like:

  • handle fetch error
  • throw user Error for banner

Plugins

new method created fetchUserPlugins which loops over the plugins list and calls either fetchJSPlugin or fetchPythonPlugin. Currently we are looking at the file extension in the url and calling the right fetch method, otherwise we will throw an exception.

For the JS plugins, they will only use the afterStartup lifecycle, which is probably fine. I've also added try/catch in the plugin manager, because my hello world plugin was failing with afterSetup is not a function unless I created a plugin that had all the Plugin methods but nothing in there.

We can't import the base Plugin class from pyscript because when we import the module we can't access the pyscript/plugin module.

There's a lot of rough edges but maybe it's okay for the first pass.

TODO

A few things still need to do:

  • Create docs for fetching python plugins
  • Create docs for fetching js docs
  • Docs on the new Error Code
  • Fix jest tests

@FabioRosado FabioRosado marked this pull request as ready for review December 22, 2022 20:02
@FabioRosado FabioRosado mentioned this pull request Dec 26, 2022
3 tasks
Copy link
Contributor

@JeffersGlass JeffersGlass left a comment

Choose a reason for hiding this comment

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

Really good stuff! A handful of small changes/thoughts, and one larger one which is really a comment about register_custom_element and does it belong in the Plugin class at all...

Copy link
Contributor

@marimeireles marimeireles left a comment

Choose a reason for hiding this comment

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

Coolio!


Now, if you go to `http://localhost:8000` you should see the text "Hello World" on the page.

Writing plugins in Python is an excellent way if you want to use PyScript's API's. However, if you want to write plugins in Javascript, you can do that too.
Copy link
Contributor

Choose a reason for hiding this comment

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

if you want to use

if you want to learn how to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I need to reword this, what i was trying to say was something along the lines of: "You can do stuff in python using pyscripts apis. But if you are comfortable using javascript you can do that to"

@JeffersGlass
Copy link
Contributor

Hi @FabioRosado! Let me know if there's anything I can help with on this PR - I think it's swell and an awesome feature to add. 😃

If the only blocker is the Docs thought, we could wait for that to be a separate PR.

@FabioRosado
Copy link
Contributor Author

Hi @FabioRosado! Let me know if there's anything I can help with on this PR - I think it's swell and an awesome feature to add. 😃

If the only blocker is the Docs thought, we could wait for that to be a separate PR.

Hey Jeff, just fixed the merge conflicts, yeah let's do the docs as a separate PR 😄 I'll try to knock it off over the weekend if I get the time thanks!

Copy link
Contributor

@JeffersGlass JeffersGlass left a comment

Choose a reason for hiding this comment

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

Sorry to took me awhile to get back around to this - thanks for all the adjustments and clarifications! We'll tackle the additional Plugin tutorial as a thought for the future.

LGTM!

@FabioRosado
Copy link
Contributor Author

I didnt have time to write the docs yet but it's on my list 😄 thank you for the approval

@FabioRosado FabioRosado merged commit cc4b460 into pyscript:main Jan 11, 2023
@FabioRosado FabioRosado deleted the fr/fetch-plugins branch January 11, 2023 17:04
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.

3 participants