Skip to content

MNT: remove inkscape from testing in favour of resvg - #32666

Merged
tacaswell merged 1 commit into
matplotlib:mainfrom
jklymak:mnt-remove-inkscape
Nov 26, 2026
Merged

tacaswell merged 1 commit into
matplotlib:mainfrom
jklymak:mnt-remove-inkscape

Conversation

@jklymak

@jklymak jklymak commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

This drops Inkscape as a test requirement, and uses resvg-py https://pypi.org/project/resvg_py/. This is conda- and pip-installable and doesn't require a GUI and installing something the size of Inkscape.

AI use: yes AI did the typing for me. I checked the CI jobs and the one image test difference by eye (see below).

I don't feel strongly about this, but given the issues with CI on the Macs its seems a win.

@github-actions github-actions Bot added the CI: Run cibuildwheel Run wheel building tests on a PR label Nov 25, 2026
@jklymak
jklymak force-pushed the mnt-remove-inkscape branch from bdb047c to c9fdd9c Compare November 26, 2026 00:38
@jklymak

jklymak commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

There is one failing test. Raised the tolerance as I don't think it is a real issue.
Diff:
pre_transform_data_svg-failed-diff

Expected:
pre_transform_data-expected_svg

Test:
pre_transform_data_svg

@jklymak
jklymak marked this pull request as ready for review November 26, 2026 00:41
@tacaswell

Copy link
Copy Markdown
Member

attn @iccir

@tacaswell tacaswell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be worth re-generating that one SVG (I assume that this is due to us truncating floating point numbers, the checked in version having lots of digits, and then us rounding and the renderer rounding are coming out slightly differently).

@iccir iccir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am approving this as I have a longstanding belief that "an always-on warning light is dangerous". I believe that a flakey or always-failing test makes people ignore that test.

That said, I have concerns and questions:

  • It was mentioned a few meetings back that users open our SVGs in Inkscape and then make modifications. With this change, are we no longer testing a common use case?
  • What exactly are we trying to test here? Should we be testing our generated SVGs against both references PNGs as well as reference SVGs?
  • What happens if we start using an SVG feature which resvg doesn't support - will we catch that in test? If resvg doesn't render a filter, we might end up testing a blank image against another blank image. Note that the same is true with Inkscape today or any other SVG engine - they all support slightly different subsets of the standard.

I think I'd rather see us keep Inkscape on Linux (if it is reliable there) and also use resvg on platforms where Inkscape isn't support. Additionally, I'd like to see some kind of testing against a browser-based SVG renderer (I'm was working on a PR that used the macOS WebKit renderer, but I can abandon that if people want).

All that said: the priority should be making the lights green. Self-merge ok. Or @tacaswell can merge as needed.

@tacaswell

Copy link
Copy Markdown
Member

The goal in to make sure our svg are stable over time, that is the same code now generates an svg that render the same as that code generated in the past. To that end, any svg renderer we can use to get to raster we can compare our checked in SVG to a new SVG is sufficient (as we mentioned, we should trust that the renderer is infact a functional SVG renderer at is not going to just render everything as (0, 0, 0, 0) ;) ).

We have in the past held the line that if we are generating valid SVG to the spec and an renderer is getting it wrong we expect the renderer to fix it self (rsvg). Hence, if we are generating valid SVG that inkscape has issues with, then that is an inkscape bug that should be reported and addressed upstream.

I'm 50/50 on if we still want to pick of the mac browser based version as well. On one hand, it does not add a lot over already having a Python package that handles it. On the other hand, it does add some diversity to the tests so if we do find blind spots in the renderers then presumably it will be different bugs so. I'm at "likely useful but not urgent".

@tacaswell
tacaswell merged commit f38a05e into matplotlib:main Nov 26, 2026
45 checks passed
@iccir

iccir commented Nov 26, 2026

Copy link
Copy Markdown
Member

I'm 50/50 on if we still want to pick of the mac browser based version as well. On one hand, it does not add a lot over already having a Python package that handles it. On the other hand, it does add some diversity to the tests so if we do find blind spots in the renderers then presumably it will be different bugs so. I'm at "likely useful but not urgent".

I too am 50/50 :) I'd be 100% in favor if there were a simple command-line tool on macOS that could invoke the renderer, or if Apple provided a simple "render this SVG as a PNG" API.

Unfortunately, it involves sending everything over to another Python process which loads a C extension, spins up the app run loop, and makes a WKWebView. That sends everything over to another process inside the WebKit sandbox. Wheeee!

@jklymak

jklymak commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

I don't think this was a "make the lights green" attempt. The goal was to get rid of a huge dependency that by itself does way more than what we need. I think historically it was the free way to translate svg but I guess these new packages have come along that do it without the GUI overhead

Google claims resvg-py and friends are 1-2.5 mb whereas Inkscape is 300-600 mb. It also thinks resvg will be much faster and wouldn't be spilling up Inkscape in tests. Finally it is a conda/pip install.

For sure I have no idea if we try to use svg extensions that are only possible in Inkscape. I would tend to say we should not do that and our svg should be standard compliant. Certainly if we allow such special cases they are not currently tested

I'm not sure I follow the idea that someone may produce blank reference images. Someone should definitely visually inspect every reference image before it is committed!

@iccir

iccir commented Nov 26, 2026

Copy link
Copy Markdown
Member

I'm not sure I follow the idea that someone may produce blank reference images. Someone should definitely visually inspect every reference image before it is committed!

I did this a bit yesterday - I copied every .svg from tests to /tmp/svgs, then ran:

from pathlib import Path
import resvg_py

directory = Path("/tmp/svgs")

for svg in directory.glob("*.svg"):
    try:
        png = svg.with_suffix(".png")
        b = resvg_py.svg_to_bytes(svg_path=str(svg), dpi=72.0)
        png.write_bytes(b)
    except Exception as e:
        print(f"Error processing {svg}: {e}")

I then compared the results in using macOS WebKit and resvg. I didn't see any differences.

@jklymak

jklymak commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Oopps sorry for the lengthy explanation after it had already been discussed and merged. Typing too slow on my phone!

@iccir iccir mentioned this pull request Nov 26, 2026
1 task done
@QuLogic QuLogic mentioned this pull request Nov 26, 2026
3 tasks done
@QuLogic QuLogic added this to the v3.12.0 milestone Nov 26, 2026
@tacaswell

Copy link
Copy Markdown
Member

This was anomalously fast to go in 🤣

@jklymak

jklymak commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

I'm not sure I follow the idea that someone may produce blank reference images. Someone should definitely visually inspect every reference image before it is committed!

Actually, I do follow this concern now. I hadn't realized that we check in the svg but the svg->png converter runs on both the reference and the test image. I'm not sure what to do about that, and the same concern existed with Inkscape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: Run cibuildwheel Run wheel building tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants