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

Skip to content

Don't link ft2font to zlib by default. #15378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ install:
# if conda-forge gets a new pyqt, it might be nice to install it as well to have more backends
# https://github.com/conda-forge/conda-forge.github.io/issues/157#issuecomment-223536381
- conda create -q -n test-environment python=%PYTHON_VERSION%
freetype=2.6 zlib=1.2 tk=8.5
freetype=2.6 tk=8.5
pip setuptools numpy sphinx tornado
- activate test-environment
- echo %PYTHON_VERSION% %TARGET_ARCH%
Expand All @@ -81,9 +81,9 @@ test_script:
# Now build the thing..
- set LINK=/LIBPATH:%cd%\lib
- pip install -ve .
# these should show no z or freetype dll...
# this should show no freetype dll...
- set "DUMPBIN=%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe"
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'
- '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'

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

after_test:
# After the tests were a success, build wheels with the static libs
# After the tests were a success, build wheels.
# Hide the output, the copied files really clutter the build log...
- set MPLSTATICBUILD=True
- 'python setup.py bdist_wheel > NUL:'
- dir dist\
- echo finished...
Expand Down
155 changes: 52 additions & 103 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ toolchain is prefixed. This may be used for cross compiling. ::
export CXX=x86_64-pc-linux-gnu-g++
export PKG_CONFIG=x86_64-pc-linux-gnu-pkg-config

Once you have satisfied the requirements detailed below (mainly
Python, NumPy, and FreeType), you can build Matplotlib.
Once you have satisfied the requirements detailed below (i.e., Python and
FreeType), you can build Matplotlib.
::

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

.. note::

Matplotlib depends on non-Python libraries.
FreeType
--------

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

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

If not using pkg-config (in particular on Windows), you may need to set the
include path (to the FreeType and zlib headers) and link path (to
the FreeType and zlib libraries) explicitly, if they are not in
standard locations. This can be done using standard environment variables
-- on Linux and OSX:
.. code-block:: sh

.. code-block:: sh
export MPLLOCALFREETYPE=1

export CFLAGS='-I/directory/containing/ft2build.h ...'
export LDFLAGS='-L/directory/containing/libfreetype.so ...'
and on Windows:

and on Windows:
.. code-block:: bat

.. code-block:: bat
set MPLLOCALFREETYPE=1

set CL=/IC:\directory\containing\ft2build.h ...
set LINK=/LIBPATH:C:\directory\containing\freetype.lib ...
and you can continue the installation (``python -m pip install .``), ignoring
everything that follows.

where ``...`` means "also give, in the same format, the directories
containing ``zlib.h`` for the include path, and for
``libz.so``/``z.lib`` for the link path."

.. note::
If you wish, instead, to use the system FreeType, you need to install the
FreeType library and headers. This can be achieved using a package manager:

The following libraries are shipped with Matplotlib:
.. code-block:: sh

- ``Agg``: the Anti-Grain Geometry C++ rendering engine;
- ``qhull``: to compute Delaunay triangulation;
- ``ttconv``: a TrueType font utility.
# Pick ONE of the following:
sudo apt install libfreetype6-dev # Debian/Ubuntu
sudo dnf install freetype-devel # Fedora
brew install freetype # macOS with Homebrew
conda install freetype # conda, any OS

.. _build_linux:
On Linux and macOS, it is also recommended to install pkg-config_, a helper
tool for locating FreeType:

Building on Linux
-----------------
.. code-block:: sh

It is easiest to use your system package manager to install the dependencies.
# Pick ONE of the following:
sudo apt install pkg-config # Debian/Ubuntu
sudo dnf install pkgconf # Fedora
brew install pkg-config # macOS with Homebrew
conda install pkg-config # conda

If you are on Debian/Ubuntu, you can get all the dependencies
required to build Matplotlib with::
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/

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

If you are on Fedora, you can get all the dependencies required to build
Matplotlib with::
.. code-block:: sh

sudo dnf builddep python-matplotlib
export CFLAGS='-I/directory/containing/ft2build.h'
export LDFLAGS='-L/directory/containing/libfreetype.so'

If you are on RedHat, you can get all the dependencies required to build
Matplotlib by first installing ``yum-builddep`` and then running::
and on Windows:

su -c "yum-builddep python-matplotlib"
.. code-block:: bat

These commands do not build Matplotlib, but instead get and install the
build dependencies, which will make building from source easier.
set CL=/IC:\directory\containing\ft2build.h
set LINK=/LIBPATH:C:\directory\containing\freetype.lib

.. _build_osx:

Building on macOS
-----------------

The build situation on macOS is complicated by the various places one
can get FreeType (MacPorts, Fink,
/usr/X11R6), the different architectures (e.g., x86, ppc, universal), and
the different macOS versions (e.g., 10.4 and 10.5). We recommend that you build
the way we do for the macOS release: get the source from the tarball or the
git repository and install the required dependencies through a third-party
package manager. Two widely used package managers are Homebrew, and MacPorts.
The following example illustrates how to install FreeType using
``brew``::

brew install freetype pkg-config

If you are using MacPorts, execute the following instead::

port install freetype pkgconfig

After installing the above requirements, install Matplotlib from source by
executing::
.. note::

python -m pip install .
The following libraries are shipped with Matplotlib:

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

.. _build_windows:

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

Since there is no canonical Windows package manager, the methods for building
FreeType and zlib from source code are documented as a build script
at `matplotlib-winbuild <https://github.com/jbmohler/matplotlib-winbuild>`_.

There are a few possibilities to build Matplotlib on Windows:

* Wheels via `matplotlib-winbuild <https://github.com/jbmohler/matplotlib-winbuild>`_
* Wheels by using conda packages (see below)
* Conda packages (see below)

If you are building your own Matplotlib wheels (or sdists), note that any DLLs
that you copy into the source tree will be packaged too.

Wheel builds using conda packages
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is a wheel build, but we use conda packages to get all the requirements.
FreeType is statically linked and therefore not needed during the wheel install.

Set up the conda environment. Note, if you want a qt backend, add ``pyqt`` to
the list of conda packages.

::

conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk zlib freetype
conda activate matplotlib_build
# force the build against static zlib libraries
set MPLSTATICBUILD=True
python setup.py bdist_wheel


Conda packages
^^^^^^^^^^^^^^
--------------

The conda packaging scripts for Matplotlib are available at
https://github.com/conda-forge/matplotlib-feedstock.
10 changes: 0 additions & 10 deletions ci/azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ steps:
prerelease: true
condition: and(succeeded(), eq(variables['python.version'], 'Pre'))

- ${{ if eq(parameters.installer, 'nuget') }}:
- task: NuGetToolInstaller@0
displayName: 'Use latest available Nuget'

- script: |
nuget install zlib-msvc14-x64 -ExcludeVersion -OutputDirectory "$(build.BinariesDirectory)"
echo ##vso[task.prependpath]$(build.BinariesDirectory)\zlib-msvc14-x64\build\native\bin_release

displayName: 'Install dependencies with nuget'

- ${{ if eq(parameters.installer, 'brew') }}:
- script: |
brew cask install xquartz
Expand Down
7 changes: 6 additions & 1 deletion doc/faq/environment_variables_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ Environment Variables
defined, :file:`{HOME}/.config/matplotlib` is generally used on unix-like
systems and :file:`{HOME}/.matplotlib` is used on other platforms, if they are
writable. Otherwise, the python standard library :func:`tempfile.gettempdir`
is used to find a base directory in which the :file:`matplotlib` subdirectory
is used to find a base directory in which the :file:`matplotlib` subdirectory
is created.

.. envvar:: MPLLOCALFREETYPE

If set, this environment variable directs Matplotlib's build script to
download and build its own copy of the FreeType library.

.. envvar:: PATH

The list of directories searched to find executable programs.
Expand Down
21 changes: 3 additions & 18 deletions doc/faq/installing_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,13 @@ or::

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

and build and install as usual with::
and build and install with::

cd matplotlib
export MPLLOCALFREETYPE=1 # on Linux and OSX.
set MPLLOCALFREETYPE=1 # on Windows.
python -mpip install .

.. note::

If you are on Debian/Ubuntu, you can get all the dependencies required to
build Matplotlib with::

sudo apt-get build-dep python-matplotlib

If you are on Fedora/RedHat, you can get all the dependencies required to
build Matplotlib by first installing ``yum-builddep`` and then running::

su -c 'yum-builddep python-matplotlib'

This does not build Matplotlib, but it does get all of the build
dependencies, which will make building from source easier.

If you want to be able to follow the development branch as it changes
just replace the last step with::

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

.. note::
OSX users please see the :ref:`build_osx` guide.

Windows users please see the :ref:`build_windows` guide.

Then, if you want to update your Matplotlib at any time, just do::
Expand Down
28 changes: 2 additions & 26 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,32 +151,23 @@ def write_cache(local_fn, data):
# matplotlib build options, which can be altered using setup.cfg
options = {
'backend': None,
'staticbuild': False,
}
}


setup_cfg = os.environ.get('MPLSETUPCFG', 'setup.cfg')
if os.path.exists(setup_cfg):
config = configparser.ConfigParser()
config.read(setup_cfg)

if config.has_option('rc_options', 'backend'):
options['backend'] = config.get("rc_options", "backend")

if config.has_option('test', 'local_freetype'):
options['local_freetype'] = config.getboolean("test", "local_freetype")

if config.has_option('build', 'staticbuild'):
options['staticbuild'] = config.getboolean("build", "staticbuild")
else:
config = None

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

staticbuild = bool(os.environ.get('MPLSTATICBUILD', os.name == 'nt'))
options['staticbuild'] = staticbuild or options.get('staticbuild', False)


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


def deplib(libname):
if sys.platform != 'win32':
return libname

known_libs = {
'z': ('zlib', 'static'),
}

libname, static_postfix = known_libs[libname]
if options['staticbuild']:
libname += static_postfix

return libname


@functools.lru_cache(1) # We only need to compute this once.
def get_pkg_config():
"""
Expand Down Expand Up @@ -521,7 +497,7 @@ def add_flags(self, ext):
ext, 'freetype2',
atleast_version='9.11.3',
alt_exec=['freetype-config'],
default_libraries=['freetype', deplib('z')])
default_libraries=['freetype'])
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))

def do_custom_build(self):
Expand Down