Skip to content

Commit

Permalink
Revert "add postprocessing to conf.py"
Browse files Browse the repository at this point in the history
This reverts commit 3cee75d.
  • Loading branch information
danibene committed Mar 14, 2024
1 parent 3cee75d commit beea684
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ endif
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

postprocess:
@echo "Running postprocessing script..."
python ./postprocess.py

clean:
rm -rf $(BUILDDIR)/* $(AUTODOCDIR)

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(MAKE) postprocess
59 changes: 0 additions & 59 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------------------------

Expand Down Expand Up @@ -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)

2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit beea684

Please sign in to comment.