From d77555b14aac208f8a192813e4e33d0344952a32 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 15 Jan 2025 18:48:13 +0000 Subject: [PATCH 1/6] Website prebuild: delete some more files. Delete some files that aren't part of the git repository, but may exist in a checkout and will cause the website build to misbehave or break. --- website/prebuild.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/website/prebuild.py b/website/prebuild.py index 17bdf86afc31c..25503024ae35c 100755 --- a/website/prebuild.py +++ b/website/prebuild.py @@ -142,15 +142,36 @@ def label_root_file( add_frontmatter(f, f.read_text(), [title], top_nav_order, has_children) +def unlink_dir(path: Path) -> None: + # TODO: Use path.walk once we require Python 3.12. + for root, dirs, files in os.walk(path, topdown=False): + root_path = Path(root) + for name in files: + (root_path / name).unlink() + for name in dirs: + (root_path / name).rmdir() + + def main() -> None: # Ensure this runs from the repo root. os.chdir(Path(__file__).parents[1]) + # bazel-generated symlinks interfere with jekyll because they may contain + # broken symlinks. + Path("bazel-out").unlink(missing_ok=True) + Path("bazel-bin").unlink(missing_ok=True) + Path("bazel-genfiles").unlink(missing_ok=True) # bazel-execroot interferes with jekyll because it's a broken symlink. Path("bazel-execroot").unlink() # This is a symlink to website/favicon.png, which is moved below. # TODO: Consider moving the icon to a location which won't break. Path("utils/vscode/images/icon.png").unlink() + # This may contain a README.md file that jekyll can't parse and that + # shouldn't appear in the navigation tree. + unlink_dir(Path("utils/vscode/node_modules")) + # This can cause a failure if jekyll has already been run prior to + # prebuild. + unlink_dir(Path("website/.jekyll-cache")) # The external symlink is created by scripts/create_compdb.py, and can # interfere with local execution. From e579a01f8d8a8de5770d8e118928b395fdbc6b45 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 15 Jan 2025 22:24:01 +0000 Subject: [PATCH 2/6] Avoid deleting things; exclude them instead. --- website/_config.yml | 7 +++++++ website/prebuild.py | 33 ++++----------------------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/website/_config.yml b/website/_config.yml index 5bdd916bc478a..892105753c735 100644 --- a/website/_config.yml +++ b/website/_config.yml @@ -10,6 +10,13 @@ theme: just-the-docs favicon_ico: '/favicon.png' +exclude: + - '.*' + - '**/node_modules' + - '**/dist' + - 'bazel-*' + - 'utils/vscode/images/icon.png' + aux_links: Discord: https://discord.gg/ZjVdShJDAs GitHub: https://github.com/carbon-language/carbon-lang diff --git a/website/prebuild.py b/website/prebuild.py index 25503024ae35c..1186519437c73 100755 --- a/website/prebuild.py +++ b/website/prebuild.py @@ -10,6 +10,7 @@ import os from pathlib import Path import re +import shutil from typing import Optional __copyright__ = """ @@ -88,7 +89,8 @@ def label_subdir( readme_titles = [readme_title] if parent_title: readme_titles.insert(0, parent_title) - children = [x for x in subdir.glob("**/*.md") if x != readme] + children = [x for x in subdir.glob("**/*.md") + if x != readme and '/node_modules/' not in str(x) and '/dist/' not in str(x)] add_frontmatter( readme, readme_content, readme_titles, top_nav_order, bool(children) ) @@ -142,37 +144,10 @@ def label_root_file( add_frontmatter(f, f.read_text(), [title], top_nav_order, has_children) -def unlink_dir(path: Path) -> None: - # TODO: Use path.walk once we require Python 3.12. - for root, dirs, files in os.walk(path, topdown=False): - root_path = Path(root) - for name in files: - (root_path / name).unlink() - for name in dirs: - (root_path / name).rmdir() - - def main() -> None: # Ensure this runs from the repo root. os.chdir(Path(__file__).parents[1]) - # bazel-generated symlinks interfere with jekyll because they may contain - # broken symlinks. - Path("bazel-out").unlink(missing_ok=True) - Path("bazel-bin").unlink(missing_ok=True) - Path("bazel-genfiles").unlink(missing_ok=True) - # bazel-execroot interferes with jekyll because it's a broken symlink. - Path("bazel-execroot").unlink() - # This is a symlink to website/favicon.png, which is moved below. - # TODO: Consider moving the icon to a location which won't break. - Path("utils/vscode/images/icon.png").unlink() - # This may contain a README.md file that jekyll can't parse and that - # shouldn't appear in the navigation tree. - unlink_dir(Path("utils/vscode/node_modules")) - # This can cause a failure if jekyll has already been run prior to - # prebuild. - unlink_dir(Path("website/.jekyll-cache")) - # The external symlink is created by scripts/create_compdb.py, and can # interfere with local execution. external = Path("external") @@ -181,7 +156,7 @@ def main() -> None: # Move files to the repo root. for f in Path("website").iterdir(): - if f.name == "README.md": + if f.name in ["README.md", '.jekyll-cache', '_site']: continue f.rename(f.name) From 5b72160b4df7f41faee4e539dedbd0399a2d4648 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 15 Jan 2025 22:46:09 +0000 Subject: [PATCH 3/6] Formatting and unused import fixes. --- website/prebuild.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/website/prebuild.py b/website/prebuild.py index 1186519437c73..281e3967614ba 100755 --- a/website/prebuild.py +++ b/website/prebuild.py @@ -10,7 +10,6 @@ import os from pathlib import Path import re -import shutil from typing import Optional __copyright__ = """ @@ -89,8 +88,13 @@ def label_subdir( readme_titles = [readme_title] if parent_title: readme_titles.insert(0, parent_title) - children = [x for x in subdir.glob("**/*.md") - if x != readme and '/node_modules/' not in str(x) and '/dist/' not in str(x)] + children = [ + x + for x in subdir.glob("**/*.md") + if x != readme + and "/node_modules/" not in str(x) + and "/dist/" not in str(x) + ] add_frontmatter( readme, readme_content, readme_titles, top_nav_order, bool(children) ) @@ -156,7 +160,7 @@ def main() -> None: # Move files to the repo root. for f in Path("website").iterdir(): - if f.name in ["README.md", '.jekyll-cache', '_site']: + if f.name in ["README.md", ".jekyll-cache", "_site"]: continue f.rename(f.name) From b0502b7eb2215611e5b450f3db2f7815b11b6874 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 16 Jan 2025 00:17:52 +0000 Subject: [PATCH 4/6] Refactor to avoid complex comprehension. --- website/prebuild.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/website/prebuild.py b/website/prebuild.py index 281e3967614ba..1406fe073d817 100755 --- a/website/prebuild.py +++ b/website/prebuild.py @@ -84,17 +84,25 @@ def label_subdir( readme = subdir / "README.md" readme_content = readme.read_text() + def include_child(md_file: Path) -> bool: + """Determines whether a markdown file should be included in the + navigation tree as a child of this label. + """ + # The top-level README.md isn't a child. + if md_file == readme: + return False + # Skip directories that aren't part of the repository. + if "/node_modules/" in str(md_file): + return False + if "/dist/" in str(md_file): + return False + return True + readme_title = get_title(readme, readme_content) readme_titles = [readme_title] if parent_title: readme_titles.insert(0, parent_title) - children = [ - x - for x in subdir.glob("**/*.md") - if x != readme - and "/node_modules/" not in str(x) - and "/dist/" not in str(x) - ] + children = [x for x in subdir.glob("**/*.md") if include_child(x)] add_frontmatter( readme, readme_content, readme_titles, top_nav_order, bool(children) ) From fca824be89a77ffcc49cb63162684e9b15a1e62a Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 15 Jan 2025 16:39:57 -0800 Subject: [PATCH 5/6] Play a round of comment golf. --- website/prebuild.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/prebuild.py b/website/prebuild.py index 1406fe073d817..0a8967148dafd 100755 --- a/website/prebuild.py +++ b/website/prebuild.py @@ -85,8 +85,7 @@ def label_subdir( readme_content = readme.read_text() def include_child(md_file: Path) -> bool: - """Determines whether a markdown file should be included in the - navigation tree as a child of this label. + """Returns whether md_file is a child of this label. """ # The top-level README.md isn't a child. if md_file == readme: From fe7617fe77a48953da520d0c852e547ec25fe900 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 17 Jan 2025 12:43:53 -0800 Subject: [PATCH 6/6] Update website/prebuild.py Co-authored-by: Carbon Infra Bot --- website/prebuild.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/prebuild.py b/website/prebuild.py index 0a8967148dafd..a2d56657aba28 100755 --- a/website/prebuild.py +++ b/website/prebuild.py @@ -85,8 +85,7 @@ def label_subdir( readme_content = readme.read_text() def include_child(md_file: Path) -> bool: - """Returns whether md_file is a child of this label. - """ + """Returns whether md_file is a child of this label.""" # The top-level README.md isn't a child. if md_file == readme: return False