Comments (17)
I created a pull request with code based on @kamilkrzyskow's suggestion of using ByteIO
, which works just fine. I tested against the Material for MkDocs documentation as well as the reproduction posted by @Aazih.
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.
from mkdocs-material.
Thanks for reporting. I'm not a Windows user, so any help is appreciated. Does your project have a .cache
folder? Did the social plugin download the font files? It should look like this:
.cache/plugin/social/fonts
└── Roboto
├── Black Italic.ttf
├── Black.ttf
├── Bold Italic.ttf
├── Bold.ttf
├── Italic.ttf
├── Light Italic.ttf
├── Light.ttf
├── Medium Italic.ttf
├── Medium.ttf
├── Regular.ttf
├── Thin Italic.ttf
└── Thin.ttf
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 .cache
folder, please try deleting it and running the plugin again.
from mkdocs-material.
I am trying to reproduce the issue but am afraid I have not found a way yet to install the libcairo
dependency on my Windows laptop. @Aazih, how did you install it? What version of Windows are you on? Should I bite the bullet and finally (up/down)grade to 11? I am using the GTK3+ runtime linked to from the troubleshooting guide. Even selected the installation into the lib
directory, checked it is on the path and ran the diagnosis script. All seems fine. Edit: Ok, so the problems I was having seem to trace back to this known problem with loading DLLs. I might be able do get to the actual question soon...
from mkdocs-material.
Ok, I managed to run the replication project and get an OSError as well, though without the stack trace for some reason. The .cache
directory has the plugin/social
subdirectories. There is a manifest.json
but it contains an empty dict. No log messages about downloading fonts are generated. Will see if I can set up a development environment debug this.
from mkdocs-material.
Thanks for reporting. I'm not a Windows user, so any help is appreciated. Does your project have a
.cache
folder? Did the social plugin download the font files? It should look like this:.cache/plugin/social/fonts └── Roboto ├── Black Italic.ttf ├── Black.ttf ├── Bold Italic.ttf ├── Bold.ttf ├── Italic.ttf ├── Light Italic.ttf ├── Light.ttf ├── Medium Italic.ttf ├── Medium.ttf ├── Regular.ttf ├── Thin Italic.ttf └── Thin.ttf
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
.cache
folder, please try deleting it and running the plugin again.
Initially:
So there is nothing in social, but windows has the ugly \ slash.
Deleting the .cache folder and doing serve again with plugins enabled.
Issue recreated. .cache, plugin, and social folders are created but nothing below that.
from mkdocs-material.
I am trying to reproduce the issue but am afraid I have not found a way yet to install the
libcairo
dependency on my Windows laptop. @Aazih, how did you install it? What version of Windows are you on? Should I bite the bullet and finally (up/down)grade to 11? I am using the GTK3+ runtime linked to from the troubleshooting guide. Even selected the installation into thelib
directory, checked it is on the path and ran the diagnosis script. All seems fine. Edit: Ok, so the problems I was having seem to trace back to this known problem with loading DLLs. I might be able do get to the actual question soon...
Thank you. Just FYI I followed the following steps to get cairo up and running.
Social Card Steps
- Install Msys2
- Within Msys2 run
pacman -S mingw-w64-x86_64-gtk4
- Add to Windows PATH
C:\msys64\mingw64\bin\
- Within python virtual environment
pip install "mkdocs-material[imaging]"
from mkdocs-material.
Ok, so this issue occurs in both the public and the insiders version and traces to a call to ImageFont.truetype(temp.name)
. The argument is a string that seems to point to the correct (temporary) file.
I copied the file to another file while the mkdocs serve
was paused in the debugger. Loaded the font I copied in a separate Python session and all was fine. When I tried to open the original file, with the temporary file still open in the process in the debugger, I got the OSError
when using ImageFont.truetype
.
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
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\ALEXVO~1\\AppData\\Local\\Temp\\tmpmhpwb1bt'
That is not the same as an OSError
, so still looking at this.
from mkdocs-material.
@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.
from mkdocs-material.
Ok, it does look like this is a Windows-specific issue with NamedTemporaryFile
: https://stackoverflow.com/questions/6416782/what-is-namedtemporaryfile-useful-for-on-windows
@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.from mkdocs-material.
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 NamedTemporaryFile
to use a regular file to download and write the font and then just move it, assuming moving doesn't require any extra permissions. Or does that lead to the same problem with seek? If yes, we can seek back to 0.
from mkdocs-material.
Or wait no, let's go for seek for now, if that works 😅 Saving file open/close sys calls is probably a better idea.
from mkdocs-material.
I used cairosvg from my PATH in Windows 10 and I believe Python 3.12 in March, had no issues @alexvoss
Even selected the installation into the lib directory, checked it is on the path and ran the diagnosis script
So I don't think I selected anything non-default like install tolib
, in the GTK-Installer, and install tobin
Python 3.8 no longer searches for DLLs in PATH
I'm interested in the source, this claim is based on, and what caused it to change 🤔
CairoFFI still uses find_library
:
And find_library
on Windows still searches in PATH:
I can see you've resolved the issue, and did great work on the debug process Alex, but maybe you could check your ctypes/util.py
in the Python interpreter directory to see how your find_library
does look like?
I want to know if something is missing from the troubleshooting guide 🤔
As for the issue at hand can't we set delete=False
like the StackOverFlow answer suggests, or is our issue at the temp.flush()
?
Also the ImageFont.truetype should accept a file-like object, so perhaps the BytesIO(res.content) could work?
All untested ideas, food for thought.
from mkdocs-material.
@kamilkrzyskow @alexvoss happy for PRs on this, as I'm unable to reproduce it.
Also the ImageFont.truetype should accept a file-like object, so perhaps the BytesIO(res.content) could work?
Sounds really promising!
from mkdocs-material.
Also the ImageFont.truetype should accept a file-like object, so perhaps the BytesIO(res.content) could work?
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 NamedTemporaryFile
thing. Will try a bit later on. Am still struggling with Windows as a development environment.
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.
from mkdocs-material.
Keeping open until released.
from mkdocs-material.
Released as part of 9.5.20.
from mkdocs-material.
@alexvoss @Aazih tangentially related, on the topic of MSYS2: it doesn't actually require full GTK, installing just Cairo is enough. I posted a proposed documentation update in #7163.
from mkdocs-material.
Related Issues (20)
- Add PlantUML Markdown extension schema HOT 1
- Version switcher lately never succeeds at staying on the same page HOT 15
- FR: Support Variable from Pyproject.toml HOT 1
- "Copy" in code blocks inject double newlines HOT 8
- Custom Icons: size and color info missing in documtation HOT 1
- multi blog instances share the same `post_date_format` date filter HOT 8
- Instant navigation: toc item requires two clicks after navigating away and returning HOT 5
- Default value for search-plugin separator has a typo HOT 1
- Version selector is not displayed correctly after enabling showing version alias HOT 4
- Mermaid Viewer Control box? How can we use it? HOT 5
- Insiders tag plugin conflicts with markdown_extensions.toc HOT 5
- Section display text alias overridden with same .md files HOT 2
- Add tab index to `.md-search__scrollwrap` in the `search` plugin HOT 11
- [change(feature) request] Page Subtitle for Blog Posts HOT 3
- Annotation doesn't work inside markdown tables HOT 2
- Running "mkdocs serve" through Docker results in "Connection reset by peer" HOT 4
- Comment: The comment page must be refreshed to appear. HOT 4
- included in the 'nav' configuration, which is not found in the documentation files. HOT 1
- Blog issue - TypeError: unsupported operand type(s) for |: 'ABCMeta' and 'NoneType' HOT 1
- Cannot use numbers as titles HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mkdocs-material.