Skip to content

Commit

Permalink
feat: adapting conf.py to properly format it
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPasMue committed Sep 20, 2024
1 parent f6927e5 commit 7ba9a25
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.2420.81" # noqa: E501


###########################################################################

# -------------------------------------------------------------------------
# Defining Sphinx build hooks
# -------------------------------------------------------------------------

###########################################################################
# Generate the package_versions directory
###########################################################################
Expand Down Expand Up @@ -350,17 +356,15 @@ def get_release_branches_in_metapackage():
return ["main"] + release_branches, ["dev"] + versions


# -------------------------------------------------------------------------
# Execute the previous functions to generate the package_versions directory
# -------------------------------------------------------------------------

branches, versions = get_release_branches_in_metapackage()
generate_rst_files(
versions,
{version: build_versions_table(branch) for version, branch in zip(versions, branches)},
)

###########################################################################
# Adapting thumbnails to the documentation
###########################################################################
# This section adapts the thumbnails to the documentation. The thumbnails
# are resized to 640x480 pixels and centered on a white background.
#
# The script resizes all images in the _static/thumbnails directory to 640x480
# pixels and saves the resized images in the same directory. After the
# documentation build, the script reverts the changes to the thumbnails.


def resize_with_background(input_image_path, output_image_path, target_size):
Expand Down Expand Up @@ -402,6 +406,11 @@ def resize_with_background(input_image_path, output_image_path, target_size):
# Save the result to the output path
background.save(output_image_path)

###########################################################################

#--------------------------------------------------------------------------
# Sphinx build hooks
#--------------------------------------------------------------------------

def resize_thumbnails(app: sphinx.application.Sphinx):
"""Resize all images in the current directory to 640x480 pixels."""
Expand All @@ -422,6 +431,14 @@ def revert_thumbnails(app: sphinx.application.Sphinx, exception):

subprocess.run(["git", "checkout", "--", thumbnail_dir])

def package_versions_table(app: sphinx.application.Sphinx):
"""Generate the package_versions directory."""
branches, versions = get_release_branches_in_metapackage()
generate_rst_files(
versions,
{version: build_versions_table(branch) for version, branch in zip(versions, branches)},
)

def setup(app: sphinx.application.Sphinx):
"""Run different hook functions during the documentation build.
Expand All @@ -432,6 +449,7 @@ def setup(app: sphinx.application.Sphinx):
"""
# At the beginning of the build process - update the version in cheatsheet
app.connect("builder-inited", resize_thumbnails)
app.connect("builder-inited", package_versions_table)

# Reverting the thumbnails - no local changes
app.connect("build-finished", revert_thumbnails)

0 comments on commit 7ba9a25

Please sign in to comment.