diff --git a/README.rst b/README.rst index e496f80f..6b0b4931 100644 --- a/README.rst +++ b/README.rst @@ -47,7 +47,7 @@ plothist :target: https://badge.fury.io/py/plothist .. |Code style: black| image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black -.. |Docs from latest| image:: https://img.shields.io/badge/docs-v1.2.0-blue.svg +.. |Docs from latest| image:: https://img.shields.io/badge/docs-v1.2.1-blue.svg :target: https://plothist.readthedocs.io/en/latest/ .. |Docs from main| image:: https://img.shields.io/badge/docs-main-blue.svg :target: https://plothist.readthedocs.io/en/main/ diff --git a/docs/conf.py b/docs/conf.py index a967537a..61566954 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -36,9 +36,9 @@ author = "Cyrille Praz, Tristan Fillinger" # The short X.Y version -version = "1.2.0" +version = "1.2.1" # The full version, including alpha/beta/rc tags -release = "1.2.0" +release = "1.2.1" # -- General configuration --------------------------------------------------- diff --git a/src/plothist/__init__.py b/src/plothist/__init__.py index bad9a5cc..720932b8 100644 --- a/src/plothist/__init__.py +++ b/src/plothist/__init__.py @@ -1,6 +1,6 @@ """Plot histograms in a scalable way and a beautiful style.""" -__version__ = "1.2.0" +__version__ = "1.2.1" from .plotters import ( create_comparison_figure, diff --git a/src/plothist/scripts/install_latin_modern_fonts.py b/src/plothist/scripts/install_latin_modern_fonts.py index ab1f41b9..94bd98cf 100644 --- a/src/plothist/scripts/install_latin_modern_fonts.py +++ b/src/plothist/scripts/install_latin_modern_fonts.py @@ -3,6 +3,36 @@ import platform from pathlib import PosixPath import time +import re + + +def _get_wget_version(): + """ + Get the version of wget. + + Returns + ------- + tuple or str + The version of wget as a tuple of integers. + + Raises + ------ + RuntimeError + If the version of wget could not be determined. + """ + version_string = subprocess.check_output( + ["wget", "--version"], universal_newlines=True + ) + # Try to find the version number in the format "XX.XX.XX" + version_match = re.search(r"(\d+\.\d+\.\d+)", version_string) + if not version_match: + # Try to find the version number in the format "XX.XX" + version_match = re.search(r"(\d+\.\d+)", version_string) + if version_match: + version = version_match.group(1) + return tuple(map(int, version.split("."))) + else: + raise RuntimeError("Could not determine wget version.") def _get_install_command(url, font_directory): @@ -24,7 +54,9 @@ def _get_install_command(url, font_directory): return [ "wget", "--retry-connrefused", # retry refused connections and similar fatal errors - "--retry-on-host-error", # retry on host errors such as 404 "Not Found" + *( + ["--retry-on-host-error"] if _get_wget_version() >= (1, 20, 0) else [] + ), # retry on host errors such as 404 "Not Found" "--waitretry=1", # wait 1 second before next retry "--read-timeout=20", # wait a maximum of 20 seconds in case no data is received and then try again "--timeout=15", # wait max 15 seconds before the initial connection times out @@ -121,25 +153,42 @@ def install_latin_modern_fonts(): # Install Latin Modern Roman and Latin Modern Sans for lm in ["roman", "sans"]: - _download_font( - f"https://www.1001fonts.com/download/latin-modern-{lm}.zip", - font_directory, - f"Latin Modern {lm}", - ) - print(f"Unzipping Latin Modern {lm}...") - - subprocess.run( - [ - "unzip", - "-o", - (font_directory / f"latin-modern-{lm}.zip"), - "-d", - (font_directory / f"latin-modern-{lm}"), - ] - ) - subprocess.run(["rm", "-f", (font_directory / f"latin-modern-{lm}.zip")]) + attempt = 0 + max_attempt = 10 + success = False + + while not success and attempt < max_attempt: + _download_font( + f"https://www.1001fonts.com/download/latin-modern-{lm}.zip", + font_directory, + f"Latin Modern {lm}", + ) + print(f"Unzipping Latin Modern {lm}...") + + result = subprocess.run( + [ + "unzip", + "-o", + (font_directory / f"latin-modern-{lm}.zip"), + "-d", + (font_directory / f"latin-modern-{lm}"), + ], + capture_output=True, + text=True, + ) + success = result.returncode == 0 + if not success: + # Print the output to the terminal + print("Try", attempt + 1, "of", max_attempt) + print("STDOUT:", result.stdout) + print("STDERR:", result.stderr) + # Increment attempt counter and wait before the next attempt + attempt += 1 + time.sleep(1) + subprocess.run(["rm", "-f", (font_directory / f"latin-modern-{lm}.zip")]) print(f"Latin Modern {lm} installed successfully.\n") + subprocess.run(["rm", "-f", (font_directory / f"latin-modern-{lm}.zip")]) # Remove font cache try: diff --git a/src/plothist/scripts/make_examples.py b/src/plothist/scripts/make_examples.py index 20cef4fe..dcfda80c 100644 --- a/src/plothist/scripts/make_examples.py +++ b/src/plothist/scripts/make_examples.py @@ -2,7 +2,6 @@ import yaml import subprocess import plothist -from pytest import fail import hashlib import warnings import sys @@ -112,6 +111,7 @@ def make_examples(no_input=False, check_svg=False, print_code=False): svg_metadata = "metadata=" + str(svg_metadata) if check_svg: + from pytest import fail img_hashes = {} for file in os.listdir(img_folder): if file.endswith(".svg"): @@ -150,7 +150,7 @@ def make_examples(no_input=False, check_svg=False, print_code=False): capture_output=True, text=True, ) - if result.returncode != 0: + if result.returncode != 0 and check_svg: fail(f"Error while redoing {file}:\n{result.stderr}\n{result.stdout}") # Move the svg files to the img folder