Skip to content

Commit ea61ca5

Browse files
committed
Merge pull request #5874 from tacaswell/enh_local_freetype_tweaks
Enh local freetype tweaks
2 parents 96fb4ea + dd559db commit ea61ca5

File tree

3 files changed

+100
-17
lines changed

3 files changed

+100
-17
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cache:
44
directories:
55
- $HOME/.ccache
66
- $HOME/.cache/pip
7+
- $HOME/.cache/matplotlib
78

89
addons:
910
apt:
@@ -127,6 +128,8 @@ script:
127128
touch build/html/Matplotlib.pdf
128129
linkchecker build/html/index.html
129130
fi
131+
- rm -rf $HOME/.cache/matplotlib/tex.cache
132+
- rm -rf $HOME/.cache/matplotlib/test_cache
130133

131134
after_failure:
132135
|

doc/devel/testing.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ matplotlib source directory::
4949
[test]
5050
local_freetype = True
5151

52+
or by setting the ``MPLLOCALFREETYPE`` environmental variable to any true
53+
value.
54+
5255
Running the tests
5356
-----------------
5457

@@ -65,7 +68,7 @@ commands, such as:
6568
``--no-network`` Disable tests that require network access
6669
======================== ===========
6770

68-
Additional arguments are passed on to nosetests. See the nose
71+
Additional arguments are passed on to nosetests. See the nose
6972
documentation for supported arguments. Some of the more important ones are given
7073
here:
7174

setupext.py

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from distutils import version
55
from distutils.core import Extension
66
import glob
7-
import io
87
import multiprocessing
98
import os
109
import re
@@ -13,14 +12,53 @@
1312
import sys
1413
import warnings
1514
from textwrap import fill
16-
15+
import shutil
1716
import versioneer
1817

1918

2019
PY3min = (sys.version_info[0] >= 3)
2120
PY32min = (PY3min and sys.version_info[1] >= 2 or sys.version_info[0] > 3)
2221

2322

23+
def _get_home():
24+
"""Find user's home directory if possible.
25+
Otherwise, returns None.
26+
27+
:see:
28+
http://mail.python.org/pipermail/python-list/2005-February/325395.html
29+
"""
30+
try:
31+
if not PY3min and sys.platform == 'win32':
32+
path = os.path.expanduser(b"~").decode(sys.getfilesystemencoding())
33+
else:
34+
path = os.path.expanduser("~")
35+
except ImportError:
36+
# This happens on Google App Engine (pwd module is not present).
37+
pass
38+
else:
39+
if os.path.isdir(path):
40+
return path
41+
for evar in ('HOME', 'USERPROFILE', 'TMP'):
42+
path = os.environ.get(evar)
43+
if path is not None and os.path.isdir(path):
44+
return path
45+
return None
46+
47+
48+
def _get_xdg_cache_dir():
49+
"""
50+
Returns the XDG cache directory, according to the `XDG
51+
base directory spec
52+
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
53+
"""
54+
path = os.environ.get('XDG_CACHE_HOME')
55+
if path is None:
56+
path = _get_home()
57+
if path is not None:
58+
path = os.path.join(path, '.cache', 'matplotlib')
59+
return path
60+
61+
2462
# This is the version of FreeType to use when building a local
2563
# version. It must match the value in
2664
# lib/matplotlib.__init__.py
@@ -70,10 +108,13 @@
70108
config.get("directories", "basedirlist").split(',')]
71109

72110
if config.has_option('test', 'local_freetype'):
73-
options['local_freetype'] = config.get("test", "local_freetype")
111+
options['local_freetype'] = config.getboolean("test", "local_freetype")
74112
else:
75113
config = None
76114

115+
lft = bool(os.environ.get('MPLLOCALFREETYPE', False))
116+
options['local_freetype'] = lft or options.get('local_freetype', False)
117+
77118

78119
def get_win32_compiler():
79120
"""
@@ -978,26 +1019,62 @@ def do_custom_build(self):
9781019
'build', 'freetype-{0}'.format(LOCAL_FREETYPE_VERSION))
9791020

9801021
# We've already built freetype
981-
if os.path.isfile(os.path.join(src_path, 'objs', '.libs', 'libfreetype.a')):
1022+
if os.path.isfile(
1023+
os.path.join(src_path, 'objs', '.libs', 'libfreetype.a')):
9821024
return
9831025

9841026
tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)
9851027
tarball_path = os.path.join('build', tarball)
1028+
try:
1029+
tarball_cache_dir = _get_xdg_cache_dir()
1030+
tarball_cache_path = os.path.join(tarball_cache_dir, tarball)
1031+
except:
1032+
# again, do not really care if this fails
1033+
tarball_cache_dir = None
1034+
tarball_cache_path = None
9861035
if not os.path.isfile(tarball_path):
987-
tarball_url = 'http://download.savannah.gnu.org/releases/freetype/{0}'.format(tarball)
988-
989-
print("Downloading {0}".format(tarball_url))
990-
if sys.version_info[0] == 2:
991-
from urllib import urlretrieve
992-
else:
993-
from urllib.request import urlretrieve
994-
995-
if not os.path.exists('build'):
996-
os.makedirs('build')
997-
urlretrieve(tarball_url, tarball_path)
1036+
if (tarball_cache_path is not None and
1037+
os.path.isfile(tarball_cache_path)):
1038+
if get_file_hash(tarball_cache_path) == LOCAL_FREETYPE_HASH:
1039+
try:
1040+
# fail on Lpy, oh well
1041+
os.makedirs('build', exist_ok=True)
1042+
shutil.copy(tarball_cache_path, tarball_path)
1043+
print('Using cached tarball: {}'
1044+
.format(tarball_cache_path))
1045+
except:
1046+
# If this fails, oh well just re-download
1047+
pass
1048+
1049+
if not os.path.isfile(tarball_path):
1050+
url_fmt = (
1051+
'http://download.savannah.gnu.org/releases/freetype/{0}')
1052+
tarball_url = url_fmt.format(tarball)
1053+
1054+
print("Downloading {0}".format(tarball_url))
1055+
if sys.version_info[0] == 2:
1056+
from urllib import urlretrieve
1057+
else:
1058+
from urllib.request import urlretrieve
1059+
1060+
if not os.path.exists('build'):
1061+
os.makedirs('build')
1062+
urlretrieve(tarball_url, tarball_path)
1063+
if get_file_hash(tarball_path) == LOCAL_FREETYPE_HASH:
1064+
try:
1065+
# this will fail on LPy, oh well
1066+
os.makedirs(tarball_cache_dir, exist_ok=True)
1067+
shutil.copy(tarball_cache_path, tarball_path)
1068+
print('Cached tarball at: {}'
1069+
.format(tarball_cache_path))
1070+
except:
1071+
# again, we do not care if this fails, can
1072+
# always re download
1073+
pass
9981074

9991075
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
1000-
raise IOError("{0} does not match expected hash.".format(tarball))
1076+
raise IOError(
1077+
"{0} does not match expected hash.".format(tarball))
10011078

10021079
print("Building {0}".format(tarball))
10031080
cflags = 'CFLAGS="{0} -fPIC" '.format(os.environ.get('CFLAGS', ''))

0 commit comments

Comments
 (0)