-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Update font_manager to only use registry on Win #24655
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
Conversation
xref to #24001 |
Actually, a test needs to be updated too.
The failure is definitely caused by this change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both loops return the same fonts1 with extensions [".afm", ".ttf", ".otf", ".ttc" ]
and the hkey points to C:\WINDOWS\Fonts
ETA: I'm now confused how that test failed since both of the keys in the fontpath are in the windows installed search function, unless it's a permissions thing?
matplotlib/lib/matplotlib/font_manager.py
Lines 223 to 226 in 65e54af
for domain, base_dirs in [ | |
(winreg.HKEY_LOCAL_MACHINE, [win32FontDirectory()]), # System. | |
(winreg.HKEY_CURRENT_USER, MSUserFontDirectories), # User. | |
]: |
Footnotes
-
the old loop returns
{'', '.CompositeFont', '.TTF', '.dat', '.fon', '.ini', '.ttc', '.ttf', '.xml'}
because there's no extension filtering. ↩
Also, I dunno if this is sensible but I modified the test to run it on my local machine, and I'm now getting the same failure, w/ the same message: @pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')
def test_user_fonts_win32():
font_test_file = 'mpltest.ttf'
# Precondition: the test font should not be available
fonts = findSystemFonts()
if any(font_test_file in font for font in fonts):
pytest.skip(f'{font_test_file} already exists in system fonts')
user_fonts_dir = Path(MSUserFontDirectories[0])
# Make sure that the user font directory exists (this is probably not the
# case on Windows versions < 1809)
user_fonts_dir.mkdir(exist_ok=True)
# Copy the test font to the user font directory
shutil.copy(Path(__file__).parent / font_test_file, user_fonts_dir)
assert (user_fonts_dir/font_test_file).exists()
# Now, the font should be available
fonts = findSystemFonts()
assert any(font_test_file in font for font in fonts)
(Path(user_fonts_dir)/font_test_file).unlink()
assert not (Path(user_fonts_dir)/font_test_file).exists() ETA: if this is sensible, then I'll wrap up "temp copy" in a context manager. ETA2: I have no idea why the test is failing b/c the directory for writing the tempfile is identical when fontpaths is set or when it's empty
while this is flipped:
and I checked and yeah the file is in AppData |
Ah, are you saying the test is wrong? I think we maybe should be calling |
No, just that I'm not sure why I can't run it locally if I create and clean-up the file during the test? |
I guess what I would like to confirm is; if you use Explorer to copy a new font there, does it get added to the registry? Does it only do so if you use the Install button on the font viewer? What about if you have a Python script that copies the font there; does the registry update automatically, or do you have to open the directory in Explorer to refresh it, or does nothing update the registry? |
No
Yup
nope
that doesn't seem to work either ETA: as far as I can tell, that test works because it's checking if a file put into a folder is found in the folder, completely bypassing the registry. |
Per discussion on this weeks dev call:
|
1. we are moving to registry only for finding fonts on windows 2. our test just drops the font in the correct directory 3. this is not enough to get the registry to agree it is there We will xfail this test for now.
per need for changes as discussed on the call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I wrote the behavior change note so this review should be taken with a grain of salt.
@story645 Can you please confirm that this works as expected for fonts installed as Windows expects and merge if you are satisfied? |
heads up that I won't be able to get to this til tomorrow night/sunday |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny what's new nit. I don't think the failing tests are related to this PR, but I'm not comfortable merging while so many tests are failing.
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> Co-authored-by: hannah <story645@gmail.com>
…655-on-v3.7.x Backport PR #24655 on branch v3.7.x (Update font_manager to only use registry on Win)
list_fonts
on Windows.