Skip to content

Commit 014aa5b

Browse files
authored
Merge pull request #15569 from anntzer/system_qhull
Allow linking against a system qhull as well.
2 parents 4ddf004 + a4356e8 commit 014aa5b

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)
@@ -153,24 +152,27 @@ etc., you can install the following:
153152
* `LaTeX <https://miktex.org/>`_ and `GhostScript (>=9.0)
154153
<https://ghostscript.com/download/>`_ : for rendering text with LaTeX.
155154

156-
FreeType
157-
--------
155+
FreeType and Qhull
156+
------------------
158157

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

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

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

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

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

@@ -196,7 +200,7 @@ tool for locating FreeType:
196200
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
197201

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

@@ -214,10 +218,9 @@ and on Windows:
214218
215219
.. note::
216220

217-
The following libraries are shipped with Matplotlib:
221+
Matplotlib always uses its own copies of the following libraries:
218222

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

223226
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)