Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MPLCONFIGDIR tries to be created in read-only home #832

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

Merged
merged 2 commits into from
Aug 25, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions 20 lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,18 @@ def _get_home():
raise RuntimeError('please define environment variable $HOME')


def _create_tmp_config_dir():
"""
If the config directory can not be created, create a temporary
directory.
"""
import tempfile

tempdir = os.path.join(tempfile.gettempdir(), 'matplotlib')
os.environ['MPLCONFIGDIR'] = tempdir

return tempdir


get_home = verbose.wrap('$HOME=%s', _get_home, always=False)

Expand All @@ -482,18 +494,18 @@ def _get_configdir():
if not os.path.exists(configdir):
os.makedirs(configdir)
if not _is_writable_dir(configdir):
raise RuntimeError('Could not write to MPLCONFIGDIR="%s"'%configdir)
return _create_tmp_config_dir()
return configdir

h = get_home()
p = os.path.join(get_home(), '.matplotlib')

if os.path.exists(p):
if not _is_writable_dir(p):
raise RuntimeError("'%s' is not a writable dir; you must set %s/.matplotlib to be a writable dir. You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored "% (h, h))
return _create_tmp_config_dir()
else:
if not _is_writable_dir(h):
raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)
return _create_tmp_config_dir()
from matplotlib.cbook import mkdirs
mkdirs(p)

Expand Down Expand Up @@ -922,7 +934,7 @@ class rc_context(object):
>>> with mpl.rc_context(fname='print.rc'):
>>> plt.plot(x, b)
>>> plt.plot(x, c)

The 'a' vs 'x' and 'c' vs 'x' plots would have settings from
'screen.rc', while the 'b' vs 'x' plot would have settings from
'print.rc'.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.