Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zsambokiandras
Copy link

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:

  • Test
  • Example (both test_plan.py and .rst)
  • Documentation (API)
  • News fragment present for release notes
  • MS info leakage check
  • For new driver: driver index page
  • For new assertion: ui/pdf/std renderers, documentation
  • For new cmdline arg: documentation

else:
makeemptydirs(self._runpath)
makeemptydirs(self._scratch)
if not env_mpl_cache:
makeemptydirs(self._mplcache)
Copy link
Contributor

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.

Copy link
Author

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"
Copy link
Contributor

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?

Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants