WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

Add public method to cleanup font configuration temporary directory

Open max-blau opened this issue 3 weeks ago • 1 comments

The temp directory used store some downloaded bytes for fonts is sometimes not being cleaned up automatically via the __del__ dunder method. This commit exposes a cleanup method to allow users to handle this cleanup themselves if it affects their workflow.

tests:

➜ ~/work/fork/WeasyPrint (expose-font-cleanup-method) [weasyprint] $ pytest tests/test_fonts.py
================================================================================================================ test session starts ================================================================================================================
platform darwin -- Python 3.10.18, pytest-9.0.2, pluggy-1.6.0
rootdir: /Users/maxblau/work/fork/WeasyPrint
configfile: pyproject.toml
collected 8 items

tests/test_fonts.py ........                                                                                                                                                                                                                  [100%]

================================================================================================================= 8 passed in 0.14s =================================================================================================================

max-blau avatar Dec 09 '25 14:12 max-blau

@liZe I don't have permissions to add reviewers, here's a PR for the workaround we discussed in https://github.com/Kozea/WeasyPrint/issues/2090

max-blau avatar Dec 09 '25 14:12 max-blau

@max-blau Why did you close this pull request?

liZe avatar Dec 15 '25 22:12 liZe

@liZe sorry, meant to post a comment. It's not needed - you can just do something like this instead:

font_config = FontConfiguration()
del font_config

max-blau avatar Dec 16 '25 13:12 max-blau

@liZe nevermind - probably due to other implementation details in weasyprint, just subtracting the ref count of the FontConfiguration instance isn't enough to get the garbage collector to delete it. Re-opening this - although its also possible to just call __del__ directly as a user - if thats OK with you, then this change could be dropped.

max-blau avatar Dec 16 '25 14:12 max-blau