Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions ci/customization/customize_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ def delete_existing_elements(soup):
delete_element(soup, element)


class UnsupportedThemeError(ValueError):
"""
Custom exception indicating that a document uses a Sphinx theme this script
either cannot identify or does not know how to modify.
"""

pass


def get_theme_info(soup, *, filepath: str):
"""
Determines what theme a given HTML file is using or exits if it's
Expand All @@ -279,11 +288,9 @@ def get_theme_info(soup, *, filepath: str):
if soup.select(pydata_identifier):
return "pydata", soup.select(pydata_identifier)[0]

print(
f"Couldn't identify {filepath} as a supported theme type. Skipping file.",
file=sys.stderr,
raise UnsupportedThemeError(
f"Couldn't identify {filepath} as a supported theme type. Skipping file."
)
exit(0)


def main(*, filepath: str, lib_path_dict: dict, versions_dict: dict[str, str]) -> None:
Expand All @@ -304,7 +311,11 @@ def main(*, filepath: str, lib_path_dict: dict, versions_dict: dict[str, str]) -
with open(filepath) as fp:
soup = BeautifulSoup(fp, "html5lib")

doc_type, reference_el = get_theme_info(soup, filepath=filepath)
try:
doc_type, reference_el = get_theme_info(soup, filepath=filepath)
except UnsupportedThemeError as err:
print(f"{str(err)}", file=sys.stderr)
return

# Delete any existing added/unnecessary elements
delete_existing_elements(soup)
Expand Down
4 changes: 2 additions & 2 deletions ci/customization/customize_docs_in_folder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Positional Arguments:
# 1) FOLDER_TO_CUSTOMIZE: project root relative folder to customize (i.e. api/, api/rmm, etc.)
#######################################
set -e
set -euo pipefail

display_usage() {
echo "Usage:"
Expand Down Expand Up @@ -51,5 +51,5 @@ grep "${JTD_SEARCH_TERM}\|${DOXYGEN_SEARCH_TERM}\|${PYDATA_SEARCH_TERM}" -rl \
> "${MANIFEST_FILE}"

echo "Customizing $(wc -l < ${MANIFEST_FILE} | tr -d ' ') HTML files"
python ${SCRIPT_SRC_FOLDER}/customize_doc.py "${MANIFEST_FILE}"
python -u ${SCRIPT_SRC_FOLDER}/customize_doc.py "${MANIFEST_FILE}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those finding this PR from search... adding -u ensures that Python stdout / stderr are printed immediately ("unbuffered").

I found that the warning about unrecognized sphinx themes, which goes to stderr, was not being printed immediately after the log messages about that same file printed to stdout.

Removing buffering fixes that.

echo "Done customizing"