Skip to content

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

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
Sep 29, 2018

Conversation

Kojoley
Copy link
Member

@Kojoley Kojoley commented Sep 22, 2018

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
@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
@@ -201,7 +201,7 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
# 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
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)?

Copy link
Member Author

@Kojoley Kojoley Sep 22, 2018

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
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
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.

@@ -242,7 +242,7 @@ def get_fontconfig_fonts(fontext='ttf'):
"""
fontext = get_fontext_synonyms(fontext)
return [fname for fname in _call_fc_list()
if Path(fname).suffix[1:] in fontext]
Copy link
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
Copy link
Member Author

Kojoley commented Sep 22, 2018

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

@anntzer
Copy link
Contributor

anntzer commented Sep 22, 2018

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
Copy link
Member

jklymak commented Sep 28, 2018

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