8000 Simplify and tighten parse_fontconfig_pattern. by anntzer · Pull Request #24220 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Simplify and tighten parse_fontconfig_pattern. #24220

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
Oct 25, 2022
Merged

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Oct 19, 2022
  • Warn on unknown constant names, e.g. DejaVu Sans:unknown (as opposed e.g. to DejaVu Sans:bold); they were previously silently ignored.

  • Rewrite the parser into something much simpler, moving nearly all the logic into a single block post-processing the result of parseString, instead of splitting everything into many small parse actions. In particular this makes the parser mostly stateless (except for the cache held by pyparsing itself), instead of having the various parts communicate through the _properties attribute.

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@anntzer anntzer added this to the v3.7.0 milestone Oct 19, 2022
@anntzer anntzer force-pushed the pfp branch 5 times, most recently from c6feb3f to f11731a Compare October 19, 2022 16:26
if "families" in parse:
props["family"] = [*map(_family_unescape, parse['families'])]
if "size" in parse:
props["size"] = parse["sizes"]
Copy link
Member

Choose a reason for hiding this comment

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

Typo? (At least I do not understand why checking for "size" is a requirement to get "sizes".)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, fixed.

``parse_fontconfig_pattern`` will no longer ignore unknown constant names
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Previously, in a fontconfig pattern like ``DejaVu Sans:foo``, the
unknown ``foo`` constant name would be silently ignored. This is now raises
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
unknown ``foo`` constant name would be silently ignored. This is now raises
unknown ``foo`` constant name would be silently ignored. This now raises

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, fixed.

@anntzer anntzer force-pushed the pfp branch 3 times, most recently from 6961e32 to cf9ebeb Compare October 20, 2022 09:09
@anntzer
Copy link
Contributor Author
anntzer commented Oct 22, 2022

I further tweaked the parser a bit for conciseness.

- Warn on unknown constant names, e.g. ``DejaVu Sans:unknown`` (as
  opposed e.g. to ``DejaVu Sans:bold``); they were previously silently
  ignored.

- Rewrite the parser into something much simpler, moving nearly all the
  logic into a single block post-processing the result of parseString,
  instead of splitting everything into many small parse actions.  In
  particular this makes the parser mostly stateless (except for the
  cache held by pyparsing itself), instead of having the various parts
  communicate through the _properties attribute.
@ksunden ksunden merged commit 0c3ba6d into matplotlib:main Oct 25, 2022
@anntzer anntzer deleted the pfp branch October 25, 2022 21:39
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.

4 participants
0