Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GitHub = "https://github.com/jpsca/writeadoc"
dev = [
"ipdb>=0.13.13",
"pytest-cov>=7.0.0",
"pytest-mock>=3.15.1",
"ruff>=0.12.4",
"tox-uv",
"ty>=0.0.1a15",
Expand Down
25 changes: 17 additions & 8 deletions src/writeadoc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,17 @@ def cli(self):
default=False,
help="Generate a `llms.txt` file with all the markdown content",
)
build_parser.add_argument(
"--boring",
action="store_true",
default=False,
help="Remove the random messages from the log output"
)

args = parser.parse_args()

if args.command == "build":
self.cli_build(archive=args.archive, llm=args.llm)
self.cli_build(archive=args.archive, llm=args.llm, boring=args.boring)
elif args.command in (None, "run"):
self.cli_run()
else:
Expand Down Expand Up @@ -168,7 +174,7 @@ def shutdown(*args):
signal.signal(signal.SIGINT, shutdown)
signal.signal(signal.SIGTERM, shutdown)

def cli_build(self, *, archive: bool, llm: bool = False) -> None:
def cli_build(self, *, archive: bool, llm: bool = False, boring: bool = False) -> None:
"""Build the documentation for deployment.
"""
if archive:
Expand All @@ -182,23 +188,25 @@ def cli_build(self, *, archive: bool, llm: bool = False) -> None:
variant.build_dir = self.build_dir
variant.prefix = f"{self.prefix}/{prefix}" if self.prefix else prefix

self.build(devmode=False, llm=llm)
self.build(devmode=False, llm=llm, boring=boring)
print("\nDocumentation built successfully.")
if archive:
print(f"Archived documentation is available in the `archive/{self.site.version}` folder.")
else:
print("Documentation is available in the `build` folder.")

def build(self, *, devmode: bool = True, llm: bool = False) -> None:
messages = get_random_messages(3)
print(f"{messages[0]}...")
def build(self, *, devmode: bool = True, llm: bool = False, boring: bool = False) -> None:
if not boring:
messages = get_random_messages(3)
print(f"{messages[0]}...")

for variant in self.variants.values():
variant.build(devmode=devmode, llm=llm)

print("Processing pages...")
nav, pages = self.pages_processor.run(self.pages)
print(f"{messages[1]}...")
if not boring:
print(f"{messages[1]}...")

self.site.nav = nav
self.site.pages = pages
Expand All @@ -209,7 +217,8 @@ def build(self, *, devmode: bool = True, llm: bool = False) -> None:
print("Rendering pages...")
for page in pages:
self._render_page(page)
print(f"{messages[2]}...")
if not boring:
print(f"{messages[2]}...")

if llm:
print("Building llms.txt...")
Expand Down
60 changes: 60 additions & 0 deletions tests/test_cli_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from unittest.mock import call

import pytest

from writeadoc.main import Docs


@pytest.fixture
def docs(tmp_root):
(tmp_root / "comp").mkdir()
(tmp_root / "comp" / "test.jx").write_text("<h2>{{ content }}</h2>")

(tmp_root / "content" / "test.md").write_text(
"""
---
title: Test Page
imports:
"Test": "test.jx"
---
<Test>This **is** a test</Test>

```
<Test />
<Test></Test>
```
""".strip()
)

docs = Docs(tmp_root, pages=["test.md"])
docs.catalog.add_folder(tmp_root / "comp")
return docs


def test_build_with_random_messages(mocker, docs):
mocker.patch(
"writeadoc.main.get_random_messages", return_value=["one", "two", "three"]
)
mock_print = mocker.patch("builtins.print")
docs.build()
assert mock_print.call_count == 5
mock_print.assert_has_calls([
call("one..."),
call("Processing pages..."),
call("two..."),
call("Rendering pages..."),
call("three..."),
])


def test_build_with_no_random_messages(mocker, docs):
mocker.patch(
"writeadoc.main.get_random_messages", return_value=["one", "two", "three"]
)
mock_print = mocker.patch("builtins.print")
docs.build(boring=True)
assert mock_print.call_count == 2
mock_print.assert_has_calls([
call("Processing pages..."),
call("Rendering pages..."),
])
14 changes: 14 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading