-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Removal of baseline images from matplotlib_baseline_images package #17793
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
Changes from all commits
1559df3
ec5e8cf
282c0a5
ba5baeb
fcdb268
a9d5aed
b32cae7
5355933
8243f7d
57bfa89
3ac82c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"files_added": [{"file" : "test_arrow_patches.py", | ||
"test" : "test_boxarrow", | ||
"img_names": ["a.png", "b.png"]}], | ||
"files_deleted": [{"file" : "test_arrow_patches.py", | ||
"test" : "test_boxarrow", | ||
"img_names": ["a.png", "b.png"]}], | ||
"files_modified": [{"prev_file" : "test_arrow_patches.py", | ||
"prev_test" : "test_boxarrow", | ||
"prev_img_names": ["a.png", "b.png"], | ||
"new_file" : "test_arrow_patches.py", | ||
"new_test" : "test_boxarrow", | ||
"new_img_names": ["a.png", "b.png"] | ||
}] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Baseline image generation | ||
------------------------- | ||
|
||
Earlier the baseline images were present in the ``baseline_images`` folder. Now they are present in the | ||
:file:`sub-wheels/matpotlib-baseline-images/lib/matplotlib_baseline_images`. | ||
|
||
In order to run local image tests, the developer should checkout the ``master`` branch and run the tests once with the | ||
``generate_images`` flag in order to get a set of baseline images that are consistent with the code in ``master``. The | ||
command will be :: | ||
|
||
python3 -mpytest --generate_images | ||
|
||
Then subsequent tests from their branches will test against these baseline images. | ||
|
||
Alternately, the developer could download the ``matplotlib-baseline-images`` package and compare against these images. | ||
However, the developer will have to be certain to have development environment that has the same free type and other | ||
dependencies as the testing environment on the the machine that made ``matplotlib-baseline-images``. Developer can | ||
install the ``matplotlib-baseline-images`` package by running the command :: | ||
|
||
python3 -mpip install -ve sub-wheels/matplotlib-baseline-images | ||
|
||
or can install the package from PyP by the command :: | ||
|
||
python3 -mpip install matplotlib-baseline-images | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -590,3 +590,69 @@ example code you can load it into a file handle with:: | |
|
||
import matplotlib.cbook as cbook | ||
fh = cbook.get_sample_data('mydata.dat') | ||
|
||
|
||
Baseline image generation | ||
------------------------- | ||
The idea is to eventually remove all of the baseline images from the matplotlib repository as the baseline images are | ||
problematic. This is due to the reason that they cause the repo size to grow rather quickly. they also force the | ||
developers to pin to a somewhat old version of freetype, because nearly every release of freetype causes tiny | ||
rasterization changes that would entail regenerating all baseline images (and thus cause even more repo size growth). | ||
After removal of the baseline images, the developer have two options to get the baselines from. | ||
In order to run local image tests, the developer should checkout the ``master`` branch and run the tests once with the | ||
``generate_images`` flag in order to get a set of baseline images that are consistent with the code in ``master``. Then | ||
subsequent tests from their branches will test against these baseline images. | ||
|
||
Alternately, the developer could download the ``matplotlib-baseline-images`` package and | ||
compare against these images. However, the developer will have to be certain to have | ||
development environment that has the same free type and other dependencies as the testing | ||
environment on the the machine that made ``matplotlib-baseline-images``. | ||
|
||
These methods are described below. Later on, developer can run :: | ||
|
||
python3 -pytest | ||
|
||
|
||
How to install matplotlib-baseline-images package? | ||
-------------------------------------------------- | ||
Developer can install the ``matplotlib-baseline-images`` package by running the command :: | ||
|
||
python3 -mpip install -ve sub-wheels/matplotlib-baseline-images | ||
|
||
or can install the package from PyP by the command :: | ||
|
||
python3 -mpip install matplotlib-baseline-images | ||
|
||
Canonical images will be tied to a given release. | ||
|
||
|
||
Baseline image generation at the fresh install of matplotlib through command line | ||
---------------------------------------------------------------------------------- | ||
The baseline images can be generated in the ``baseline_images`` directory by using :: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above - not sure we should encourage this. Its basically a useless test if local images pass but fail when uploaded. |
||
|
||
python3 -mpytest --generate_images | ||
|
||
SidharthBansal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
For a given developer the baseline images don't change due to local changes (even if there may be some variation | ||
between developers respective baselines due to different freetype / latex etc. | ||
|
||
|
||
SidharthBansal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
How to update an existing baseline image? | ||
--------------------------------------------- | ||
Tests generating the baseline images may change over time. So, the baseline images needs to be regenerated by the | ||
developer after fetching the changes through ``git pull`` or ``git checkout -b featured_branch``. Missing baseline | ||
images can be generated in the ``baseline_images`` directory with the following command:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I still don't understand what will happen at this point. I fix a bug, but it changes the image for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great thoughts. I will write the documentation for those cases. Thanks |
||
|
||
python3 -mpytest --generate_images | ||
|
||
Later on, developer can run the test suite with :: | ||
|
||
python3 -pytest | ||
|
||
|
||
Add new tests that require new images | ||
------------------------------------- | ||
Tests which require new expected image can be inserted in the test files without adding the baseline or expected images. | ||
The baseline or expected images will be first created by:: | ||
|
||
python3 -mpytest --generate_images | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,13 +144,14 @@ tests it:: | |
fig, ax = plt.subplots() | ||
ax.plot(range(10), linestyle=(0, (3, 3)), lw=5) | ||
|
||
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. | ||
|
||
What should a developer do if they want to change any baseline images? | ||
---------------------------------------------------------------------- | ||
In the previous flow the committed baseline images were changed when the tests generating them changed. Now, there is | ||
no need to change the baseline images as they will be generated by running the tests by other developers. Instead, | ||
change the name of the baseline images. It can be done by changing the id appended to the name of the test to the next | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the previous flow changed baseline images were explicitly committed to the repo as part of the PR as a change to the file, and you could compare before and after. I'm still not at all clear what the new plan is from these descriptions. This needs a thorough before and after guide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. |
||
corresponding id if the id field is already present in the image name. Otherwise, add an id equals to ``1`` to the | ||
image names. | ||
|
||
Baseline images take a lot of space in the Matplotlib repository. | ||
An alternative approach for image comparison tests is to use the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
|
||
|
||
def pytest_addoption(parser): | ||
try: | ||
parser.addoption( | ||
"--generate_images", | ||
action="store_true", | ||
default=False, | ||
help="run matplotlib baseline image generation tests" | ||
) | ||
except: | ||
pass | ||
|
||
|
||
def pytest_collection_modifyitems(config, items): | ||
if config.getoption("--generate_images"): | ||
skip_non_baseline_img_gen_tests \ | ||
= pytest.mark.skip(reason="No need to run non " | ||
"image generation tests") | ||
for item in items: | ||
if "generate_images" not in item.keywords: | ||
item.add_marker(skip_non_baseline_img_gen_tests) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +0,0 @@ | ||
from pathlib import Path | ||
|
||
|
||
# Check that the test directories exist. | ||
if not (Path(__file__).parent / 'baseline_images').exists(): | ||
raise IOError( | ||
'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.') | ||
Uh oh!
There was an error while loading. Please reload this page.