-
Notifications
You must be signed in to change notification settings - Fork 91
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 lazy import for Matplotlib and move cache to runpath #1148
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Use lazy import for Matplotlib and move cache to runpath. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,9 @@ | |
import tempfile | ||
import uuid | ||
|
||
import matplotlib | ||
from reportlab.lib.units import inch | ||
from reportlab.platypus import Image | ||
|
||
matplotlib.use("Agg") | ||
import matplotlib.pyplot as plot | ||
|
||
|
||
def export_plot_to_image(graph_plot): | ||
"""Convert a MatPlot plot into an image readable in the pdf.""" | ||
|
@@ -81,6 +77,11 @@ def get_matlib_plot(source): | |
Call the appropriate plotting function based on | ||
whether a graph or chart is being plotted. | ||
""" | ||
import matplotlib | ||
|
||
matplotlib.use("Agg") | ||
import matplotlib.pyplot as plot | ||
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. maybe this line can be removed? |
||
|
||
graph_type = source["graph_type"] | ||
|
||
valid_graph_types = [ | ||
|
@@ -106,6 +107,8 @@ def plot_graph(source, graph_type): | |
Create a MatPlot plot for any graph requiring | ||
axis (and can therefore use the get_xy_coords function.) | ||
""" | ||
import matplotlib.pyplot as plot | ||
|
||
data = source["graph_data"] | ||
graph_options = source["graph_options"] | ||
series_options = source["series_options"] | ||
|
@@ -170,6 +173,8 @@ def plot_graph(source, graph_type): | |
|
||
def plot_chart(source, graph_type): | ||
"""Create a MatPlot plot for any chart not requiring axes.""" | ||
import matplotlib.pyplot as plot | ||
|
||
data = source["graph_data"] | ||
|
||
for entry in data: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1072,6 +1072,11 @@ def make_runpath_dirs(self): | |
) | ||
makedirs(self.resource_monitor_server_file_path) | ||
|
||
if not os.environ.get("MPLCONFIGDIR"): | ||
os.environ["MPLCONFIGDIR"] = os.path.join( | ||
self._runpath, "matplotlib" | ||
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. does matplotlib complain if the dir pointed by MPLCONFIGDIR doesn't exist? 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, it tries to create that. This sets the path to the runpath, if the user didn't set the env var. This way there will be no warning, and the dir is only created when the matplotlib import executes. If I remove this default setting, there will be a warning when matplotlib is imported (and the default location is read-only). |
||
) | ||
|
||
def _start_resource_monitor(self): | ||
"""Start resource monitor server and client""" | ||
if self.cfg.resource_monitor: | ||
|
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.
can we rename this file to maybe
utils.py
in this pr as well?