Running tests on git master

I would like to get matplotlib master and run the tests. Despite all the information found online, e.g., https://matplotlib.org/devel/index.html, I was not able to do so.

What I’ve tried:

git clone git@github.com:matplotlib/matplotlib.git
cd matplotlib
pip3 install . --user
pytest

This fails with

E   ImportError: cannot import name 'ft2font' from 'matplotlib' (/home/nschloe/software/matplotlib/source-nschloe/lib/matplotlib/__init__.py)

If instead of pytest I run

python3 -c "import matplotlib; matplotlib.test()"

I’m getting

E   OSError: The baseline image directory does not exist. This is most likely because the test data is not installed. You may need to install matplotlib from source to get the test data.

I have no idea what’s going wrong. Any hints?

The process you should follow in documented at https://matplotlib.org/devel/contributing.html#installing-matplotlib-in-developer-mode .

--user is pip installings things “globally” which can cause havoc when working with virtual enviroments and multiple versions of Python.

The source of both of those issues is that by not passing -e you have fully installed Matplotlib. In the first case pytest is finding the source files, trying to import them and failing because the built modules are not in the right place for pytest to find them (they are in the right place if you were to just import matplotlib). This is a consequence of pytests extensive test discovery code. The second issue is because by default we do not install the baseline images (which save a lot of bits for the wheels and conda packages). In that case you can import Matplotlib, but then it can’t find the baseline images.

Where should we have put that information to make it more findable?

Thanks for the reply!

When doing

python3 -mpip install -ve .

I get

    running develop
    error: can't create or remove files in install directory

    The following error occurred while trying to add or remove files in the
    installation directory:

        [Errno 13] Permission denied: '/usr/local/lib/python3.7/dist-packages/test-easy-install-22315.write-test'

I have to add --user. It does work then though, and also running pytest in the source directory works. I suppose it picks up matplotlib from ~/.local/ then.

Where should we have put that information to make it more findable?

The first place I was looking at testing was the main readme under Test. It would have helped me if the line of code

python3 -mpip install -ve --user .

would have appeared there.

Perhaps too quick? When running the tests, I get

FileNotFoundError: [Errno 2] No such file or directory: '/home/nschloe/software/matplotlib/source-nschloe/result_images/test_arrow_patches/fancyarrow_test_image-expected_svg.png'

In the directory, I see a bunch of files, but not the right one:

fancyarrow_test_image-expected.pdf
fancyarrow_test_image-expected.png
fancyarrow_test_image.pdf
fancyarrow_test_image.png
fancyarrow_test_image-expected_pdf.png
fancyarrow_test_image-expected.svg
fancyarrow_test_image_pdf.png
fancyarrow_test_image.svg

I strongly suggest making use of a virtual enviroment for development (of whatever flavor you prefer) and am :-1: on suggesting the use of --user in the documentation.

That suggests you have overlapping installs of Matplotlib and are running the tests from one of them against the baseline images from the other.

ref: https://matplotlib.org/devel/contributing.html#retrieving-and-installing-the-latest-version-of-the-code

I strongly suggest using conda. It installs all the dependencies and then you can manually install matplotlib ontop:

conda create -n matplotlibdev
conda activate matplotlibdev
conda install pip matplotlib pytest # maybe others?  This should install all dependencies
conda uninstall matplotlib
cd ~/matplotlib
python3 -mpip install -ve .

Thanks for the comments!

I’ve got all mpl dependencies installed, so I suppose I don’t have to resort to conda right now.

I’m not too familiar with virtualenvs, so I’ll have to make myself familiar with it first. One problem that I can foresee is the fact that I’d like to build matplotlib against a local (modified) copy of numpy.

You can also install your patched version of numpy in that venv.
See also https://github.com/matplotlib/matplotlib/issues/15961 for a suggested new version of the docs re: developing mpl.

Thanks @anntzer.lee for your comment. I think being more opinionated about the build environment is a good thing. I’ll wait for this to get merged and then try again.

@nico.schloemer It would be very helpful for us if you could “test drive” those instructions. The core-devs already have our (sometimes idiosyncratic) development workflows set up so are not in a good position to evaluate how useful those directions are to a new contributor!

1 Like

Sure, I can do that.