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

Skip to content

Commit 01b5833

Browse files
authored
Merge pull request #15378 from anntzer/zless
Don't link ft2font to zlib by default.
2 parents cfd52eb + f3165b7 commit 01b5833

6 files changed

+67
-163
lines changed

.appveyor.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ install:
6060
# if conda-forge gets a new pyqt, it might be nice to install it as well to have more backends
6161
# https://github.com/conda-forge/conda-forge.github.io/issues/157#issuecomment-223536381
6262
- conda create -q -n test-environment python=%PYTHON_VERSION%
63-
freetype=2.6 zlib=1.2 tk=8.5
63+
freetype=2.6 tk=8.5
6464
pip setuptools numpy sphinx tornado
6565
- activate test-environment
6666
- echo %PYTHON_VERSION% %TARGET_ARCH%
@@ -81,9 +81,9 @@ test_script:
8181
# Now build the thing..
8282
- set LINK=/LIBPATH:%cd%\lib
8383
- pip install -ve .
84-
# these should show no z or freetype dll...
84+
# this should show no freetype dll...
8585
- set "DUMPBIN=%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe"
86-
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'
86+
- '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'
8787

8888
# this are optional dependencies so that we don't skip so many tests...
8989
- if x%TEST_ALL% == xyes conda install -q ffmpeg inkscape miktex pillow
@@ -98,9 +98,8 @@ test_script:
9898
- pytest %PYTEST_ARGS%
9999

100100
after_test:
101-
# After the tests were a success, build wheels with the static libs
101+
# After the tests were a success, build wheels.
102102
# Hide the output, the copied files really clutter the build log...
103-
- set MPLSTATICBUILD=True
104103
- 'python setup.py bdist_wheel > NUL:'
105104
- dir dist\
106105
- echo finished...

INSTALL.rst

Lines changed: 52 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ toolchain is prefixed. This may be used for cross compiling. ::
9898
export CXX=x86_64-pc-linux-gnu-g++
9999
export PKG_CONFIG=x86_64-pc-linux-gnu-pkg-config
100100

101-
Once you have satisfied the requirements detailed below (mainly
102-
Python, NumPy, and FreeType), you can build Matplotlib.
101+
Once you have satisfied the requirements detailed below (i.e., Python and
102+
FreeType), you can build Matplotlib.
103103
::
104104

105105
cd matplotlib
@@ -165,101 +165,78 @@ etc., you can install the following:
165165
* `LaTeX <https://miktex.org/>`_ and `GhostScript (>=9.0)
166166
<https://ghostscript.com/download/>`_ : for rendering text with LaTeX.
167167

168-
.. note::
169-
170-
Matplotlib depends on non-Python libraries.
168+
FreeType
169+
--------
171170

172-
On Linux and OSX, pkg-config_ can be used to find required non-Python
173-
libraries and thus make the install go more smoothly if the libraries and
174-
headers are not in the expected locations.
171+
Matplotlib depends on FreeType, a font rendering library. It can either
172+
download and build its own copy of the library, or use a copy of FreeType
173+
already installed in your system.
175174

176-
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
175+
The easiest option is to make Matplotlib download and build FreeType. This is
176+
done by setting the :envvar:`MPLLOCALFREETYPE` environment variable to 1 -- on
177+
Linux and OSX:
177178

178-
If not using pkg-config (in particular on Windows), you may need to set the
179-
include path (to the FreeType and zlib headers) and link path (to
180-
the FreeType and zlib libraries) explicitly, if they are not in
181-
standard locations. This can be done using standard environment variables
182-
-- on Linux and OSX:
179+
.. code-block:: sh
183180
184-
.. code-block:: sh
181+
export MPLLOCALFREETYPE=1
185182
186-
export CFLAGS='-I/directory/containing/ft2build.h ...'
187-
export LDFLAGS='-L/directory/containing/libfreetype.so ...'
183+
and on Windows:
188184

189-
and on Windows:
185+
.. code-block:: bat
190186
191-
.. code-block:: bat
187+
set MPLLOCALFREETYPE=1
192188
193-
set CL=/IC:\directory\containing\ft2build.h ...
194-
set LINK=/LIBPATH:C:\directory\containing\freetype.lib ...
189+
and you can continue the installation (``python -m pip install .``), ignoring
190+
everything that follows.
195191

196-
where ``...`` means "also give, in the same format, the directories
197-
containing ``zlib.h`` for the include path, and for
198-
``libz.so``/``z.lib`` for the link path."
199-
200-
.. note::
192+
If you wish, instead, to use the system FreeType, you need to install the
193+
FreeType library and headers. This can be achieved using a package manager:
201194

202-
The following libraries are shipped with Matplotlib:
195+
.. code-block:: sh
203196
204-
- ``Agg``: the Anti-Grain Geometry C++ rendering engine;
205-
- ``qhull``: to compute Delaunay triangulation;
206-
- ``ttconv``: a TrueType font utility.
197+
# Pick ONE of the following:
198+
sudo apt install libfreetype6-dev # Debian/Ubuntu
199+
sudo dnf install freetype-devel # Fedora
200+
brew install freetype # macOS with Homebrew
201+
conda install freetype # conda, any OS
207202
208-
.. _build_linux:
203+
On Linux and macOS, it is also recommended to install pkg-config_, a helper
204+
tool for locating FreeType:
209205

210-
Building on Linux
211-
-----------------
206+
.. code-block:: sh
212207
213-
It is easiest to use your system package manager to install the dependencies.
208+
# Pick ONE of the following:
209+
sudo apt install pkg-config # Debian/Ubuntu
210+
sudo dnf install pkgconf # Fedora
211+
brew install pkg-config # macOS with Homebrew
212+
conda install pkg-config # conda
214213
215-
If you are on Debian/Ubuntu, you can get all the dependencies
216-
required to build Matplotlib with::
214+
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
217215

218-
sudo apt-get build-dep python-matplotlib
216+
If not using pkg-config (in particular on Windows), you may need to set the
217+
include path (to the FreeType headers) and link path (to the FreeType library)
218+
explicitly, if they are not in standard locations. This can be done using
219+
standard environment variables -- on Linux and OSX:
219220

220-
If you are on Fedora, you can get all the dependencies required to build
221-
Matplotlib with::
221+
.. code-block:: sh
222222
223-
sudo dnf builddep python-matplotlib
223+
export CFLAGS='-I/directory/containing/ft2build.h'
224+
export LDFLAGS='-L/directory/containing/libfreetype.so'
224225
225-
If you are on RedHat, you can get all the dependencies required to build
226-
Matplotlib by first installing ``yum-builddep`` and then running::
226+
and on Windows:
227227

228-
su -c "yum-builddep python-matplotlib"
228+
.. code-block:: bat
229229
230-
These commands do not build Matplotlib, but instead get and install the
231-
build dependencies, which will make building from source easier.
230+
set CL=/IC:\directory\containing\ft2build.h
231+
set LINK=/LIBPATH:C:\directory\containing\freetype.lib
232232
233-
.. _build_osx:
234-
235-
Building on macOS
236-
-----------------
237-
238-
The build situation on macOS is complicated by the various places one
239-
can get FreeType (MacPorts, Fink,
240-
/usr/X11R6), the different architectures (e.g., x86, ppc, universal), and
241-
the different macOS versions (e.g., 10.4 and 10.5). We recommend that you build
242-
the way we do for the macOS release: get the source from the tarball or the
243-
git repository and install the required dependencies through a third-party
244-
package manager. Two widely used package managers are Homebrew, and MacPorts.
245-
The following example illustrates how to install FreeType using
246-
``brew``::
247-
248-
brew install freetype pkg-config
249-
250-
If you are using MacPorts, execute the following instead::
251-
252-
port install freetype pkgconfig
253-
254-
After installing the above requirements, install Matplotlib from source by
255-
executing::
233+
.. note::
256234

