8000 _GSConverter: handle stray 'GS' in output gracefully by mgorny · Pull Request #20473 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

_GSConverter: handle stray 'GS' in output gracefully #20473

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

Merged
merged 1 commit into from
Jun 21, 2021

Conversation

mgorny
Copy link
Contributor
@mgorny mgorny commented Jun 20, 2021

PR Summary

Search the GS output stream for either "GS<" or "GS>" explicitly rather
than any "GS", in order to prevent the code from wrongly matching stray
"GS". This fixes a recent test regression on Gentoo where the following
output seems to have been wrongly matched:

**** Error 'gs' ignored -- ExtGState missing from Resources.
                              ^^

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Fixes #20472

Copy link
@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

raise ImageComparisonFailure(
(err + b"GS" + stack + b">")
.decode(sys.getfilesystemencoding(), "replace"))
err = self._read_until((b"GS<", b"GS>"))
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICT _read_until doesn't support tuples as is (len(terminator) is wrong) and needs to be fixed to support them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct, I was so happy about figuring out that .endswith() accepts tuples that I've missed it ;-).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so I've figured out that if instead of passing an explicit tuple, I use *terminator arg, I can allow multiple terminators without having to actually change the call sites or having to add a compatibility hack. If you don't like that, I can revert to adding if not isinstance(terminator, tuple) or changing all the call sites.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, wrong. I've just realized that stripping actually makes the err.endswith() test wrong :-/.

Copy link
Contributor
@anntzer anntzer Jun 21, 2021

Choose a reason for hiding this comment

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

I guess you need a read_until(*terminator, include_terminator=False|True)? Or just always include the terminator (returning a tuple for simpler use) and change all the call sites, perhaps that's slightly nicer APIwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think it's ready now. I've noticed another late-night mistake, and fixed it. I've aimed for minimal change / keeping the code simple now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the whole thing would be simpler by having terminator be a regex instead, and return match.groups()? This way you can just match r"GS(?:<(\d+))>" instead of having to do two read_untils. (The slight extra cost of doing regex matches should be negligible compared to interacting with the subprocess.)

(If doing so, I would suggest having the argument be always a compiled regex object so that callers have to call re.compile themselves to make it completely clear that the argument is a regex.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I don't really want to spend more time on it and I don't think it's really important how it's implemented given it's only used in tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

no worries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

@mgorny mgorny force-pushed the gs-cruft branch 3 times, most recently from b605a5b to ff2b05c Compare June 21, 2021 06:01
Search the GS output stream for either "GS<" or "GS>" explicitly rather
than any "GS", in order to prevent the code from wrongly matching stray
"GS".  This fixes a recent test regression on Gentoo where the following
output seems to have been wrongly matched:

    **** Error 'gs' ignored -- ExtGState missing from Resources.
                                  ^^

Fixes matplotlib#20472
@tacaswell tacaswell added this to the v3.4.3 milestone Jun 21, 2021
@tacaswell tacaswell merged commit 9ee41b4 into matplotlib:master Jun 21, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jun 21, 2021
@tacaswell
Copy link
Member

Thanks @mgorny ! Congratulations on your first Matplotlib PR merged 🎉 . Hopefully we will hear from you again.

QuLogic added a commit that referenced this pull request Jun 22, 2021
…473-on-v3.4.x

Backport PR #20473 on branch v3.4.x (_GSConverter: handle stray 'GS' in output gracefully)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_backend_pgf.py::test_xelatex[pdf] - ValueError: invalid literal for int() with base 10: b'ate missing from Resources. [...]
3 participants
0