Skip to content

Commit 1743a43

Browse files
committed
Show which paths changed when rebuilding
1 parent 028cf60 commit 1743a43

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

sphinx_autobuild/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def main(argv=()):
8383

8484
if not args.no_initial_build:
8585
show_message("Starting initial build")
86-
builder(rebuild=False)
86+
builder(changed_paths=())
8787

8888
if args.open_browser:
8989
open_browser(url_host, args.delay)

sphinx_autobuild/build.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
from __future__ import annotations
44

5+
import contextlib
56
import subprocess
67
import sys
8+
from collections.abc import Sequence
9+
from pathlib import Path
710

811
import sphinx
912

@@ -16,10 +19,20 @@ def __init__(self, sphinx_args, *, url_host, pre_build_commands):
1619
self.pre_build_commands = pre_build_commands
1720
self.uri = f"http://{url_host}"
1821

19-
def __call__(self, *, rebuild: bool = True):
22+
def __call__(self, *, changed_paths: Sequence[Path]):
2023
"""Generate the documentation using ``sphinx``."""
21-
if rebuild:
22-
show_message("Detected change. Rebuilding...")
24+
if changed_paths:
25+
cwd = Path.cwd()
26+
rel_paths = []
27+
for changed_path in changed_paths[:5]:
28+
if not changed_path.exists():
29+
continue
30+
with contextlib.suppress(ValueError):
31+
changed_path = changed_path.relative_to(cwd)
32+
rel_paths.append(changed_path.as_posix())
33+
if rel_paths:
34+
show_message(f"Detected changes ({', '.join(rel_paths)})")
35+
show_message("Rebuilding...")
2336

2437
try:
2538
for command in self.pre_build_commands:

sphinx_autobuild/server.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
if TYPE_CHECKING:
1313
import os
14-
from collections.abc import Callable
14+
from collections.abc import Callable, Sequence
1515

1616
from starlette.types import Receive, Scope, Send
1717

@@ -23,7 +23,7 @@ def __init__(
2323
self,
2424
paths: list[os.PathLike[str]],
2525
ignore_filter: IgnoreFilter,
26-
change_callback: Callable[[], None],
26+
change_callback: Callable[[Sequence[Path]], None],
2727
) -> None:
2828
self.paths = [Path(path).resolve(strict=True) for path in paths]
2929
self.ignore = ignore_filter
@@ -49,12 +49,13 @@ async def main(self) -> None:
4949
[task.result() for task in done]
5050

5151
async def watch(self) -> None:
52-
async for _changes in watchfiles.awatch(
52+
async for changes in watchfiles.awatch(
5353
*self.paths,
5454
watch_filter=lambda _, path: not self.ignore(path),
5555
):
56+
changed_paths = [Path(path).resolve() for (_, path) in changes]
5657
with ProcessPoolExecutor() as pool:
57-
fut = pool.submit(self.change_callback)
58+
fut = pool.submit(self.change_callback, changed_paths=changed_paths)
5859
await asyncio.wrap_future(fut)
5960
self.flag.set()
6061

tests/test_application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_application(tmp_path):
2626
app = _create_app([src_dir], ignore_handler, builder, out_dir, url_host)
2727
client = TestClient(app)
2828

29-
builder(rebuild=False)
29+
builder(changed_paths=())
3030

3131
response = client.get("/")
3232
assert response.status_code == 200

0 commit comments

Comments
 (0)