diff options
| author | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2024-08-09 16:37:47 +0200 |
|---|---|---|
| committer | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2024-08-14 13:53:01 +0200 |
| commit | 3f78f5f1a47484d0da2b2c1e8aa623d10de4db80 (patch) | |
| tree | 52c014a4a24c669bbe821ff4b95865857d980c95 /tools/broken_links.py | |
| parent | 1d1274a57f65b5d16e0d007cc3062be1dd4146a4 (diff) | |
Docs: Find broken_links
- Adds a new script that find the broken sphinx links and writes
them into broken_links.json file. This is to be run after running
sphinx-build with linkcheck, which will generate a output.json
file with the status of all the links in the documentation.
- Modified conf.py.in to ignore relative paths when runnning
sphinx-build with linkcheck.
Task-number: PYSIDE-2837
Change-Id: If2437049abc344ad942814a2304c88c4ef7b0c3f
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'tools/broken_links.py')
| -rw-r--r-- | tools/broken_links.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/broken_links.py b/tools/broken_links.py new file mode 100644 index 000000000..b39815551 --- /dev/null +++ b/tools/broken_links.py @@ -0,0 +1,52 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +# broken_links.py +# This script is used to find the broken links in the generated sphinx documentation. + +# Pre-requisites before running this script: +# +# 1. Generate the HTML documentation as given in +# https://doc.qt.io/qtforpython-6/gettingstarted/index.html#building-the-documentation +# . This will generate a folder inside 'pyside-setup' called 'html'. +# 2. Run sphinx-build with linkcheck builder to generate an output.json file inside 'html' folder. +# The command to run is: +# sphinx-build -b linkcheck -j auto -n -c ./html/pyside6/base <folder_of_rst> ./html +# +# The final output will be <output_folder>/broken_links.json + +import json +import argparse +from pathlib import Path + + +def find_broken_links(file_path): + with open(file_path, 'r') as file: + lines = file.readlines() + + broken_links = [] + for line in lines: + entry = json.loads(line) + if entry.get("status") == "broken": + broken_links.append(entry) + + return broken_links + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Find broken links in a JSON file.") + parser.add_argument('--input-file', type=str, required=True, help='Path to the input JSON file') + parser.add_argument('--output-folder', type=str, default=Path(__file__).resolve().parents[2], + help='Path to the output folder') + args = parser.parse_args() + + broken_links = find_broken_links(args.input_file) + + output_file_path = Path(args.output_folder) / 'broken_links.json' + + if broken_links: + with open(output_file_path, 'w') as outfile: + json.dump(broken_links, outfile, indent=4) + print(f"Broken links written to {output_file_path}") + else: + print("No broken links found.") |
