]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: generate html-docs using meson compile html-docs
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 17 Feb 2025 11:46:47 +0000 (12:46 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 17 Feb 2025 14:24:22 +0000 (15:24 +0100)
docs/generate-docs.py [new file with mode: 0755]
pdns/recursordist/docs/generate-docs.py [new symlink]
pdns/recursordist/meson.build

diff --git a/docs/generate-docs.py b/docs/generate-docs.py
new file mode 100755 (executable)
index 0000000..f820aab
--- /dev/null
@@ -0,0 +1,105 @@
+"""Generate docs using sphinx in a venv."""
+
+import argparse
+import glob
+import itertools
+import subprocess
+import sys
+import venv
+from pathlib import Path
+
+
+def main():
+    """Start the script."""
+    args = create_argument_parser()
+
+    source_root = args.source_root
+    build_root = args.build_root
+
+    # Create the venv.
+    venv_directory = build_root.joinpath(args.venv_name)
+    venv.create(
+        venv_directory,
+        with_pip=True,
+        clear=True,
+        upgrade_deps=True,
+        prompt=args.venv_name,
+    )
+
+    # Install some stuff into the venv.
+    requirements_file = source_root.joinpath(args.requirements_file)
+    pip = venv_directory.joinpath("bin").joinpath("pip")
+    subprocess.run([pip, "install", "-U", "pip", "setuptools", "wheel"], check=True)
+    subprocess.run([pip, "install", "-r", requirements_file], check=True)
+
+    # Run sphinx to generate the man-pages.
+    source_directory = source_root.joinpath(args.source_directory)
+    target_directory = build_root.joinpath(args.target_directory)
+    files = [glob.glob(str(source_root.joinpath(pat))) for pat in args.files]
+    files = list(itertools.chain.from_iterable(files))
+    sphinx_build = venv_directory.joinpath("bin").joinpath("sphinx-build")
+    subprocess.run(
+        [
+            sphinx_build,
+            "-b",
+            "html",
+            source_directory,
+            target_directory,
+        ]
+        + files, # default is to do all
+        check=True
+    )
+
+
+def create_argument_parser():
+    """Create command-line argument parser."""
+    parser = argparse.ArgumentParser(
+        description="Create a virtualenv from a requirements file"
+    )
+    parser.add_argument(
+        "--build-root",
+        type=Path,
+        required=True,
+        help="Build root",
+    )
+    parser.add_argument(
+        "--source-root",
+        type=Path,
+        required=True,
+        help="Source root",
+    )
+    parser.add_argument(
+        "--venv-name",
+        type=str,
+        required=True,
+        help="Name for the virtualenv",
+    )
+    parser.add_argument(
+        "--requirements-file",
+        type=Path,
+        required=True,
+        help="Package requirements file relative to the source root",
+    )
+    parser.add_argument(
+        "--source-directory",
+        type=Path,
+        required=True,
+        help="Docs directory relative to the source root (contains conf.py)",
+    )
+    parser.add_argument(
+        "--target-directory",
+        type=Path,
+        required=True,
+        help="Target directory for man-pages relative to the build root",
+    )
+    parser.add_argument(
+        "files",
+        type=Path,
+        nargs="*",
+        help="Input files relative to the source root",
+    )
+    return parser.parse_args()
+
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/pdns/recursordist/docs/generate-docs.py b/pdns/recursordist/docs/generate-docs.py
new file mode 120000 (symlink)
index 0000000..4862bfd
--- /dev/null
@@ -0,0 +1 @@
+../../../docs/generate-docs.py
\ No newline at end of file
index e369367bd44f77e527f546586694f426fcf52068..38ce7c09a7a7f0adbf32812c21114a3de4269f14 100644 (file)
@@ -734,3 +734,16 @@ dep_conf_distfile = custom_target(
   install_dir:  get_option('sysconfdir'),
 )
 
+run_target(
+  'html-docs',
+  command: [
+      python,
+      product_source_dir / docs_dir / 'generate-docs.py',
+      '--build-root', '@BUILD_ROOT@',
+      '--source-root', '@SOURCE_ROOT@',
+      '--venv-name', 'venv-docs',
+      '--requirements-file', docs_dir / 'requirements.txt',
+      '--source-directory', docs_dir,
+      '--target-directory', '@BUILD_ROOT@' / 'html-docs',
+  ]
+)
\ No newline at end of file