From 5f7af8d97d81c620071e8b639a694b3a7135e2f8 Mon Sep 17 00:00:00 2001 From: Callum Macpherson <93673602+CalMacCQ@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:00:22 +0000 Subject: [PATCH] fix: remove unecessary `_tket` perfix in local docs build (#1721) * update build script to replace _tket * delete unused makefile * uncomment sed * fix path for searchindex.js sed * final fix for search index replace * make shell script work for linux and mac * uupdate script to align with website build * minor edits * fix comment --- pytket/docs/Makefile | 27 --------------------------- pytket/docs/build-docs.sh | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 28 deletions(-) delete mode 100644 pytket/docs/Makefile diff --git a/pytket/docs/Makefile b/pytket/docs/Makefile deleted file mode 100644 index 8039fcc515..0000000000 --- a/pytket/docs/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# Makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -SOURCEDIR = . -BUILDDIR = build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# 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) - find build/html/ -type f -name "*.html" | xargs sed -i 's/pytket._tket/pytket/g' - sed -i 's/pytket._tket/pytket/g' build/html/searchindex.js - -# for local builds on mac (mac sed is slightly different) -html-mac: - @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - find build/html/ -type f -name "*.html" | xargs sed -e 's/pytket._tket/pytket/g' -i "" - sed -e 's/pytket._tket/pytket/g' -i "" build/html/searchindex.js diff --git a/pytket/docs/build-docs.sh b/pytket/docs/build-docs.sh index a5cb926d21..f33746eb15 100644 --- a/pytket/docs/build-docs.sh +++ b/pytket/docs/build-docs.sh @@ -2,7 +2,23 @@ cp -R pytket-docs-theming/_static . cp -R pytket-docs-theming/quantinuum-sphinx . cp pytket-docs-theming/conf.py . -sphinx-build -b html . build -D html_title="pytket" +# Get pytket package version to be used in page title +PYTKET_VERSION="$(pip show pytket| grep Version | awk '{print $2}')" + +PACKAGE="pytket $PYTKET_VERSION" + +# Build the docs setting the html title to show the correct pytket version. +sphinx-build -b html . build -D html_title="$PACKAGE API documentation" + +# Replace unnecessary _tket for all classes and functions in the built html +# Apple MACOSX and Linux have differing sed replace syntax +if [[ "$OSTYPE" == "darwin"* ]]; then + find build/ -type f -name "*.html" | xargs sed -e 's/pytket._tket/pytket/g' -i "" + sed -i '' 's/pytket._tket/pytket/g' build/searchindex.js +else + find build/ -type f -name "*.html" | xargs sed -i 's/pytket._tket/pytket/g' + sed -i 's/pytket._tket/pytket/g' build/searchindex.js +fi # Remove copied files. This ensures reusability. rm -r _static