Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
A hodgepodge of Py3 & style fixes.#10793
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
""" | ||
Displays Agg images in the browser, with interactivity | ||
""" | ||
# The WebAgg backend is divided into two modules: | ||
# | ||
@@ -13,12 +11,12 @@ | ||
# - `backend_webagg.py` contains a concrete implementation of a basic | ||
# application, implemented with tornado. | ||
from contextlib import contextmanager | ||
import errno | ||
from io import BytesIO | ||
import json | ||
import os | ||
from pathlib import Path | ||
import random | ||
import sys | ||
import signal | ||
@@ -63,14 +61,9 @@ class WebAggApplication(tornado.web.Application): | ||
class FavIcon(tornado.web.RequestHandler): | ||
def get(self): | ||
self.set_header('Content-Type', 'image/png') | ||
image_path = Path(rcParams["datapath"], "images", "matplotlib.png") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm a little confused about pathlib now. Will this work on 3.5? I wouldn't pick on it, but the test coverage of this PR is not good, so... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Yes, pathlib is 3.4+ (https://docs.python.org/3/library/pathlib.html) ({read,write}_{text,bytes} is 3.5+,https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_bytes). What changed in 3.6 is that a bunch of stdlib functions that were previously only accepting string paths (open, os.path.*, etc.) started to also accept Path objects (https://www.python.org/dev/peps/pep-0519/), thus greatly decreasing the friction when using Path objects. But that's not something we can rely on (yet). There are quite a few places where we use the old idiom (e.g.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. OK, and I take it nothing trivial can be done to increase the test coverage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Probably not? If that makes you really uncomfortable I can revert that change, just let me know. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. No, I trust you, just asking in case you felt guilty about it... | ||
self.write(image_path.read_bytes()) | ||
class SingleFigurePage(tornado.web.RequestHandler): | ||
def __init__(self, application, request, **kwargs): | ||
@@ -135,7 +128,7 @@ def get(self, fignum, fmt): | ||
self.set_header('Content-Type', mimetypes.get(fmt, 'binary')) | ||
buff = BytesIO() | ||
manager.canvas.figure.savefig(buff, format=fmt) | ||
self.write(buff.getvalue()) | ||
@@ -304,13 +297,9 @@ def ipython_inline_display(figure): | ||
if not webagg_server_thread.is_alive(): | ||
webagg_server_thread.start() | ||
fignum = figure.number | ||
tpl = Path(core.FigureManagerWebAgg.get_static_file_path(), | ||
"ipython_inline_figure.html").read_text() | ||
t = tornado.template.Template(tpl) | ||
return t.generate( | ||
prefix=WebAggApplication.url_prefix, | ||