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

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/matplotlib/__init__.py
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 that is destroyed atexit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now it is not destroyed atexit, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- forgot to update the docstring.

"""
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