257-
python -m pip install .
235+
The following libraries are shipped with Matplotlib:
258236

259-
Note that your environment is somewhat important. Some conda users have
260-
found that, to run the tests, their PYTHONPATH must include
261-
/path/to/anaconda/.../site-packages and their DYLD_FALLBACK_LIBRARY_PATH
262-
must include /path/to/anaconda/lib.
237+
- ``Agg``: the Anti-Grain Geometry C++ rendering engine;
238+
- ``qhull``: to compute Delaunay triangulation;
239+
- ``ttconv``: a TrueType font utility.
263240

264241
.. _build_windows:
265242

@@ -269,42 +246,14 @@ Building on Windows
269246
The Python shipped from https://www.python.org is compiled with Visual Studio
270247
2015 for 3.5+. Python extensions should be compiled with the same
271248
compiler, see e.g.
272-
https://packaging.python.org/guides/packaging-binary-extensions/#setting-up-a-build-environment-on-windows
249+
https://packaging.python.org/guides/packaging-binary-extensions/#binary-extensions-for-windows
273250
for how to set up a build environment.
274251

275-
Since there is no canonical Windows package manager, the methods for building
276-
FreeType and zlib from source code are documented as a build script
277-
at `matplotlib-winbuild <https://github.com/jbmohler/matplotlib-winbuild>`_.
278-
279-
There are a few possibilities to build Matplotlib on Windows:
280-
281-
* Wheels via `matplotlib-winbuild <https://github.com/jbmohler/matplotlib-winbuild>`_
282-
* Wheels by using conda packages (see below)
283-
* Conda packages (see below)
284-
285252
If you are building your own Matplotlib wheels (or sdists), note that any DLLs
286253
that you copy into the source tree will be packaged too.
287254

288-
Wheel builds using conda packages
289-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
290-
291-
This is a wheel build, but we use conda packages to get all the requirements.
292-
FreeType is statically linked and therefore not needed during the wheel install.
293-
294-
Set up the conda environment. Note, if you want a qt backend, add ``pyqt`` to
295-
the list of conda packages.
296-
297-
::
298-
299-
conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk zlib freetype
300-
conda activate matplotlib_build
301-
# force the build against static zlib libraries
302-
set MPLSTATICBUILD=True
303-
python setup.py bdist_wheel
304-
305-
306255
Conda packages
307-
^^^^^^^^^^^^^^
256+
--------------
308257

309258
The conda packaging scripts for Matplotlib are available at
310259
https://github.com/conda-forge/matplotlib-feedstock.

ci/azure-pipelines-steps.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ steps:
1616
prerelease: true
1717
condition: and(succeeded(), eq(variables['python.version'], 'Pre'))
1818

19-
- ${{ if eq(parameters.installer, 'nuget') }}:
20-
- task: NuGetToolInstaller@0
21-
displayName: 'Use latest available Nuget'
22-
23-
- script: |
24-
nuget install zlib-msvc14-x64 -ExcludeVersion -OutputDirectory "$(build.BinariesDirectory)"
25-
echo ##vso[task.prependpath]$(build.BinariesDirectory)\zlib-msvc14-x64\build\native\bin_release
26-
27-
displayName: 'Install dependencies with nuget'
28-
2919
- ${{ if eq(parameters.installer, 'brew') }}:
3020
- script: |
3121
brew cask install xquartz

doc/faq/environment_variables_faq.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ Environment Variables
3131
defined, :file:`{HOME}/.config/matplotlib` is generally used on unix-like
3232
systems and :file:`{HOME}/.matplotlib` is used on other platforms, if they are
3333
writable. Otherwise, the python standard library :func:`tempfile.gettempdir`
34-
is used to find a base directory in which the :file:`matplotlib` subdirectory
34+
is used to find a base directory in which the :file:`matplotlib` subdirectory
3535
is created.
3636

37+
.. envvar:: MPLLOCALFREETYPE
38+
39+
If set, this environment variable directs Matplotlib's build script to
40+
download and build its own copy of the FreeType library.
41+
3742
.. envvar:: PATH
3843

3944
The list of directories searched to find executable programs.

doc/faq/installing_faq.rst

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,13 @@ or::
182182

183183
git clone git://github.com/matplotlib/matplotlib.git
184184

185-
and build and install as usual with::
185+
and build and install with::
186186

187187
cd matplotlib
188+
export MPLLOCALFREETYPE=1 # on Linux and OSX.
189+
set MPLLOCALFREETYPE=1 # on Windows.
188190
python -mpip install .
189191

190-
.. note::
191-
192-
If you are on Debian/Ubuntu, you can get all the dependencies required to
193-
build Matplotlib with::
194-
195-
sudo apt-get build-dep python-matplotlib
196-
197-
If you are on Fedora/RedHat, you can get all the dependencies required to
198-
build Matplotlib by first installing ``yum-builddep`` and then running::
199-
200-
su -c 'yum-builddep python-matplotlib'
201-
202-
This does not build Matplotlib, but it does get all of the build
203-
dependencies, which will make building from source easier.
204-
205192
If you want to be able to follow the development branch as it changes
206193
just replace the last step with::
207194

@@ -211,8 +198,6 @@ This creates links and installs the command line script in the appropriate
211198
places.
212199

213200
.. note::
214-
OSX users please see the :ref:`build_osx` guide.
215-
216201
Windows users please see the :ref:`build_windows` guide.
217202

218203
Then, if you want to update your Matplotlib at any time, just do::

setupext.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -151,32 +151,23 @@ def write_cache(local_fn, data):
151151
# matplotlib build options, which can be altered using setup.cfg
152152
options = {
153153
'backend': None,
154-
'staticbuild': False,
155-
}
154+
}
156155

157156

158157
setup_cfg = os.environ.get('MPLSETUPCFG', 'setup.cfg')
159158
if os.path.exists(setup_cfg):
160159
config = configparser.ConfigParser()
161160
config.read(setup_cfg)
162-
163161
if config.has_option('rc_options', 'backend'):
164162
options['backend'] = config.get("rc_options", "backend")
165-
166163
if config.has_option('test', 'local_freetype'):
167164
options['local_freetype'] = config.getboolean("test", "local_freetype")
168-
169-
if config.has_option('build', 'staticbuild'):
170-
options['staticbuild'] = config.getboolean("build", "staticbuild")
171165
else:
172166
config = None
173167

174168
lft = bool(os.environ.get('MPLLOCALFREETYPE', False))
175169
options['local_freetype'] = lft or options.get('local_freetype', False)
176170

177-
staticbuild = bool(os.environ.get('MPLSTATICBUILD', os.name == 'nt'))
178-
options['staticbuild'] = staticbuild or options.get('staticbuild', False)
179-
180171

181172
if '-q' in sys.argv or '--quiet' in sys.argv:
182173
def print_raw(*args, **kwargs): pass # Suppress our own output.
@@ -202,21 +193,6 @@ def get_buffer_hash(fd):
202193
return hasher.hexdigest()
203194

204195

205-
def deplib(libname):
206-
if sys.platform != 'win32':
207-
return libname
208-
209-
known_libs = {
210-
'z': ('zlib', 'static'),
211-
}
212-
213-
libname, static_postfix = known_libs[libname]
214-
if options['staticbuild']:
215-
libname += static_postfix
216-
217-
return libname
218-
219-
220196
@functools.lru_cache(1) # We only need to compute this once.
221197
def get_pkg_config():
222198
"""
@@ -521,7 +497,7 @@ def add_flags(self, ext):
521497
ext, 'freetype2',
522498
atleast_version='9.11.3',
523499
alt_exec=['freetype-config'],
524-
default_libraries=['freetype', deplib('z')])
500+
default_libraries=['freetype'])
525501
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))
526502

527503
def do_custom_build(self):

0 commit comments

Comments
 (0)