From beea684159dd9439836b0213cd1e420cbc7ac884 Mon Sep 17 00:00:00 2001 From: danibene <34680344+danibene@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:50:46 -0400 Subject: [PATCH] Revert "add postprocessing to conf.py" This reverts commit 3cee75d8fd81e66ab430cdd7e09c33b46f11213d. --- .readthedocs.yml | 3 +++ docs/Makefile | 5 ++++ docs/conf.py | 59 ------------------------------------------------ tox.ini | 2 +- 4 files changed, 9 insertions(+), 60 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 65bdb8f..a33a517 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -20,6 +20,9 @@ build: os: ubuntu-22.04 tools: python: "3.10" + jobs: + post_build: + - python docs/postprocess.py --path "$READTHEDOCS_OUTPUT/html" python: install: diff --git a/docs/Makefile b/docs/Makefile index 31655dd..236359e 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -20,6 +20,10 @@ endif help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +postprocess: + @echo "Running postprocessing script..." + python ./postprocess.py + clean: rm -rf $(BUILDDIR)/* $(AUTODOCDIR) @@ -27,3 +31,4 @@ clean: # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + @$(MAKE) postprocess diff --git a/docs/conf.py b/docs/conf.py index cdd9cfe..8f6d206 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,18 +12,6 @@ import sys from pathlib import Path import shutil -import argparse # Import the argparse module -import re -from pathlib import Path -from typing import Match, Union - -from bs4 import BeautifulSoup, Tag - -try: - from emoji import emojize -except ImportError: - print("Error: package not found, install 'emoji' package with 'pip install emoji'") - # -- Path setup -------------------------------------------------------------- @@ -330,50 +318,3 @@ } print(f"loading configurations for {project} {version} ...", file=sys.stderr) - -def match_to_emoji(m: Match[str]) -> str: - """Call emoji.emojize on m).""" - return emojize(m.group()) - - -def emojize_all(s: str) -> str: - """Convert all emojis :aliases: of the string s to emojis in UTF-8.""" - return re.sub(r":([a-z_-]+):", match_to_emoji, s) - - -def update_image_paths(soup: BeautifulSoup) -> None: - """Update src attribute of img tags starting with 'utils/'.""" - imgs = soup.find_all("img", src=re.compile("^utils/")) - for img in imgs: - if isinstance(img, Tag): # Ensuring that 'img' is a Tag object - img["src"] = img["src"].replace("utils/", "_images/") - - -def process_html_file(html_file: Union[str, Path]) -> None: - """Process an individual HTML file.""" - with open(html_file, "r", encoding="utf-8") as file: - content = file.read() - - content = emojize_all(content) - soup = BeautifulSoup(content, "html.parser") - update_image_paths(soup) - - with open(html_file, "w", encoding="utf-8") as file: - file.write(str(soup)) - -def postprocess(app, exception): - __location__: Path = Path(__file__).parent - base_path = __location__ / "_build" / "html" - - html_files: list[Path] = list(base_path.glob("*.html")) - - for html_file in html_files: - print(f"Processing {html_file}...") - process_html_file(html_file) - - print("HTML postprocessing completed.") - # stuff to edit and save the html - -def setup(app): - app.connect('build-finished', postprocess) - diff --git a/tox.ini b/tox.ini index b0565db..4667724 100644 --- a/tox.ini +++ b/tox.ini @@ -73,7 +73,7 @@ deps = -r {toxinidir}/docs/requirements.txt # ^ requirements.txt shared with Read The Docs commands = - sphinx-build --color -b {env:BUILD} -d "{env:BUILDDIR}/doctrees" "{env:DOCSDIR}" "{env:BUILDDIR}/{env:BUILD}" {posargs} + make -C {toxinidir}/docs html [testenv:publish] description =