-
Notifications
You must be signed in to change notification settings - Fork 87
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
base: main
Are you sure you want to change the base?
Use lazy import for Matplotlib and move cache to runpath #1148
Conversation
testplan/runnable/base.py
Outdated
else: | ||
makeemptydirs(self._runpath) | ||
makeemptydirs(self._scratch) | ||
if not env_mpl_cache: | ||
makeemptydirs(self._mplcache) |
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 don't think we shall always create this dir for matplotlib, 99% of time we don't need this dir. Now that the warning msg is only issued when matplotlib is actually used by pdf exporter, it's OK to leave it to user to set it.
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.
Removed the creation, now matplotlib automatically creates the dir. Should I also remove setting the env var to the runpath, if not set by the user?
@@ -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 comment
The 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 comment
The 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).
Bug / Requirement Description
When one runs Testplan scripts that include matplotlib you get a warning about matplotlib not being able to write to a disted path.
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-xxxxxxxx because the default path (xxx/.config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
Solution description
Set matplotlib default config/cache path. We can use MPLCONFIGDIR env var to define where matplotlib can write. Use testplan runtime path.
Checklist: