8000 Package initialization made possible when executed in environments wh… · matplotlib/matplotlib@98439df · GitHub
[go: up one dir, main page]

Skip to content

Commit 98439df

Browse files
committed
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).
1 parent ecdcc74 commit 98439df

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines change 10000 d

lib/matplotlib/__init__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,12 @@ def _get_xdg_config_dir():
531531
base directory spec
532532
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
533533
"""
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'))
534+
path = os.environ.get('XDG_CONFIG_HOME')
535+
if path is None:
536+
path = get_home()
537+
if path is not None:
538+
path = os.path.join(path, '.config')
539+
return path
539540

540541

541542
def _get_xdg_cache_dir():
@@ -544,11 +545,12 @@ def _get_xdg_cache_dir():
544545
base directory spec
545546
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
546547
"""
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'))
548+
path = os.environ.get('XDG_CACHE_HOME')
549+
if path is None:
550+
path = get_home()
551+
if path is not None:
552+
path = os.path.join(path, '.cache')
553+
return path
552554

553555

554556
def _get_config_or_cache_dir(xdg_base):
@@ -568,9 +570,8 @@ def _get_config_or_cache_dir(xdg_base):
568570
h = get_home()
569571
if h is not None:
570572
p = os.path.join(h, '.matplotlib')
571-
if (sys.platform.startswith('linux') and
572-
xdg_base is not None):
573-
p = os.path.join(xdg_base, 'matplotlib')
573+
if (sys.platform.startswith('linux') and xdg_base):
574+
p = os.path.join(xdg_base, 'matplotlib')
574575

575576
if p is not None:
576577
if os.path.exists(p):

0 commit comments

Comments
 (0)
0