From f6554f1fecedec3514aa39d3657cb2eb3bd9087d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 21 Dec 2013 23:12:17 +0100 Subject: [PATCH 1/2] _get_xdg_config_dir(), _get_xdg_cache_dir() - Restored in a way that the functions fulfil the specification of the standard. The previous change to avoid exceptions if no home directory exists broke the standard. Configuration and cache directories could be specified by environment variables independent from the existence of a home directory because they can be elsewhere. --- lib/matplotlib/__init__.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index b891c030886d..43d201b49892 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): From 7da7e6056fe8c227e04708384a694da14aa8d21a Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 22 Dec 2013 20:51:12 +0100 Subject: [PATCH 2/2] _get_config_or_cache_dir() - behaviour according specification in _get_configdir() restored. 1. If an old config $HOME/.matplotlib exists it should be chosen also on Linux. 2. However, if the old config does not exist and xdg_home is None (can be the case in cluster environments) -> do not try to create directory in the non-existing home directory rather in the temporary directory. --- lib/matplotlib/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 43d201b49892..e499f915e720 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -568,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