From 9dc7a0b258ff2cca889d0946820df3378d075d1c Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Wed, 27 Mar 2024 17:31:26 +0900 Subject: [PATCH 1/8] Fonts bugfix + pytest dependancy added --- pyproject.toml | 1 + .../scripts/install_latin_modern_fonts.py | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 50cfe6d7..5b99e921 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ dependencies = [ "matplotlib>=3.0", "pyyaml>=5.3.1", "scipy>=1.6.0", + "pytest>=7.0.0", ] [project.urls] diff --git a/src/plothist/scripts/install_latin_modern_fonts.py b/src/plothist/scripts/install_latin_modern_fonts.py index ab1f41b9..5b5d7c97 100644 --- a/src/plothist/scripts/install_latin_modern_fonts.py +++ b/src/plothist/scripts/install_latin_modern_fonts.py @@ -3,6 +3,24 @@ import platform from pathlib import PosixPath import time +import re + + +def _get_wget_version(): + try: + version_string = subprocess.check_output( + ["wget", "--version"], universal_newlines=True + ) + version_match = re.search(r"(\d+\.\d+\.\d+)", version_string) + if not version_match: + 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.") + except Exception as e: + return str(e) def _get_install_command(url, font_directory): @@ -24,7 +42,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 From fd4fd032e65e5a79f270850b013c645c6c74a23c Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 28 Mar 2024 12:57:35 +0900 Subject: [PATCH 2/8] remove pytest dependence --- pyproject.toml | 1 - src/plothist/scripts/make_examples.py | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5b99e921..50cfe6d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,6 @@ dependencies = [ "matplotlib>=3.0", "pyyaml>=5.3.1", "scipy>=1.6.0", - "pytest>=7.0.0", ] [project.urls] diff --git a/src/plothist/scripts/make_examples.py b/src/plothist/scripts/make_examples.py index 20cef4fe..8cd3d4d2 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 @@ -35,6 +34,9 @@ def make_examples(no_input=False, check_svg=False, print_code=False): ) return 1 + if check_svg: + from pytest import fail + plothist_folder = ( plothist.__path__[0] if os.environ.get("PLOTHIST_PATH") is None @@ -150,7 +152,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 From 469441ed247532b8cc42de672a08aac7be1f18da Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 28 Mar 2024 13:52:18 +0900 Subject: [PATCH 3/8] docstring for _get_wget_version --- .../scripts/install_latin_modern_fonts.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/plothist/scripts/install_latin_modern_fonts.py b/src/plothist/scripts/install_latin_modern_fonts.py index 5b5d7c97..3212a2b0 100644 --- a/src/plothist/scripts/install_latin_modern_fonts.py +++ b/src/plothist/scripts/install_latin_modern_fonts.py @@ -7,12 +7,27 @@ 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. + """ try: version_string = subprocess.check_output( ["wget", "--version"], universal_newlines=True ) + # Try to find the version number in the format "1.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 "1.XX" version_match = re.search(r"(\d+\.\d+)", version_string) if version_match: version = version_match.group(1) From a74f17f2a125d028788425cd6ed7fab6cf811cfe Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 28 Mar 2024 13:53:08 +0900 Subject: [PATCH 4/8] remove try excpet in _get_wget_version --- .../scripts/install_latin_modern_fonts.py | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/plothist/scripts/install_latin_modern_fonts.py b/src/plothist/scripts/install_latin_modern_fonts.py index 3212a2b0..172b2752 100644 --- a/src/plothist/scripts/install_latin_modern_fonts.py +++ b/src/plothist/scripts/install_latin_modern_fonts.py @@ -20,22 +20,19 @@ def _get_wget_version(): RuntimeError If the version of wget could not be determined. """ - try: - version_string = subprocess.check_output( - ["wget", "--version"], universal_newlines=True - ) - # Try to find the version number in the format "1.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 "1.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.") - except Exception as e: - return str(e) + version_string = subprocess.check_output( + ["wget", "--version"], universal_newlines=True + ) + # Try to find the version number in the format "1.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 "1.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): From 26cf9ffb409b7602f05aab7f7f08ba79370df96b Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 28 Mar 2024 13:54:37 +0900 Subject: [PATCH 5/8] docstring for _get_wget_version --- src/plothist/scripts/install_latin_modern_fonts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plothist/scripts/install_latin_modern_fonts.py b/src/plothist/scripts/install_latin_modern_fonts.py index 172b2752..8f0d2f16 100644 --- a/src/plothist/scripts/install_latin_modern_fonts.py +++ b/src/plothist/scripts/install_latin_modern_fonts.py @@ -23,10 +23,10 @@ def _get_wget_version(): version_string = subprocess.check_output( ["wget", "--version"], universal_newlines=True ) - # Try to find the version number in the format "1.XX.XX" + # 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 "1.XX" + # 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) From 4a532345bfb47d22c44c47b241479ecb4175f8e0 Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 28 Mar 2024 15:15:20 +0900 Subject: [PATCH 6/8] added check if unzip fails (End-of-central-directory signature not found error) --- .../scripts/install_latin_modern_fonts.py | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/plothist/scripts/install_latin_modern_fonts.py b/src/plothist/scripts/install_latin_modern_fonts.py index 8f0d2f16..94bd98cf 100644 --- a/src/plothist/scripts/install_latin_modern_fonts.py +++ b/src/plothist/scripts/install_latin_modern_fonts.py @@ -153,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: From 15709a5543f44234dd316a331c5ba98b77d8a811 Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 28 Mar 2024 15:17:13 +0900 Subject: [PATCH 7/8] v1.2.0 -> v1.2.1 --- README.rst | 2 +- docs/conf.py | 4 ++-- src/plothist/__init__.py | 2 +- src/plothist/scripts/make_examples.py | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) 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/make_examples.py b/src/plothist/scripts/make_examples.py index 8cd3d4d2..37fb1025 100644 --- a/src/plothist/scripts/make_examples.py +++ b/src/plothist/scripts/make_examples.py @@ -34,9 +34,6 @@ def make_examples(no_input=False, check_svg=False, print_code=False): ) return 1 - if check_svg: - from pytest import fail - plothist_folder = ( plothist.__path__[0] if os.environ.get("PLOTHIST_PATH") is None @@ -120,6 +117,9 @@ def make_examples(no_input=False, check_svg=False, print_code=False): with open(os.path.join(img_folder, file), "r") as f: img_hashes[file] = hashlib.sha256(f.read().encode()).hexdigest() + if check_svg: + from pytest import fail + # Iterate through all subfolders and files in the source folder for root, dirs, files in os.walk(example_folder): for file in files: From c0202311cfa0f335119dae8447b1ab50c15092f0 Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 28 Mar 2024 15:17:58 +0900 Subject: [PATCH 8/8] import pytest better placement --- src/plothist/scripts/make_examples.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/plothist/scripts/make_examples.py b/src/plothist/scripts/make_examples.py index 37fb1025..dcfda80c 100644 --- a/src/plothist/scripts/make_examples.py +++ b/src/plothist/scripts/make_examples.py @@ -111,15 +111,13 @@ 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"): with open(os.path.join(img_folder, file), "r") as f: img_hashes[file] = hashlib.sha256(f.read().encode()).hexdigest() - if check_svg: - from pytest import fail - # Iterate through all subfolders and files in the source folder for root, dirs, files in os.walk(example_folder): for file in files: