Skip to content

Commit

Permalink
Hooks: Fix matplotlib hooks to support matplotlib 3.3.0. (pyinstaller…
Browse files Browse the repository at this point in the history
…#5006)

This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes pyinstaller#5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue pyinstaller#5004) which
presumably isn't intentional.
  • Loading branch information
bwoodsend authored and orenadav committed Jul 26, 2021
1 parent a668e62 commit 0de3e80
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion PyInstaller/hooks/hook-matplotlib.py
Expand Up @@ -16,5 +16,5 @@
"import matplotlib; print(matplotlib._get_data_path())")

datas = [
(mpl_data_dir, "mpl-data"),
(mpl_data_dir, "matplotlib/mpl-data"),
]
2 changes: 1 addition & 1 deletion PyInstaller/loader/rthooks.dat
Expand Up @@ -11,7 +11,7 @@
'gst': ['pyi_rth_gstreamer.py'],
'kivy': ['pyi_rth_kivy.py'],
'kivy.lib.gstplayer': ['pyi_rth_gstreamer.py'],
'matplotlib': ['pyi_rth_mplconfig.py', 'pyi_rth_mpldata.py'],
'matplotlib': ['pyi_rth_mplconfig.py'],
'osgeo': ['pyi_rth_osgeo.py'],
'pkg_resources': ['pyi_rth_pkgres.py'],
'PyQt4': ['pyi_rth_qt4plugins.py'],
Expand Down
2 changes: 2 additions & 0 deletions news/5006.hooks.rst
@@ -0,0 +1,2 @@
Remove runtime hook and fix regular hook for matplotlib's data to support ``matplotlib>=3.3.0``, fix deprecation warning on version 3.1<= & <3.3,
and behave normally for versions <3.1.
8 changes: 1 addition & 7 deletions tests/functional/test_hooks/test_matplotlib.py
Expand Up @@ -109,13 +109,7 @@ def test_matplotlib(
if not configdir.startswith(tempfile.gettempdir()):
raise SystemExit('MPLCONFIGDIR not pointing to temp directory.')
# Matplotlib's data directory should point to sys._MEIPASS.
datadir = os.environ['MATPLOTLIBDATA']
print('MATPLOTLIBDATA: %s' % datadir)
if not datadir.startswith(sys._MEIPASS):
raise SystemExit('MATPLOTLIBDATA not pointing to sys._MEIPASS.')
# Test access to the standard "mpl_toolkits" namespace package installed
# Test access to the standard 'mpl_toolkits' namespace package installed
# with Matplotlib. Note that this import was reported to fail under
# Matplotlib 1.3.0.
from mpl_toolkits import axes_grid1
Expand Down

0 comments on commit 0de3e80

Please sign in to comment.