From adfddb635eec28ef8f67aa95d0927041d25815e7 Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 29 Aug 2024 11:03:24 +0900 Subject: [PATCH] close downloaded font --- src/plothist/scripts/install_latin_modern_fonts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plothist/scripts/install_latin_modern_fonts.py b/src/plothist/scripts/install_latin_modern_fonts.py index a69e882..9477995 100644 --- a/src/plothist/scripts/install_latin_modern_fonts.py +++ b/src/plothist/scripts/install_latin_modern_fonts.py @@ -32,11 +32,12 @@ def _download_font(url, font_directory, font_name): while not success and attempt < max_attempt: try: r = requests.get(url) - open(f"{font_directory}/{url.split('/')[-1]}", "wb").write(r.content) + with (font_directory / url.split('/')[-1]).open("wb") as f: + f.write(r.content) success = True except Exception as e: # Print the output to the terminal - print(f"Try {attempt + 1} of {max_attempt}\n {e}") + print(f"Error: {e}\nTry {attempt + 1} of {max_attempt}") # Increment attempt counter and wait before the next attempt attempt += 1 time.sleep(attempt) @@ -108,7 +109,7 @@ def install_latin_modern_fonts(): success = True except Exception as e: # Print the output to the terminal - print(f"Try {attempt + 1} of {max_attempt}\n {e}") + print(f"Error: {e}\nTry {attempt + 1} of {max_attempt}") # Increment attempt counter and wait before the next attempt attempt += 1 time.sleep(attempt)