aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-09-13 09:08:21 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-09-13 18:37:57 +0000
commitba91461927bb71377e147830183aa6fcf2a72567 (patch)
tree5b386dbe10be708fe1b5f51d20d824ebca6b85bc
parent9c6d0451cee8b96486bc25a27bbb8769e300f970 (diff)
Documentation/patch_qhp.py: Brush up script
- Fix flake8 warnings - Warn about errors - Move line processing into a function for further extension - Make file a positional argument Change-Id: Ice191b8b78ff3a151581066ae0fc493ecb54fb64 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit 3b31a65a76de7f29f32c27201b35f5f3c17d14e5) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/doc/CMakeLists.txt2
-rw-r--r--sources/shiboken6/doc/CMakeLists.txt2
-rw-r--r--sources/shiboken6/doc/scripts/patch_qhp.py63
3 files changed, 40 insertions, 27 deletions
diff --git a/sources/pyside6/doc/CMakeLists.txt b/sources/pyside6/doc/CMakeLists.txt
index 61133c97a..93c4b995a 100644
--- a/sources/pyside6/doc/CMakeLists.txt
+++ b/sources/pyside6/doc/CMakeLists.txt
@@ -215,7 +215,7 @@ else()
set(PATCH_QHP_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/../../shiboken6/doc/scripts/patch_qhp.py")
file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/html/PySide.qhp QHP_FILE)
add_custom_command(TARGET apidoc POST_BUILD
- COMMAND ${python_executable} ${PATCH_QHP_SCRIPT} -f ${QHP_FILE} -v pyside6
+ COMMAND ${python_executable} ${PATCH_QHP_SCRIPT} -v pyside6 ${QHP_FILE}
COMMAND "${qhelpgenerator_binary}" ${QHP_FILE}
COMMENT "Generating QCH from a QHP file..."
VERBATIM
diff --git a/sources/shiboken6/doc/CMakeLists.txt b/sources/shiboken6/doc/CMakeLists.txt
index acf9acc94..0f909b3c5 100644
--- a/sources/shiboken6/doc/CMakeLists.txt
+++ b/sources/shiboken6/doc/CMakeLists.txt
@@ -41,7 +41,7 @@ if(SPHINX_BUILD)
endif()
add_custom_command(TARGET doc POST_BUILD
- COMMAND "${python_executable}" ${PATCH_QHP_SCRIPT} -f ${QHP_FILE} -v shiboken6
+ COMMAND "${python_executable}" ${PATCH_QHP_SCRIPT} -v shiboken6 ${QHP_FILE}
COMMAND "${qhelpgenerator_binary}" ${QHP_FILE}
COMMENT "Generating shiboken documentation QCH files based on the QHP files"
VERBATIM)
diff --git a/sources/shiboken6/doc/scripts/patch_qhp.py b/sources/shiboken6/doc/scripts/patch_qhp.py
index a9f858889..9c7c875ae 100644
--- a/sources/shiboken6/doc/scripts/patch_qhp.py
+++ b/sources/shiboken6/doc/scripts/patch_qhp.py
@@ -39,31 +39,44 @@
import fileinput
import re
+import sys
from argparse import ArgumentParser, RawTextHelpFormatter
-options = ArgumentParser(description='Qhp file updater',
- formatter_class=RawTextHelpFormatter)
-options.add_argument('-f',
- '--filename',
- type=str,
- help='Qhp filename with the relative path.',
- required=True)
-options.add_argument('-v',
- '--vfolder',
- type=str,
- help='String to be injected into the Qhp file.')
-args=options.parse_args()
-try:
- for line in fileinput.input(args.filename,inplace=True,backup='.bak'):
- line_copy=line.strip()
- if not line_copy: # check for empty line
- continue
- match=re.match('(^.*virtualFolder.)doc(.*$)',line)
- if match:
- repl=''.join([match.group(1), args.vfolder, match.group(2)])
- print(line.replace(match.group(0),repl),end=' ')
- else:
- print(line.rstrip())
-except:
- pass
+DESC="""Qhp file updater
+
+Replaces virtual folder ids in .qhp files preparing for
+registering the documentation in Qt Assistant."""
+
+
+VIRTUAL_FOLDER_PATTERN = re.compile("(^.*virtualFolder.)doc(.*$)")
+
+
+virtual_folder = ""
+
+
+def process_line(line):
+ global virtual_folder
+ match = VIRTUAL_FOLDER_PATTERN.match(line)
+ if match:
+ print(f"{match.group(1)}{virtual_folder}{match.group(2)}")
+ return
+ sys.stdout.write(line)
+
+
+if __name__ == '__main__':
+ arg_parser = ArgumentParser(description=DESC,
+ formatter_class=RawTextHelpFormatter)
+ arg_parser.add_argument('-v', '--vfolder', type=str,
+ help='String to be injected into the Qhp file.')
+ arg_parser.add_argument("file", type=str, help='Qhp filename.')
+ options = arg_parser.parse_args()
+ virtual_folder = options.vfolder
+
+ try:
+ with fileinput.input(options.file, inplace=True,
+ backup=".bak") as fh:
+ for line in fh:
+ process_line(line)
+ except Exception as e:
+ print(f"WARNING: patch_qhp.py failed: {e}", file=sys.stderr)