From 1e8d592ed0439ac6fe8fc08d5efe522799acf4fe Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 27 Sep 2013 09:37:18 -0400 Subject: [PATCH] Fix #2300: deal with the case where there are no writable directories. --- lib/matplotlib/__init__.py | 50 ++++++++++++++++++++++------------ lib/matplotlib/font_manager.py | 4 +-- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 3d8aa3ae7296..3df1e6bdbc8c 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -532,7 +532,11 @@ def _get_xdg_config_dir(): base directory spec `_. """ - return os.environ.get('XDG_CONFIG_HOME', os.path.join(get_home(), '.config')) + home = get_home() + if home is None: + return None + else: + return os.environ.get('XDG_CONFIG_HOME', os.path.join(home, '.config')) def _get_xdg_cache_dir(): @@ -541,7 +545,11 @@ def _get_xdg_cache_dir(): base directory spec `_. """ - return os.environ.get('XDG_CACHE_HOME', os.path.join(get_home(), '.cache')) + home = get_home() + if home is None: + return None + else: + return os.environ.get('XDG_CACHE_HOME', os.path.join(home, '.cache')) def _get_config_or_cache_dir(xdg_base): @@ -557,22 +565,28 @@ def _get_config_or_cache_dir(xdg_base): return _create_tmp_config_dir() return configdir + p = None h = get_home() - p = os.path.join(h, '.matplotlib') - if (sys.platform.startswith('linux') and - not os.path.exists(p)): - p = os.path.join(xdg_base, 'matplotlib') - - if os.path.exists(p): - if not _is_writable_dir(p): - return _create_tmp_config_dir() - else: - try: - mkdirs(p) - except OSError: - return _create_tmp_config_dir() + if h is not None: + p = os.path.join(h, '.matplotlib') + if (sys.platform.startswith('linux') and + not os.path.exists(p) and + xdg_base is not None): + p = os.path.join(xdg_base, 'matplotlib') + + if p is not None: + if os.path.exists(p): + if _is_writable_dir(p): + return p + else: + try: + mkdirs(p) + except OSError: + pass + else: + return p - return p + return _create_tmp_config_dir() def _get_configdir(): @@ -728,9 +742,11 @@ def matplotlib_fname(): if configdir is not None: fname = os.path.join(configdir, 'matplotlibrc') if os.path.exists(fname): + home = get_home() if (sys.platform.startswith('linux') and + home is not None and fname == os.path.join( - get_home(), '.matplotlib', 'matplotlibrc')): + home, '.matplotlib', 'matplotlibrc')): warnings.warn( "Found matplotlib configuration in ~/.matplotlib/. " "To conform with the XDG base directory standard, " diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index b7670efdcb2c..10ccbda3bba3 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -1324,6 +1324,8 @@ def findfont(prop, fontext='ttf'): return result else: + _fmcache = None + if not 'TRAVIS' in os.environ: cachedir = get_cachedir() if cachedir is not None: @@ -1331,8 +1333,6 @@ def findfont(prop, fontext='ttf'): _fmcache = os.path.join(cachedir, 'fontList.py3k.cache') else: _fmcache = os.path.join(cachedir, 'fontList.cache') - else: - _fmcache = None fontManager = None