-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Social plugin: can't find fonts on Windows #7085
Comments
Thanks for reporting. I'm not a Windows user, so any help is appreciated. Does your project have a
It the font files are not there, the download or writing the files did not work. To be clear, the social plugin will download the files automatically, but if that failed for whatever reason or the files cannot be written because of permissions, it would explain the problem. If there is a |
mkdocs serve
I am trying to reproduce the issue but am afraid I have not found a way yet to install the |
Ok, I managed to run the replication project and get an OSError as well, though without the stack trace for some reason. The |
Thank you. Just FYI I followed the following steps to get cairo up and running. Social Card Steps
|
Ok, so this issue occurs in both the public and the insiders version and traces to a call to I copied the file to another file while the Is it possible that Windows does not allow a temporary file to be opened again? I wrote a small test script to see what would happen: from tempfile import NamedTemporaryFile
with NamedTemporaryFile(mode='w') as file:
file.write("HELLO")
file.flush()
fd = open(file.name, 'r') Promptly got a
That is not the same as an |
@Aazih thanks for the info about installing using MSYS2. I tried that in October but ran into various problems. Would be good if we could say this has become a reliable way of installing it. |
Ok, it does look like this is a Windows-specific issue with @squidfunk, this is in mkdocs-material/src/plugins/social/plugin.py Line 531 in dca9c27
seek the open temporary file back to 0 and pass the file object to ImageFont.truetype() instead of the filename. That did the trick but the next problem is that copy_file also wants to open the file and fails - with a PermissionError . We'd need to do the same trick with that one, I guess? Let me know if you want me to try to implement this. It would save two file open operations and I don't see why it should not work on Unix-type operating systems.
|
Wow, thanks for gathering all the intel! I'm a little tight on time right now, but as I read we could just exchange the approach using |
Or wait no, let's go for seek for now, if that works 😅 Saving file open/close sys calls is probably a better idea. |
I used cairosvg from my PATH in Windows 10 and I believe Python 3.12 in March, had no issues @alexvoss
I'm interested in the source, this claim is based on, and what caused it to change 🤔 And I can see you've resolved the issue, and did great work on the debug process Alex, but maybe you could check your As for the issue at hand can't we set |
@kamilkrzyskow @alexvoss happy for PRs on this, as I'm unable to reproduce it.
Sounds really promising! |
Aha, BytesIO might be what I was looking for. Hope it is possible toread the data more than once without copying to a buffer. We might be able to get rid of the whole Thanks for the notes on DLLs. I will look at that as well later on and open a new issue if don't find I just made a silly mistake. First time in a long time I am using Windows for anything other than playing Minecraft with my daughter, so apologies in advance. |
I created a pull request with code based on @kamilkrzyskow's suggestion of using Seems a nice rare case where fixing a problem that affects only one OS led to a reduction in code size as well as, presumably, a speedup since we are writing to only one file now. Will do the equivalent for the Insider Edition tomorrow - unless @squidfunk beats me to it or anyone spots a problem. |
Keeping open until released. |
Released as part of 9.5.20. |
Context
I am attempting to setup social cards for the first time in Windows. Have searched for solutions but it appears that loading fonts is not working as expected
Bug description
Enable social plugin in mkdocs.yml via adding the following lines:
`plugins:
`
Results in the following error:
INFO - Building documentation... INFO - Cleaning site directory INFO - Documentation built in 0.28 seconds INFO - [23:48:15] Watching paths for changes: 'docs', 'mkdocs.yml' INFO - [23:48:15] Serving on http://127.0.0.1:8000/ INFO - [23:48:16] Browser connected: http://127.0.0.1:8000/ INFO - [23:48:21] Detected file changes INFO - Building documentation... Traceback (most recent call last): File "C:\Programming\materialtest\venv\Lib\site-packages\mkdocs\livereload\__init__.py", line 193, in _build_loop func() File "C:\Programming\materialtest\venv\Lib\site-packages\mkdocs\commands\serve.py", line 67, in builder build(config, live_server=None if is_clean else server, dirty=is_dirty) File "C:\Programming\materialtest\venv\Lib\site-packages\mkdocs\commands\build.py", line 277, in build config = config.plugins.on_config(config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Programming\materialtest\venv\Lib\site-packages\mkdocs\plugins.py", line 527, in on_config return self.run_event('config', config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Programming\materialtest\venv\Lib\site-packages\mkdocs\plugins.py", line 507, in run_event result = method(item, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Programming\materialtest\venv\Lib\site-packages\material\plugins\social\plugin.py", line 160, in on_config self.font = self._load_font(config) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Programming\materialtest\venv\Lib\site-packages\material\plugins\social\plugin.py", line 462, in _load_font font[style] = self._resolve_font(name, style) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Programming\materialtest\venv\Lib\site-packages\material\plugins\social\plugin.py", line 476, in _resolve_font self._fetch_font_from_google_fonts(family) File "C:\Programming\materialtest\venv\Lib\site-packages\material\plugins\social\plugin.py", line 537, in _fetch_font_from_google_fonts font = ImageFont.truetype(temp.name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Programming\materialtest\venv\Lib\site-packages\PIL\ImageFont.py", line 807, in truetype return freetype(font) ^^^^^^^^^^^^^^ File "C:\Programming\materialtest\venv\Lib\site-packages\PIL\ImageFont.py", line 804, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Programming\materialtest\venv\Lib\site-packages\PIL\ImageFont.py", line 244, in __init__ self.font = core.getfont( ^^^^^^^^^^^^^ OSError: cannot open resource
Related links
Reproduction
9.5.18-social-plugin-windows.zip
Steps to reproduce
`
Browser
No response
Before submitting
The text was updated successfully, but these errors were encountered: