-
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
show_in_browser()
method for folium.folium.Map
#953
show_in_browser()
method for folium.folium.Map
#953
Conversation
if sys.version_info[0] < 3: | ||
raise NotImplementedError('Only works with python 3!') | ||
|
||
import webbrowser |
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.
E402 module level import not at top of file
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.
that seems to be the case for most of the other files in the repo, so I chose consistency over purity.
folium/_server.py
Outdated
raise NotImplementedError('Only works with python 3!') | ||
|
||
import webbrowser | ||
from http.server import BaseHTTPRequestHandler, HTTPServer |
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.
E402 module level import not at top of file
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.
that seems to be the case for most of the other files in the repo, so I chose consistency over purity.
|
||
import webbrowser | ||
from http.server import BaseHTTPRequestHandler, HTTPServer | ||
from textwrap import dedent |
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.
E402 module level import not at top of file
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.
that seems to be the case for most of the other files in the repo, so I chose consistency over purity.
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.
Please follow the liner cues here. We are cleaning up the code and new code should be compliant from the start.
So, err, both checks fail :(
|
Raising a |
examples/OpenMapInBrowser.py
Outdated
HeatMap(data).add_to(folium_map) | ||
|
||
# open in in browser | ||
folium_map.show_in_browser() |
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.
No need for this example. This can be in the method docstring.
folium/_server.py
Outdated
|
||
import sys | ||
if sys.version_info[0] < 3: | ||
raise NotImplementedError('Only works with python 3!') |
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.
Maybe a more verbose message like:
This feature is only available on Python 3.
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.
I actually realised i might have misunderstood something. Because there is an http server in python 2, so I'll check it again tomorrow.
folium/_server.py
Outdated
HTTPServer.allow_reuse_address = True | ||
httpd = HTTPServer((self.host, self.port), HTTPServerRequestHandler) | ||
|
||
# run the temporary http server with graceful exit option |
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.
Most of these comment can be removed. I guess that they were added on SO to explain the answer. We don't need them here.
I definitely appreciate the effort @Demetrio92, but to be honest I think having an HTTP server is overkill. Currently (as far as I know) all data is embedded in the map, so you could just as easily call I learned from @ocefpaf he would like to work towards not having all data embedded in the map, which is fine. But let's implement an HTTP server when or if we get there. All code needs to be maintained, so the less the better. |
That is in the long term and may never happen...
Yep.
💯 |
@Conengmo @ocefpaf In defence of the "server" code, it's base python and I really doubt there will be major compatibility breaks or maintenance required. Please let me know if this PR generally would be accepted or not. If yes, I'll address the remaining issues, otherwise let's just close it. |
from SimpleHTTPServer import SimpleHTTPRequestHandler as BaseHTTPRequestHandler | ||
from SocketServer import TCPServer as HTTPServer | ||
|
||
import webbrowser |
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.
E402 module level import not at top of file
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.
same as before this seems to be a convention in the repo
from SocketServer import TCPServer as HTTPServer | ||
|
||
import webbrowser | ||
from textwrap import dedent |
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.
E402 module level import not at top of file
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.
same as before this seems to be a convention in the repo
from SimpleHTTPServer import SimpleHTTPRequestHandler as BaseHTTPRequestHandler | ||
from SocketServer import TCPServer as HTTPServer | ||
|
||
import webbrowser |
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.
E402 module level import not at top of file
from SocketServer import TCPServer as HTTPServer | ||
|
||
import webbrowser | ||
from textwrap import dedent |
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.
E402 module level import not at top of file
I fixed python 2.7 issue, and addressed all the feedback, except that we don't really need the feature :D Linter complaining about |
53546b8
to
9f2299a
Compare
Close in favor of #1651 Thanks for your efforts on this, sorry it got left hanging for so long. |
fixes #946
Adds
show_in_browser()
method for folium.folium.Map which should work even in a vanilla python, e.g. try:I did not write any tests for the new functionality, as I am not quite sure how to test it. Suggestions welcome.
On the other hand, some tests were failing before I added any of my code, and some packages were missing in the
requirements-dev.txt
. I collected all the fixes here: #952p.s. sorry for the branch name, this should work:
git checkout 'show_in_browser()-method-for-folium.folium.Map'