Skip to content

Set MPLCONFIGDIR before matplotlib import (fixes #39)#57

Draft
endolith wants to merge 1 commit into
mainfrom
cursor/mplconfigdir-writable-cache-ce97
Draft

Set MPLCONFIGDIR before matplotlib import (fixes #39)#57
endolith wants to merge 1 commit into
mainfrom
cursor/mplconfigdir-writable-cache-ce97

Conversation

@endolith

Copy link
Copy Markdown
Owner

Summary

Issue #39: Matplotlib logs a warning and uses a random temporary cache directory when the default config path (for example under $HOME/.config/matplotlib) is not writable, which is common in serverless environments.

Changes

  • Import tempfile and, if MPLCONFIGDIR is not already set by the environment, set it to a stable writable directory under tempfile.gettempdir() (e.g. .../usgs-lidar-tile-server-matplotlib) and ensure it exists.
  • This runs before any third-party imports so matplotlib’s first import sees the variable.

Users who need a specific location can still set MPLCONFIGDIR in the environment; the code does not override an existing value.

Open in Web Open in Cursor 

Matplotlib warns and uses a random temp directory when the default
config path under HOME is not writable (e.g. AWS Lambda). Point
MPLCONFIGDIR at a stable directory under tempfile.gettempdir() so
imports and caching behave consistently unless the user already set
MPLCONFIGDIR.

Co-authored-by: endolith <endolith@gmail.com>
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