Skip to content

font_manager: Fixed problems with Path(...).suffix - #12212

Merged
QuLogic merged 1 commit into
masterfrom
fix-font_manager-path-suffix-usages
Sep 29, 2018
Merged

QuLogic merged 1 commit into
masterfrom
fix-font_manager-path-suffix-usages

Conversation

@Kojoley

@Kojoley Kojoley commented Sep 22, 2018 •

Copy link
Copy Markdown
Member

The problem is that Path(...).suffix includes the dot, so '.ttf' in ('ttf',) gives False.
Also fixed problems of other .suffix usages.

@Kojoley
Kojoley requested a review from anntzer September 22, 2018 13:35
Comment thread lib/matplotlib/font_manager.py Resolved
@Kojoley
Kojoley force-pushed the fix-font_manager-path-suffix-usages branch 3 times, most recently from b66cb41 to 1148d94 Compare September 22, 2018 13:57
# is fixed in Py>=3.6.1.
direc = direc.split("\0", 1)[0]
path = Path(directory, direc).resolve()
if path.suffix.lower() in fontext:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems easier to prepend a dot to fontext at line 191 (as in list_fonts)?

@Kojoley Kojoley Sep 22, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fontext can be either string or tuple of strings, it will require something like:

if isinstance(fontext, str):
    fontext = '.' + fontext
else:
    fontext = ['.' + ext for ext in fontext]

Should I do it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You need to make it a list of strings so that we don't get false positives with extensionless files ("" not in [".ttf"] but "" in ".ttf")

Thanks for investigating.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, will fix it.

"""
fontext = get_fontext_synonyms(fontext)
return [fname for fname in _call_fc_list()
if Path(fname).suffix[1:] in fontext]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as above: prepend a dot to fontext

The problem is that `Path(...).suffix` includes the dot, so ``.ttf` in 'ttf'` gives `False`.
Also fixed other suffix usages.
@Kojoley
Kojoley force-pushed the fix-font_manager-path-suffix-usages branch from 1148d94 to 333dad1 Compare September 22, 2018 14:13
@Kojoley

Kojoley commented Sep 22, 2018

Copy link
Copy Markdown
Member Author

Alternatively we can change the output of get_fontext_synonyms, but it will be API break as it is public, right?

@anntzer

anntzer commented Sep 22, 2018

Copy link
Copy Markdown
Contributor

It probably shouldn't be public but it's nearly as simple to fix it without changing the API so let's not.

@Kojoley Kojoley mentioned this pull request Sep 22, 2018
@Kojoley Kojoley added this to the v3.0.x milestone Sep 23, 2018
@jklymak

jklymak commented Sep 28, 2018

Copy link
Copy Markdown
Member

ping @anntzer and @dopplershift about this one in anticipation of 3.0.1

@QuLogic
QuLogic merged commit b7824b1 into master Sep 29, 2018
@QuLogic
QuLogic deleted the fix-font_manager-path-suffix-usages branch September 29, 2018 08:50
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 29, 2018
dstansby added a commit that referenced this pull request Sep 29, 2018
…212-on-v3.0.x

Backport PR #12212 on branch v3.0.x (font_manager: Fixed problems with Path(...).suffix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants