Skip to content

Create a wheel/sdist with the baseline images #17557

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

Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ per-file-ignores =
lib/matplotlib/pylab.py: F401, F403
lib/matplotlib/pyplot.py: F401, F811
lib/matplotlib/style/__init__.py: F401
lib/matplotlib/tests/__init__.py F401
lib/matplotlib/testing/conftest.py: F401
lib/matplotlib/testing/decorators.py: F401
lib/matplotlib/tests/conftest.py: F401
Expand All @@ -82,6 +83,7 @@ per-file-ignores =
lib/mpl_toolkits/axisartist/axes_rgb.py: F401
lib/mpl_toolkits/axisartist/axislines.py: F401
lib/mpl_toolkits/mplot3d/__init__.py: F401
lib/mpl_toolkits/tests/__init__.py F401
lib/mpl_toolkits/tests/conftest.py: F401
lib/pylab.py: F401, F403

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ recursive-include tutorials *
include versioneer.py
include lib/matplotlib/_version.py
include tests.py
prune sub-wheels
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ steps:

- bash: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install -r requirements/testing/travis_all.txt -r requirements/testing/travis_extra.txt ||
[[ "$PYTHON_VERSION" = 'Pre' ]]
displayName: 'Install dependencies with pip'
Expand Down
7 changes: 4 additions & 3 deletions doc/devel/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ The first time this test is run, there will be no baseline image to compare
against, so the test will fail. Copy the output images (in this case
:file:`result_images/test_lines/test_line_dashes.png`) to the correct
subdirectory of :file:`baseline_images` tree in the source directory (in this
case :file:`lib/matplotlib/tests/baseline_images/test_lines`). Put this new
file under source code revision control (with ``git add``). When rerunning
the tests, they should now pass.
case :file:`sub-wheels/matplotlib-baseline-images/lib/'
'matplotlib_baseline_images/test_lines`). Put this new file under source code
revision control (with ``git add``). When rerunning the tests,
they should now pass.

