Skip to content

matplotlib interface does not correctly set up when set up with UPS #56

@chenel

Description

@chenel

Unfortunately, the $MPLCONFIGDIR mechanism used to instruct matplotlib where to look for stylesheets also sets the cache directory. Because in the UPS implementation this is a read-only directory, matplotlib re-sets this to a different, temporary directory upon startup, which then makes it unable to find the style file. Example invocation on a DUNE gpvm:

$ source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh
Setting up larsoft UPS area... /cvmfs/larsoft.opensciencegrid.org
Setting up DUNE UPS area... /cvmfs/dune.opensciencegrid.org/products/dune/
$ setup duneutil v10_11_00d00 -q e26:prof
$ setup dune_plot_style v01_02
$ python3
Python 3.9.15 (main, Feb  8 2023, 11:36:31) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dunestyle import matplotlib as dunestyle
Matplotlib created a temporary cache directory at /tmp/matplotlib-mv9gap30 because the default path (/cvmfs/dune.opensciencegrid.org/products/dune/dune_plot_style/v01_02/stylelib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/cvmfs/dune.opensciencegrid.org/products/dune/dune_plot_style/v01_02/python/dunestyle/matplotlib/__init__.py", line 18, in <module>
    from .dunestyle import *
  File "/cvmfs/dune.opensciencegrid.org/products/dune/dune_plot_style/v01_02/python/dunestyle/matplotlib/dunestyle.py", line 33, in <module>
    enable()
  File "/cvmfs/dune.opensciencegrid.org/products/dune/dune_plot_style/v01_02/python/dunestyle/matplotlib/dunestyle.py", line 25, in enable
    assert os.path.exists(path), "Can't locate DUNE matplotlib style sheet file!  I tried path: " + path
AssertionError: Can't locate DUNE matplotlib style sheet file!  I tried path: /tmp/matplotlib-mv9gap30/dune.mplstyle
>>> 

Matplotlib 3.7 (2022) introduced a better mechanism for custom stylesheets. This should be adopted by dune_plot_style. Changes are relatively simple:

  • instead of installing the src/matplotlib/stylelib file into its own directory, install its contents into the same directory as the __init__.py
  • eliminate the setting of $MPLCONFIGDIR in the UPS files
  • make matplotlib an optional dependency, but specify the version as >= 3.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions