-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Use the JsCode object from the js_loader package #2081
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First question, why not add it to the requirements.txt, but add it 'manually' to the Github Actions workflows and setup.py?
As it is, I don't see the benefit of this PR. We exchange 11 lines of code for a new mandatory dependency. I know you made that library, so it's not that I don't trust you. But seen from Folium, we'd give up control of this part to just you and whoever is in the 'streamlit-community' org, which we don't know.
The difficulty with Branca being a separate library has shown that there's a downside to splitting interwoven functionality off. I don't want to repeat that with JsCode
.
So having an external library that helps with loading Javascript files? Sounds good! Moving a class that is used everywhere throughout Folium to a separate library? Maybe not a good idea.
The
Fair enough, but I think it is not so bad in practice. See my comments below.
I see your concern about losing control over a key class. (It is also flattering to see how quickly One suggestion from me is that we can make |
Ah I understand. I guess we should get it on Conda if we want to adopt it.
That's an interesting comparison. I feel like the contact surface with xyzservices is pretty limited in comparison, and also not expected to change. Geopandas is not even an required dependency. I see JsCode being used in much more places, and also being something we might want to adapt going forward.
Definitely true, it's been a great idea!
Agreed. This PR just moves JsCode to another repo, so I'm mainly responding to that. I'd be very interested to instead learn more about how it would look like to support the extended behavior you mention here. Maybe we can discuss some code snippets that achieve that? If we know what behavior we want to include, we can then decide where we ideally want to place those. Some options:
|
give an example how we can load javascript from javascript files.
so the js_loader example will work
I added some documentation to the advanced guide to show someone could load JsCode from a javascript file. Moving Alternatively, we could also work around that by using a mypy protocol wherever we now expect a |
and JsCode like objects that come from external sources.
@Conengmo I implemented typing using a |
Sorry Hans I'm a bit overwhelmed at the moment, I do want to take a moment to properly understand this, but I don't have the space for it right now. But soon! |
No problem sir. We all have lives outside of Folium with work and family obligations. I am not particularly attached to this change either. So its perfectly fine with me if you just reject it as not worth the effort. |
This PR is based on a discussion in #1942.
In that issue, the user wanted to load
JsCode
objects from a javascript file, instead of embedding javascript code as strings in a python file. The advantages are that users can use linters, syntax highlighting and autocomplete on the JavaScript code.The
js_loader
package allows this. It provides an import hook that will parse Common JS source files and exposes exported functions asJsCode
objects. It allows users to do this: