Misleading installation instructions in INSTALL file

[Brought conversation back to matplotlib-devel list].

Mario Oschwald wrote:

Hello

Michael Droettboom wrote:

Mario Oschwald wrote:

This passage in the INSTALL file is misleading:

Note that if you install matplotlib anywhere other than the default
location, you will need to set the MATPLOTLIBDATA environment
variable to point to the install base dir.

Was that necessary? I routinely install matplotlib to a non-standard
location, and have never set MATPLOTLIBDATA. If MATPLOTLIBDATA is not
set, it appears that matplotlib will look for the "mpl-data" directory
underneath the main matplotlib directory. (Which in your case is
/home/mo/mpl/lib/python2.4/site-packages/matplotlib/). I'm curious if
you get errors without specifying MATPLOTLIBDATA, and what the error is.
Perhaps the INSTALL docs should be updated to clarify that you only
need this if you install the data in a non-standard place *relative to*
the source code...

You are right - if I unset that variable the mpl-data directory is found
automagically :wink: Stupid me for reading INSTALL files :-). That passage
should definitely be updated to reflect that behaviour.

I'm +1 on just removing the paragraph altogether. It only applies if someone did:

  python setup.py install --install-data=/some/weird/place

Is that a common enough use case to confuse the matter? (Obviously MATPLOTLIBDATA should be mentioned elsewhere in the docs, but it seems too unimportant for the main INSTALL file.)

Secondly this passage in matplotlib/mathtext.py

544 if cached_font is None:
545 try:
546 font = FT2Font(basename)
547 except RuntimeError:
548 return None

The intent of this code is "if the font isn't found, use a dummy
character." Since there are so many different font configurations, and
they're all a little brittle, I thought it better to warn and fail
gracefully than to fail completely (and users can always use the "-We"
to fail on warnings.) Otherwise, we run the risk of having some plots
not working on all installations (because of font limitations, etc.)

However, the implementation isn't quite right because not all callers
expect and deal with the 'None' result correctly. I have fixed this in
-r4557. Can you please send a script that triggers this error, so I can
ensure my patch corrects for it?

OK, I can understand that. If you set the MATPLOTLIBDATA environment variable
to some wrong directory and the font file is not found it crashes right here
when trying to access the returned None object without a prior check:

669 if symbol_name is None:
670 warn("Unrecognized symbol '%s'. Substituting with a dummy symbol."
671 % sym.encode('ascii', 'backslashreplace'), MathTextWarning)
672 fontname = 'it'
673 cached_font = self._get_font(fontname)
674 num = 0x3F # currency character, for lack of anything better
->675 gid = cached_font.charmap[num]

Snipped stacktrace below:
/home/mo/mpl/lib/python2.4/site-packages/matplotlib/mathtext.py:671: MathTextWarning: Unrecognized symbol 'e'. Substituting with a dummy symbol.
  % sym.encode('ascii', 'backslashreplace'), MathTextWarning)
IN FONTMAP
---lots of parsing---
File "/home/mo/mpl/lib/python2.4/site-packages/matplotlib/mathtext.py", line 2243, in symbol
    char = Char(c, self.get_state())
  File "/home/mo/mpl/lib/python2.4/site-packages/matplotlib/mathtext.py", line 1211, in __init__
    self._update_metrics()
  File "/home/mo/mpl/lib/python2.4/site-packages/matplotlib/mathtext.py", line 1217, in _update_metrics
    metrics = self._metrics = self.font_output.get_metrics(
  File "/home/mo/mpl/lib/python2.4/site-packages/matplotlib/mathtext.py", line 464, in get_metrics
    info = self._get_info(font, font_class, sym, fontsize, dpi)
  File "/home/mo/mpl/lib/python2.4/site-packages/matplotlib/mathtext.py", line 567, in _get_info
    cached_font, num, symbol_name, fontsize, slanted = \
  File "/home/mo/mpl/lib/python2.4/site-packages/matplotlib/mathtext.py", line 675, in _get_glyph
    gid = cached_font.charmap[num]
AttributeError: 'NoneType' object has no attribute 'charmap'

You can trigger it with the attached script, provided you set the MATPLOTLIBDATA to something
bad or remove the font file all together.

Thanks. r4557 fixes this. There will probably be another bugfix release (0.91.2 or something) in the near future that includes this change.

Cheers,
Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Yes, it should be removed. It predates the move of the data to
mpl-data in the matplotlib installation directory, and isn't really
needed anymore.

JDH

···

On Dec 3, 2007 9:10 AM, Michael Droettboom <mdroe@...31...> wrote:

I'm +1 on just removing the paragraph altogether. It only applies if
someone did:

        python setup.py install --install-data=/some/weird/place