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

Skip to content

Commit 1d51360

Browse files
committed
Merge pull request #2300 from mdboom/fix-get-home
would crash if get_home() returns None
2 parents 5dce348 + 1e8d592 commit 1d51360

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
@@ -531,7 +531,11 @@ def _get_xdg_config_dir():
531531
base directory spec
532532
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
533533
"""
534-
return os.environ.get('XDG_CONFIG_HOME', os.path.join(get_home(), '.config'))
534+
home = get_home()
535+
if home is None:
536+
return None
537+
else:
538+
return os.environ.get('XDG_CONFIG_HOME', os.path.join(home, '.config'))
535539

536540

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

545553

546554
def _get_config_or_cache_dir(xdg_base):
@@ -556,22 +564,28 @@ def _get_config_or_cache_dir(xdg_base):
556564
return _create_tmp_config_dir()
557565
return configdir
558566

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

574-
return p
588+
return _create_tmp_config_dir()
575589

576590

577591
def _get_configdir():
@@ -727,9 +741,11 @@ def matplotlib_fname():
727741
if configdir is not None:
728742
fname = os.path.join(configdir, 'matplotlibrc')
729743
if os.path.exists(fname):
744+
home = get_home()
730745
if (sys.platform.startswith('linux') and
746+
home is not None and
731747
fname == os.path.join(
732-
get_home(), '.matplotlib', 'matplotlibrc')):
748+
home, '.matplotlib', 'matplotlibrc')):
733749
warnings.warn(
734750
"Found matplotlib configuration in ~/.matplotlib/. "
735751
"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)