Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cf10f8

Browse files
committed
Simplify _get_xdg_cache_dir in setupext.
1. we don't support google app engine anymore. 2. in setupext, the cache dir is only used to cache the freetype tarball, so it's really not a huge deal if a cache dir cannot be located (this case is handled explicitly by the freetype build code).
1 parent f4b1a61 commit 5cf10f8

File tree

1 file changed

+9
-34
lines changed

1 file changed

+9
-34
lines changed

setupext.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,18 @@
2323
PY3min = (sys.version_info[0] >= 3)
2424

2525

26-
def _get_home():
27-
"""Find user's home directory if possible.
28-
Otherwise, returns None.
29-
30-
:see:
31-
http://mail.python.org/pipermail/python-list/2005-February/325395.html
32-
"""
33-
try:
34-
if not PY3min and sys.platform == 'win32':
35-
path = os.path.expanduser(b"~").decode(sys.getfilesystemencoding())
36-
else:
37-
path = os.path.expanduser("~")
38-
except ImportError:
39-
# This happens on Google App Engine (pwd module is not present).
40-
pass
41-
else:
42-
if os.path.isdir(path):
43-
return path
44-
for evar in ('HOME', 'USERPROFILE', 'TMP'):
45-
path = os.environ.get(evar)
46-
if path is not None and os.path.isdir(path):
47-
return path
48-
return None
49-
50-
5126
def _get_xdg_cache_dir():
5227
"""
53-
Returns the XDG cache directory, according to the `XDG
54-
base directory spec
55-
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
28+
Return the XDG cache directory.
29+
30+
See https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
5631
"""
57-
path = os.environ.get('XDG_CACHE_HOME')
58-
if path is None:
59-
path = _get_home()
60-
if path is not None:
61-
path = os.path.join(path, '.cache', 'matplotlib')
62-
return path
32+
cache_dir = os.environ.get('XDG_CACHE_HOME')
33+
if not cache_dir:
34+
cache_dir = os.path.expanduser('~/.cache')
35+
if cache_dir.startswith('~/'): # Expansion failed.
36+
return None
37+
return os.path.join(cache_dir, 'matplotlib')
6338

6439

6540
# SHA256 hashes of the FreeType tarballs

0 commit comments

Comments
 (0)