From 98439df2ea1bbbc32c4e63e2b967800ab0049007 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 11 Jan 2014 12:37:38 +0100 Subject: [PATCH] Package initialization made possible when executed in environments whithout access to the home directory. Functions _get_xdg_config_dir(), _get_xdg_cache_dir(), _get_config_or_cache_dir() allow now the use of the environment variables XDG_CONFIG_HOME resp. XDG_CACHE_HOME without requiring access to the home directory (f.ex. in batch jobs on clusters). Before, the definitions of the environment variables would not have been used when the home directory was not accessible. Nevertheless, the standard does not bind the variable definitions to the existence of home directories (only the default values are defined with respect to them). --- lib/matplotlib/__init__.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 1592e2db2274..aff198209cc7 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -531,11 +531,12 @@ 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 = os.environ.get('XDG_CONFIG_HOME') + if path is None: + path = get_home() + if path is not None: + path = os.path.join(path, '.config') + return path def _get_xdg_cache_dir(): @@ -544,11 +545,12 @@ 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 = os.environ.get('XDG_CACHE_HOME') + if path is None: + path = get_home() + if path is not None: + path = os.path.join(path, '.cache') + return path def _get_config_or_cache_dir(xdg_base): @@ -568,9 +570,8 @@ def _get_config_or_cache_dir(xdg_base): h = get_home() if h is not None: 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 xdg_base): + p = os.path.join(xdg_base, 'matplotlib') if p is not None: if os.path.exists(p):