-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MAINT: Deterministic SVG and PDF tests #7748
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
529afdc
8c7adbb
93b2eea
eab297c
ec941b4
749e81f
6736f7d
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 |
---|---|---|
@@ -1,14 +1,28 @@ | ||
Reproducible PS and PDF output | ||
------------------------------ | ||
Reproducible PS, PDF and SVG output | ||
----------------------------------- | ||
|
||
The ``SOURCE_DATE_EPOCH`` environment variable can now be used to set | ||
the timestamp value in the PS and PDF outputs. See | ||
https://reproducible-builds.org/specs/source-date-epoch/ | ||
|
||
Alternatively, calling ``savefig`` with ``metadata={'creationDate': None}`` | ||
will omit the timestamp altogether. | ||
|
||
The reproducibility of the output from the PS and PDF backends has so | ||
far been tested using various plot elements but only default values of | ||
options such as ``{ps,pdf}.fonttype`` that can affect the output at a | ||
low level, and not with the mathtext or usetex features. When | ||
matplotlib calls external tools (such as PS distillers or LaTeX) their | ||
versions need to be kept constant for reproducibility, and they may | ||
add sources of nondeterminism outside the control of matplotlib. | ||
|
||
For SVG output, the ``svg.hashsalt`` rc parameter has been added in an | ||
earlier release. This parameter changes some random identifiers in the | ||
SVG file to be deterministic. The downside of this setting is that if | ||
more than one file is generated using deterministic identifiers | ||
and they end up as parts of one larger document, the identifiers can | ||
collide and cause the different parts to affect each other. | ||
|
||
These features are now enabled in the tests for the PDF and SVG | ||
backends, so most test output files (but not all of them) are now | ||
deterministic. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,10 @@ def set_font_settings_for_testing(): | |
rcParams['text.hinting_factor'] = 8 | ||
|
||
|
||
def set_reproducibility_for_testing(): | ||
rcParams['svg.hashsalt'] = 'matplotlib' | ||
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. This will also break, in a way, the determinism test. 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. Can you explain in more detail? The 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. Probably along the same lines as @tacaswell; I was thinking it wouldn't fail if |
||
|
||
|
||
def setup(): | ||
# The baseline images are created in this locale, so we should use | ||
# it during all of the tests. | ||
|
@@ -161,3 +165,4 @@ def setup(): | |
rcdefaults() # Start with all defaults | ||
|
||
set_font_settings_for_testing() | ||
set_reproducibility_for_testing() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -298,7 +298,12 @@ def compare(self, idx, baseline, extension): | |
remove_ticks_and_titles(fig) | ||
|
||
actual_fname = os.path.join(self.result_dir, baseline) + '.' + extension | ||
fig.savefig(actual_fname, **self.savefig_kwargs) | ||
kwargs = self.savefig_kwargs.copy() | ||
if extension == 'pdf': | ||
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. Doesn't this break the test of 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. No, that test starts a separate subprocess to write the output and doesn't use the image_comparison decorator at all. 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. Ah, 🐑 |
||
kwargs.setdefault('metadata', | ||
{'Creator': None, 'Producer': None, | ||
'CreationDate': None}) | ||
fig.savefig(actual_fname, **kwargs) | ||
|
||
expected_fname = self.copy_baseline(baseline, extension) | ||
raise_on_image_difference(expected_fname, actual_fname, self.tol) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even need the version here? It's in the
Creator
tag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought including the version in both would help with debugging when the user has overridden just one of these. If you use Matplotlib as a component of some larger application, you might want to override Creator and leave Producer pointing to the PDF backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.