Add public method to cleanup font configuration temporary directory
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 =================================================================================================================
@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 Why did you close this pull request?
@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
@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.