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

Skip to content

Commit 1e8d592

Browse files
committed
Fix #2300: deal with the case where there are no writable directories.
1 parent e4ec9d5 commit 1e8d592

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

lib/matplotlib/__init__.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,11 @@ def _get_xdg_config_dir():
532532
base directory spec
533533
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
534534
"""
535-
return os.environ.get('XDG_CONFIG_HOME', os.path.join(get_home(), '.config'))
535+
home = get_home()
536+
if home is None:
537+
return None
538+
else:
539+
return os.environ.get('XDG_CONFIG_HOME', os.path.join(home, '.config'))
536540

537541

538542
def _get_xdg_cache_dir():
@@ -541,7 +545,11 @@ def _get_xdg_cache_dir():
541545
base directory spec
542546
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
543547
"""
544-
return os.environ.get('XDG_CACHE_HOME', os.path.join(get_home(), '.cache'))
548+
home = get_home()
549+
if home is None:
550+
return None
551+
else:
552+
return os.environ.get('XDG_CACHE_HOME', os.path.join(home, '.cache'))
545553

546554

547555
def _get_config_or_cache_dir(xdg_base):
@@ -557,22 +565,28 @@ def _get_config_or_cache_dir(xdg_base):
557565
return _create_tmp_config_dir()
558566
return configdir
559567

568+
p = None
560569
h = get_home()
561-
p = os.path.join(h, '.matplotlib')
562-
if (sys.platform.startswith('linux') and
563-
not os.path.exists(p)):
564-
p = os.path.join(xdg_base, 'matplotlib')
565-
566-
if os.path.exists(p):
567-
if not _is_writable_dir(p):
568-
return _create_tmp_config_dir()
569-
else:
570-
try:
571-
mkdirs(p)
572-
except OSError:
573-
return _create_tmp_config_dir()
570+
if h is not None:
571+
p = os.path.join(h, '.matplotlib')
572+
if (sys.platform.startswith('linux') and
573+
not os.path.exists(p) and
574+
xdg_base is not None):
575+
p = os.path.join(xdg_base, 'matplotlib')
576+
577+
if p is not None:
578+
if os.path.exists(p):
579+
if _is_writable_dir(p):
580+
return p
581+
else:
582+
try:
583+
mkdirs(p)
584+
except OSError:
585+
pass
586+
else:
587+
return p
574588

575-
return p
589+
return _create_tmp_config_dir()
576590

577591

578592
def _get_configdir():
@@ -728,9 +742,11 @@ def matplotlib_fname():
728742
if configdir is not None:
729743
fname = os.path.join(configdir, 'matplotlibrc')
730744
if os.path.exists(fname):
745+
home = get_home()
731746
if (sys.platform.startswith('linux') and
747+
home is not None and
732748
fname == os.path.join(
733-
get_home(), '.matplotlib', 'matplotlibrc')):
749+
home, '.matplotlib', 'matplotlibrc')):
734750
warnings.warn(
735751
"Found matplotlib configuration in ~/.matplotlib/. "
736752
"To conform with the XDG base directory standard, "

lib/matplotlib/font_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,15 +1324,15 @@ def findfont(prop, fontext='ttf'):
13241324
return result
13251325

13261326
else:
1327+
_fmcache = None
1328+
13271329
if not 'TRAVIS' in os.environ:
13281330
cachedir = get_cachedir()
13291331
if cachedir is not None:
13301332
if sys.version_info[0] >= 3:
13311333
_fmcache = os.path.join(cachedir, 'fontList.py3k.cache')
13321334
else:
13331335
_fmcache = os.path.join(cachedir, 'fontList.cache')
1334-
else:
1335-
_fmcache = None
13361336

13371337
fontManager = None
13381338

0 commit comments

Comments
 (0)