diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index b891c030886d..e499f915e720 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -535,11 +535,10 @@ def _get_xdg_config_dir(): base directory spec `_. """ - home = get_home() - if home is None: - return None - else: - return os.environ.get('XDG_CONFIG_HOME', os.path.join(home, '.config')) + path = get_home() + if path: + path = os.path.join(path, '.config') + return os.environ.get('XDG_CONFIG_HOME', path) def _get_xdg_cache_dir(): @@ -548,11 +547,10 @@ def _get_xdg_cache_dir(): base directory spec `_. """ - home = get_home() - if home is None: - return None - else: - return os.environ.get('XDG_CACHE_HOME', os.path.join(home, '.cache')) + path = get_home() + if path: + path = os.path.join(path, '.cache') + return os.environ.get('XDG_CACHE_HOME', path) def _get_config_or_cache_dir(xdg_base): @@ -570,13 +568,16 @@ def _get_config_or_cache_dir(xdg_base): p = None h = get_home() - if h is not None: + if h: p = os.path.join(h, '.matplotlib') - if (sys.platform.startswith('linux') and - xdg_base is not None): - p = os.path.join(xdg_base, 'matplotlib') + if sys.platform.startswith('linux') and not os.path.exists(p): + # no old config exists + if xdg_base: + p = os.path.join(xdg_base, 'matplotlib') + else: + p = None - if p is not None: + if p: if os.path.exists(p): if _is_writable_dir(p): return p