Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d934dc1

Browse files
committed
added better support for finding the config dir; added environment variable MPLCONFIGDIR
svn path=/trunk/matplotlib/; revision=3421
1 parent 0b19380 commit d934dc1

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

CHANGELOG

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2007-06-27 Added MPLCONFIGDIR for the default location for mpl data
2+
and configuration. useful for some apache installs where
3+
HOME is not writable. Tried to clean up the logic in
4+
_get_config_dir to support non-writable HOME where are
5+
writable HOME/.matplotlib already exists - JDH
6+
7+
2007-06-27 Fixed locale bug reported at
8+
http://sourceforge.net/tracker/index.php?func=detail&aid=1744154&group_id=80706&atid=560720
9+
by adding a cbook.unicode_safe function - JDH
10+
111
2007-06-27 Applied Micheal's tk savefig bugfix described at
212
http://sourceforge.net/tracker/index.php?func=detail&aid=1716732&group_id=80706&atid=560720
313
Thanks Michael!

lib/matplotlib/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,16 +323,28 @@ def _get_home():
323323

324324
def _get_configdir():
325325
"""
326-
Return the string representing the configuration dir. If s is the
327-
special string _default_, use HOME/.matplotlib. s must be writable
326+
Return the string representing the configuration dir.
327+
328+
default is HOME/.matplotlib. you can override this with the
329+
MPLCONFIGDIR environment variable
328330
"""
329-
h = get_home()
330-
if not _is_writable_dir(h):
331-
raise RuntimeError("'%s' is not a writable dir; you must set environment variable HOME to be a writable dir "%h)
332331

332+
configdir = os.environ.get('MPLCONFIGDIR')
333+
if configdir is not None:
334+
if not _is_writable_dir(configdir):
335+
raise RuntimeError('Could not write to MPLCONFIGDIR="%s"'%configdir)
336+
return configdir
337+
338+
h = get_home()
333339
p = os.path.join(get_home(), '.matplotlib')
340+
341+
if os.path.exists(p):
342+
if not _is_writable_dir(p):
343+
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)
344+
else:
345+
if not _is_writable_dir(h):
346+
raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)
334347

335-
if not _is_writable_dir(p):
336348
os.mkdir(p)
337349

338350
return p

0 commit comments

Comments
 (0)