Skip to content

Commit a4356e8

Browse files
committed
Allow linking against a system qhull as well.
1 parent 5d6f889 commit a4356e8

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

INSTALL.rst

+15-12
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ Dependencies
109109
Matplotlib requires the following dependencies:
110110

111111
* `Python <https://www.python.org/downloads/>`_ (>= 3.6)
112-
* `FreeType <https://www.freetype.org/>`_ (>= 2.3)
113112
* `NumPy <http://www.numpy.org>`_ (>= 1.11)
114113
* `setuptools <https://setuptools.readthedocs.io/en/latest/>`_
115114
* `cycler <http://matplotlib.org/cycler/>`_ (>= 0.10.0)
@@ -154,24 +153,27 @@ etc., you can install the following:
154153
* `LaTeX <https://miktex.org/>`_ and `GhostScript (>=9.0)
155154
<https://ghostscript.com/download/>`_ : for rendering text with LaTeX.
156155

157-
FreeType
158-
--------
156+
FreeType and Qhull
157+
------------------
159158

160-
Matplotlib depends on FreeType, a font rendering library. By default,
161-
Matplotlib downloads and builds its own copy of FreeType.
159+
Matplotlib depends on `FreeType <https://www.freetype.org/>`_ (>= 2.3), a
160+
font rendering library, and on `Qhull <http://www.qhull.org/>`_ (>= 2015.2),
161+
a library for computing triangulations. By default, Matplotlib downloads and
162+
builds its own copy of FreeType, and uses its own copy of Qhull.
162163

163-
To force Matplotlib to use a copy of FreeType already installed in your system,
164-
create a :file:`setup.cfg` file with the following contents:
164+
To force Matplotlib to use a copy of FreeType or Qhull already installed in
165+
your system, create a :file:`setup.cfg` file with the following contents:
165166

166167
.. code-block:: cfg
167168
168169
[libs]
169170
system_freetype = true
171+
system_qhull = true
170172
171173
before running ``python -m pip install .``.
172174

173-
In this case, you need to install the FreeType library and headers. This can
174-
be achieved using a package manager:
175+
In this case, you need to install the FreeType and Qhull library and headers.
176+
This can be achieved using a package manager, e.g. for FreeType:
175177

176178
.. code-block:: sh
177179
@@ -181,6 +183,8 @@ be achieved using a package manager:
181183
brew install freetype # macOS with Homebrew
182184
conda install freetype # conda, any OS
183185
186+
(adapt accordingly for Qhull).
187+
184188
On Linux and macOS, it is also recommended to install pkg-config_, a helper
185189
tool for locating FreeType:
186190

@@ -197,7 +201,7 @@ tool for locating FreeType:
197201
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
198202

199203
If not using pkg-config (in particular on Windows), you may need to set the
200-
include path (to the FreeType headers) and link path (to the FreeType library)
204+
include path (to the library headers) and link path (to the libraries)
201205
explicitly, if they are not in standard locations. This can be done using
202206
standard environment variables -- on Linux and OSX:
203207

@@ -215,10 +219,9 @@ and on Windows:
215219
216220
.. note::
217221

218-
The following libraries are shipped with Matplotlib:
222+
Matplotlib always uses its own copies of the following libraries:
219223

220224
- ``Agg``: the Anti-Grain Geometry C++ rendering engine;
221-
- ``qhull``: to compute Delaunay triangulation;
222225
- ``ttconv``: a TrueType font utility.
223226

224227
Building on Windows

setup.cfg.template

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
[egg_info]
55

66
[libs]
7-
# By default, Matplotlib downloads and builds its own copy of FreeType. You
8-
# may set the following variable to True to instead link against a system
9-
# FreeType.
7+
# By default, Matplotlib downloads and builds its own copy of FreeType, and
8+
# builds its own copy of Qhull. You may set the following to True to instead
9+
# link against a system FreeType/Qhull.
1010
#system_freetype = False
11+
#system_qhull = False
1112

1213
[packages]
1314
# There are a number of data subpackages from Matplotlib that are

setupext.py

+16-20
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,17 @@ def write_cache(local_fn, data):
149149

150150

151151
# matplotlib build options, which can be altered using setup.cfg
152-
options = {
153-
'backend': None,
154-
}
155-
156-
157152
setup_cfg = os.environ.get('MPLSETUPCFG', 'setup.cfg')
153+
config = configparser.ConfigParser()
158154
if os.path.exists(setup_cfg):
159-
config = configparser.ConfigParser()
160155
config.read(setup_cfg)
161-
options['backend'] = config.get('rc_options', 'backend', fallback=None)
162-
options['system_freetype'] = config.getboolean('libs', 'system_freetype',
163-
fallback=False)
164-
else:
165-
config = None
156+
options = {
157+
'backend': config.get('rc_options', 'backend', fallback=None),
158+
'system_freetype': config.getboolean('libs', 'system_freetype',
159+
fallback=False),
160+
'system_qhull': config.getboolean('libs', 'system_qhull',
161+
fallback=False),
162+
}
166163

167164

168165
if '-q' in sys.argv or '--quiet' in sys.argv:
@@ -318,8 +315,7 @@ def get_config(cls):
318315
insensitively defined as 0, false, no, off for False).
319316
"""
320317
conf = cls.default_config
321-
if (config is not None
322-
and config.has_option(cls.config_category, cls.name)):
318+
if config.has_option(cls.config_category, cls.name):
323319
try:
324320
conf = config.getboolean(cls.config_category, cls.name)
325321
except ValueError:
@@ -614,13 +610,13 @@ class Qhull(SetupPackage):
614610
name = "qhull"
615611

616612
def add_flags(self, ext):
617-
# Qhull doesn't distribute pkg-config info, so we have no way of
618-
# knowing whether a system install is recent enough. Thus, always use
619-
# the vendored version.
620-
ext.include_dirs.insert(0, 'extern')
621-
ext.sources.extend(sorted(glob.glob('extern/libqhull/*.c')))
622-
if sysconfig.get_config_var('LIBM') == '-lm':
623-
ext.libraries.extend('m')
613+
if options.get('system_qhull'):
614+
ext.libraries.append('qhull')
615+
else:
616+
ext.include_dirs.insert(0, 'extern')
617+
ext.sources.extend(sorted(glob.glob('extern/libqhull/*.c')))
618+
if sysconfig.get_config_var('LIBM') == '-lm':
619+
ext.libraries.extend('m')
624620

625621

626622
class TTConv(SetupPackage):

0 commit comments

Comments
 (0)