Baseline images take a lot of space in the Matplotlib repository.
An alternative approach for image comparison tests is to use the
Expand Down
20 changes: 19 additions & 1 deletion lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,25 @@ def _image_directories(func):
doesn't exist.
"""
module_path = Path(sys.modules[func.__module__].__file__)
baseline_dir = module_path.parent / "baseline_images" / module_path.stem
if func.__module__.startswith("matplotlib."):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not on this pass, but we should think about how packages can what package carries their test images.

Maybe entrypoints?

try:
import matplotlib_baseline_images
except:
raise ImportError("Not able to import matplotlib_baseline_images")
baseline_dir = (Path(matplotlib_baseline_images.__file__).parent /
module_path.stem)
elif func.__module__.startswith("mpl_toolkits."):
try:
import mpl_toolkits_baseline_images
except:
raise ImportError("Not able to import "
"mpl_toolkits_baseline_images")
baseline_dir = (Path(mpl_toolkits_baseline_images.__file__).parent /
module_path.stem)
else:
baseline_dir = (module_path.parent /
"baseline_images" /
module_path.stem)
result_dir = Path().resolve() / "result_images" / module_path.stem
result_dir.mkdir(parents=True, exist_ok=True)
return baseline_dir, result_dir
13 changes: 6 additions & 7 deletions lib/matplotlib/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from pathlib import Path


# Check that the test directories exist.
if not (Path(__file__).parent / 'baseline_images').exists():
raise IOError(
# Check for the matplotlib_baseline_images.
try:
import matplotlib_baseline_images
except:
raise ImportError(
'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 '
'You may need to install matplotlib_baseline_images to get the '
'test data.')
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def test_PsfontsMap(monkeypatch):
monkeypatch.setattr(dr, 'find_tex_file', lambda x: x)

filename = str(Path(__file__).parent / 'baseline_images/dviread/test.map')
filename = str(Path(__file__).parent / 'test_data/dviread/test.map')
fontmap = dr.PsfontsMap(filename)
# Check all properties of a few fonts
for n in [1, 2, 3, 4, 5]:
Expand Down Expand Up @@ -51,7 +51,7 @@ def test_PsfontsMap(monkeypatch):
@pytest.mark.skipif(shutil.which("kpsewhich") is None,
reason="kpsewhich is not available")
def test_dviread():
dirpath = Path(__file__).parent / 'baseline_images/dviread'
dirpath = Path(__file__).parent / 'test_data/dviread'
with (dirpath / 'test.json').open() as f:
correct = json.load(f)
with dr.Dvi(str(dirpath / 'test.dvi'), None) as dvi:
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def test_imshow_zoom(fig_test, fig_ref):
@check_figures_equal()
def test_imshow_pil(fig_test, fig_ref):
style.use("default")
png_path = Path(__file__).parent / "baseline_images/pngsuite/basn3p04.png"
tiff_path = Path(__file__).parent / "baseline_images/test_image/uint16.tif"
png_path = Path(__file__).parent / "test_data/pngsuite/basn3p04.png"
tiff_path = Path(__file__).parent / "test_data/test_image/uint16.tif"
axs = fig_test.subplots(2)
axs[0].imshow(Image.open(png_path))
axs[1].imshow(Image.open(tiff_path))
Expand All @@ -160,14 +160,14 @@ def test_imshow_pil(fig_test, fig_ref):

def test_imread_pil_uint16():
img = plt.imread(os.path.join(os.path.dirname(__file__),
'baseline_images', 'test_image', 'uint16.tif'))
'test_data', 'test_image', 'uint16.tif'))
assert img.dtype == np.uint16
assert np.sum(img) == 134184960


def test_imread_fspath():
img = plt.imread(
Path(__file__).parent / 'baseline_images/test_image/uint16.tif')
Path(__file__).parent / 'test_data/test_image/uint16.tif')
assert img.dtype == np.uint16
assert np.sum(img) == 134184960

Expand Down Expand Up @@ -713,7 +713,7 @@ def test_minimized_rasterized():


def test_load_from_url():
path = Path(__file__).parent / "baseline_images/pngsuite/basn3p04.png"
path = Path(__file__).parent / "test_data/pngsuite/basn3p04.png"
url = ('file:'
+ ('///' if sys.platform == 'win32' else '')
+ path.resolve().as_posix())
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@image_comparison(['pngsuite.png'], tol=0.03)
def test_pngsuite():
files = sorted(
(Path(__file__).parent / "baseline_images/pngsuite").glob("basn*.png"))
(Path(__file__).parent / "test_data/pngsuite").glob("basn*.png"))

plt.figure(figsize=(len(files), 2))

Expand Down
13 changes: 6 additions & 7 deletions lib/mpl_toolkits/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from pathlib import Path


# Check that the test directories exist
if not (Path(__file__).parent / "baseline_images").exists():
raise IOError(
# Check for the mpl_toolkits_baseline_images.
try:
import mpl_toolkits_baseline_images
except:
raise ImportError(
'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 '
'You may need to install mpl_toolkits_baseline_images to get the '
'test data.')
1 change: 1 addition & 0 deletions requirements/testing/travis_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pytest-timeout
pytest-xdist
python-dateutil
tornado
-e sub-wheels/matplotlib-baseline-images
5 changes: 2 additions & 3 deletions setup.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

[packages]
# There are a number of data subpackages from Matplotlib that are
# considered optional. All except 'tests' data (meaning the baseline
# image files) are installed by default, but that can be changed here.
#tests = False
# considered optional. Sample data are installed by default, but that can be
# changed here.
#sample_data = True

[gui_support]
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
setupext.Platform(),
setupext.FreeType(),
setupext.SampleData(),
setupext.Tests(),
setupext.BackendMacOSX(),
]

Expand Down
18 changes: 0 additions & 18 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,24 +444,6 @@ def get_package_data(self):
}


class Tests(OptionalPackage):
name = "tests"
default_config = False

def get_package_data(self):
return {
'matplotlib': [
*_pkg_data_helper('matplotlib', 'tests/baseline_images'),
*_pkg_data_helper('matplotlib', 'tests/tinypages'),
'tests/cmr10.pfb',
'tests/mpltest.ttf',
],
'mpl_toolkits': [
*_pkg_data_helper('mpl_toolkits', 'tests/baseline_images'),
]
}


def add_numpy_flags(ext):
import numpy as np
ext.include_dirs.append(np.get_include())
Expand Down
99 changes: 99 additions & 0 deletions sub-wheels/matplotlib-baseline-images/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
License agreement for matplotlib versions 1.3.0 and later
=========================================================

1. This LICENSE AGREEMENT is between the Matplotlib Development Team
("MDT"), and the Individual or Organization ("Licensee") accessing and
otherwise using matplotlib software in source or binary form and its
associated documentation.

2. Subject to the terms and conditions of this License Agreement, MDT
hereby grants Licensee a nonexclusive, royalty-free, world-wide license
to reproduce, analyze, test, perform and/or display publicly, prepare
derivative works, distribute, and otherwise use matplotlib
alone or in any derivative version, provided, however, that MDT's
License Agreement and MDT's notice of copyright, i.e., "Copyright (c)
2012- Matplotlib Development Team; All Rights Reserved" are retained in
matplotlib alone or in any derivative version prepared by
Licensee.

3. In the event Licensee prepares a derivative work that is based on or
incorporates matplotlib or any part thereof, and wants to
make the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to matplotlib .

4. MDT is making matplotlib available to Licensee on an "AS
IS" basis. MDT MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, MDT MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.

5. MDT SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
THE POSSIBILITY THEREOF.

6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.

7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between MDT and
Licensee. This License Agreement does not grant permission to use MDT
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.

8. By copying, installing or otherwise using matplotlib ,
Licensee agrees to be bound by the terms and conditions of this License
Agreement.

License agreement for matplotlib versions prior to 1.3.0
========================================================

1. This LICENSE AGREEMENT is between John D. Hunter ("JDH"), and the
Individual or Organization ("Licensee") accessing and otherwise using
matplotlib software in source or binary form and its associated
documentation.

2. Subject to the terms and conditions of this License Agreement, JDH
hereby grants Licensee a nonexclusive, royalty-free, world-wide license
to reproduce, analyze, test, perform and/or display publicly, prepare
derivative works, distribute, and otherwise use matplotlib
alone or in any derivative version, provided, however, that JDH's
License Agreement and JDH's notice of copyright, i.e., "Copyright (c)
2002-2011 John D. Hunter; All Rights Reserved" are retained in
matplotlib alone or in any derivative version prepared by
Licensee.

3. In the event Licensee prepares a derivative work that is based on or
incorporates matplotlib or any part thereof, and wants to
make the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to matplotlib.

4. JDH is making matplotlib available to Licensee on an "AS
IS" basis. JDH MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, JDH MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.

5. JDH SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
THE POSSIBILITY THEREOF.

6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.

7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between JDH and
Licensee. This License Agreement does not grant permission to use JDH
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.

8. By copying, installing or otherwise using matplotlib,
Licensee agrees to be bound by the terms and conditions of this License
Agreement.
4 changes: 4 additions & 0 deletions sub-wheels/matplotlib-baseline-images/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Matplotlib-baseline-images is a data package containing matplotlib baseline
images and matplotlib toolkit baseline images. Baseline images were earlier
installed with the matplotlib. Now they are separately installed with the main
matplotlib package.
Loading