Skip to content

Commit

Permalink
Add automatic docs/source builder to check the output easily (#3138)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungmanc authored Mar 18, 2024
1 parent cdd7044 commit c76fb06
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ src/**/*.so

# For regression test data storage
for_developers/regression_test/postgres_data/**/*

# docs/reference
docs/source/guide/reference/_autosummary/*
59 changes: 59 additions & 0 deletions docs/utils/auto_sphinx_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""This script enable automatic detect the change of docs/source contents.
It brings the convinient to check the output of the docs.
When you used the VSCode + watchdog, you can easily check the docs output.
1. Open the builded index.rst file with live server (Visual Studio Code extension)
2. Execute this script `auto_sphix_build_for_vscode.py`
3. Then, the watchdog + sphinx builder automatically builds the source when there are changes
"""

import os
import sys
import time
from pathlib import Path
from typing import Any

from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer


class SphinxBuilder(FileSystemEventHandler):
"""Build sphinx docs."""

def on_modified(self, event: Any) -> None: # noqa:ANN401
"""When the file is modified."""
print(f"Changes detected: {event.src_path}")
os.system("sphinx-build -b html ../source ../build") # noqa:S605, S607


def main(path: str) -> None:
"""Main function."""
event_handler: FileSystemEventHandler = SphinxBuilder()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()


if __name__ == "__main__":
print("Auto sphinx builder is ON. It automatically builds the source when the change is detected.")
script_location = Path(__file__).resolve().parent
parent_dir = script_location.parent
source_folder = parent_dir / "source"
print(f"The location of source folder: {source_folder}")
print("Initial build...")
time.sleep(10)
os.system("sphinx-build -b html ../source ../build") # noqa:S605, S607
path: str = sys.argv[1] if len(sys.argv) > 1 else str(source_folder)
main(path)

0 comments on commit c76fb06

Please sign in to comment.