From 305a298ae288d370a4534009a9e1ca2cfbb31e01 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 27 Jan 2025 02:04:54 +0100 Subject: [PATCH] Simplify build_docs.py (#18910) Signed-off-by: Glenn Jocher --- docs/build_docs.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/build_docs.py b/docs/build_docs.py index e75219aa..d8b04835 100644 --- a/docs/build_docs.py +++ b/docs/build_docs.py @@ -49,23 +49,29 @@ def create_vercel_config(): def prepare_docs_markdown(clone_repos=True): """Build docs using mkdocs.""" - if SITE.exists(): - print(f"Removing existing {SITE}") - shutil.rmtree(SITE) + print("Removing existing build artifacts") + shutil.rmtree(SITE, ignore_errors=True) + shutil.rmtree(DOCS / "repos", ignore_errors=True) - # Get hub-sdk repo if clone_repos: + # Get hub-sdk repo repo = "https://github.com/ultralytics/hub-sdk" - local_dir = DOCS.parent / Path(repo).name - if not local_dir.exists(): - os.system(f"git clone {repo} {local_dir}") - os.system(f"git -C {local_dir} pull") # update repo + local_dir = DOCS / "repos" / Path(repo).name + os.system(f"git clone {repo} {local_dir} --depth 1 --single-branch --branch main") shutil.rmtree(DOCS / "en/hub/sdk", ignore_errors=True) # delete if exists shutil.copytree(local_dir / "docs", DOCS / "en/hub/sdk") # for docs shutil.rmtree(DOCS.parent / "hub_sdk", ignore_errors=True) # delete if exists shutil.copytree(local_dir / "hub_sdk", DOCS.parent / "hub_sdk") # for mkdocstrings print(f"Cloned/Updated {repo} in {local_dir}") + # Get docs repo + repo = "https://github.com/ultralytics/docs" + local_dir = DOCS / "repos" / Path(repo).name + os.system(f"git clone {repo} {local_dir} --depth 1 --single-branch --branch main") + shutil.rmtree(DOCS / "en/compare", ignore_errors=True) # delete if exists + shutil.copytree(local_dir / "docs/en/compare", DOCS / "en/compare") # for docs + print(f"Cloned/Updated {repo} in {local_dir}") + # Add frontmatter for file in tqdm((DOCS / "en").rglob("*.md"), desc="Adding frontmatter"): update_markdown_files(file) @@ -317,6 +323,10 @@ def main(): # Minify files minify_files(html=False, css=False, js=False) + # Cleanup + shutil.rmtree(DOCS.parent / "hub_sdk", ignore_errors=True) + shutil.rmtree(DOCS / "repos", ignore_errors=True) + # Show command to serve built website print('Docs built correctly ✅\nServe site at http://localhost:8000 with "python -m http.server --directory site"')