md2site-cli 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- md2site/__init__.py +7 -0
- md2site/__main__.py +10 -0
- md2site/assets.py +211 -0
- md2site/build.py +152 -0
- md2site/cli.py +354 -0
- md2site/config.py +444 -0
- md2site/diagnostics.py +167 -0
- md2site/frontmatter.py +245 -0
- md2site/hook.py +129 -0
- md2site/init_cmd.py +153 -0
- md2site/links.py +1403 -0
- md2site/markdown.py +408 -0
- md2site/model.py +80 -0
- md2site/nav.py +286 -0
- md2site/paths.py +130 -0
- md2site/render.py +306 -0
- md2site/scanner.py +273 -0
- md2site/search.py +96 -0
- md2site/server.py +267 -0
- md2site/skill/SKILL.md +50 -0
- md2site/slug.py +40 -0
- md2site/static/css/md2site.css +974 -0
- md2site/static/js/app.js +301 -0
- md2site/static/js/mermaid-init.js +93 -0
- md2site/static/js/search.js +577 -0
- md2site/static/js/theme-init.js +24 -0
- md2site/static/vendor/mermaid.min.js +4329 -0
- md2site/templates/base.html +82 -0
- md2site/templates/landing.html +30 -0
- md2site/templates/page.html +13 -0
- md2site/templates/partials/breadcrumbs.html +15 -0
- md2site/templates/partials/nav.html +37 -0
- md2site/templates/partials/prevnext.html +20 -0
- md2site/templates/partials/toc.html +14 -0
- md2site/titles.py +96 -0
- md2site/watcher.py +447 -0
- md2site/wikilinks.py +314 -0
- md2site_cli-0.2.0.dist-info/METADATA +280 -0
- md2site_cli-0.2.0.dist-info/RECORD +43 -0
- md2site_cli-0.2.0.dist-info/WHEEL +4 -0
- md2site_cli-0.2.0.dist-info/entry_points.txt +3 -0
- md2site_cli-0.2.0.dist-info/licenses/LICENSE +21 -0
- md2site_cli-0.2.0.dist-info/licenses/THIRD_PARTY_LICENSES.md +36 -0
md2site/watcher.py
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
"""Filesystem watcher and incremental rebuild coordinator."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import threading
|
|
6
|
+
import time
|
|
7
|
+
import webbrowser
|
|
8
|
+
from collections.abc import Callable, Iterable
|
|
9
|
+
from pathlib import Path, PurePosixPath
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from markdown_it import MarkdownIt
|
|
13
|
+
from markdown_it.token import Token
|
|
14
|
+
from watchdog.events import FileSystemEvent, FileSystemEventHandler
|
|
15
|
+
from watchdog.observers import Observer
|
|
16
|
+
|
|
17
|
+
from md2site.assets import MANIFEST_FILENAME, write_if_changed
|
|
18
|
+
from md2site.build import BuildResult, run_pipeline
|
|
19
|
+
from md2site.config import Config, ConfigError, load_config
|
|
20
|
+
from md2site.diagnostics import format_diagnostics
|
|
21
|
+
from md2site.frontmatter import split_front_matter
|
|
22
|
+
from md2site.links import resolve_site
|
|
23
|
+
from md2site.markdown import make_engine, parse, render
|
|
24
|
+
from md2site.model import Diagnostic, Page, Site
|
|
25
|
+
from md2site.nav import flatten
|
|
26
|
+
from md2site.render import render_page
|
|
27
|
+
from md2site.search import build_search_index_js
|
|
28
|
+
from md2site.server import first_page_url, start_server, stop_server
|
|
29
|
+
from md2site.titles import page_title
|
|
30
|
+
|
|
31
|
+
_EDITOR_TEMP_SUFFIXES = (".swp", ".swo", ".swx", ".tmp", "~")
|
|
32
|
+
_MD_EXTENSIONS = frozenset({".md", ".markdown"})
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def should_ignore_path(path: Path, config: Config) -> bool:
|
|
36
|
+
"""Return True if a filesystem event path should be ignored by watch mode."""
|
|
37
|
+
name = path.name
|
|
38
|
+
if not name:
|
|
39
|
+
return True
|
|
40
|
+
if name == MANIFEST_FILENAME or name == "4913":
|
|
41
|
+
return True
|
|
42
|
+
if name.endswith(_EDITOR_TEMP_SUFFIXES):
|
|
43
|
+
return True
|
|
44
|
+
if name.startswith(".#") or (name.startswith("#") and name.endswith("#")):
|
|
45
|
+
return True
|
|
46
|
+
|
|
47
|
+
# Ignore anything inside output_dir
|
|
48
|
+
out_resolved = config.output_dir.resolve()
|
|
49
|
+
try:
|
|
50
|
+
resolved = path.resolve()
|
|
51
|
+
except OSError:
|
|
52
|
+
resolved = path
|
|
53
|
+
if resolved == out_resolved or out_resolved in resolved.parents:
|
|
54
|
+
return True
|
|
55
|
+
|
|
56
|
+
# Ignore dot-files / dot-directories under docs_dir or config dir
|
|
57
|
+
docs_resolved = config.docs_dir.resolve()
|
|
58
|
+
try:
|
|
59
|
+
rel_parts = resolved.relative_to(docs_resolved).parts
|
|
60
|
+
if any(part.startswith(".") for part in rel_parts):
|
|
61
|
+
return True
|
|
62
|
+
except ValueError:
|
|
63
|
+
if name.startswith("."):
|
|
64
|
+
return True
|
|
65
|
+
|
|
66
|
+
return False
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class EventDebouncer:
|
|
70
|
+
"""Coalesce bursts of filesystem events over ``delay_s`` seconds."""
|
|
71
|
+
|
|
72
|
+
def __init__(
|
|
73
|
+
self,
|
|
74
|
+
callback: Callable[[set[Path]], None],
|
|
75
|
+
*,
|
|
76
|
+
delay_s: float = 0.15,
|
|
77
|
+
) -> None:
|
|
78
|
+
self._callback = callback
|
|
79
|
+
self._delay_s = delay_s
|
|
80
|
+
self._lock = threading.Lock()
|
|
81
|
+
self._pending: set[Path] = set()
|
|
82
|
+
self._timer: threading.Timer | None = None
|
|
83
|
+
self._stopped = False
|
|
84
|
+
|
|
85
|
+
def push(self, path: Path) -> None:
|
|
86
|
+
with self._lock:
|
|
87
|
+
if self._stopped:
|
|
88
|
+
return
|
|
89
|
+
self._pending.add(path)
|
|
90
|
+
if self._timer is not None:
|
|
91
|
+
self._timer.cancel()
|
|
92
|
+
timer = threading.Timer(self._delay_s, self._on_timer)
|
|
93
|
+
timer.daemon = True
|
|
94
|
+
self._timer = timer
|
|
95
|
+
timer.start()
|
|
96
|
+
|
|
97
|
+
def _on_timer(self) -> None:
|
|
98
|
+
self.flush_now()
|
|
99
|
+
|
|
100
|
+
def flush_now(self) -> set[Path]:
|
|
101
|
+
with self._lock:
|
|
102
|
+
if self._timer is not None:
|
|
103
|
+
self._timer.cancel()
|
|
104
|
+
self._timer = None
|
|
105
|
+
batch = set(self._pending)
|
|
106
|
+
self._pending.clear()
|
|
107
|
+
if batch and not self._stopped:
|
|
108
|
+
self._callback(batch)
|
|
109
|
+
return batch
|
|
110
|
+
|
|
111
|
+
def stop(self) -> None:
|
|
112
|
+
with self._lock:
|
|
113
|
+
self._stopped = True
|
|
114
|
+
if self._timer is not None:
|
|
115
|
+
self._timer.cancel()
|
|
116
|
+
self._timer = None
|
|
117
|
+
self._pending.clear()
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _extract_outgoing_targets(tokens: Iterable[Token]) -> tuple[str, ...]:
|
|
121
|
+
targets: list[str] = []
|
|
122
|
+
for token in tokens:
|
|
123
|
+
if token.type == "inline" and token.children:
|
|
124
|
+
for child in token.children:
|
|
125
|
+
if child.type == "link_open":
|
|
126
|
+
wl = child.meta.get("wikilink")
|
|
127
|
+
if wl is not None:
|
|
128
|
+
targets.append(f"wl:{wl.get('raw', '')}")
|
|
129
|
+
else:
|
|
130
|
+
targets.append(f"href:{child.attrGet('href') or ''}")
|
|
131
|
+
elif child.type == "image":
|
|
132
|
+
wl = child.meta.get("wikilink")
|
|
133
|
+
if wl is not None:
|
|
134
|
+
targets.append(f"wlembed:{wl.get('raw', '')}")
|
|
135
|
+
else:
|
|
136
|
+
targets.append(f"src:{child.attrGet('src') or ''}")
|
|
137
|
+
return tuple(targets)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _page_signature(page: Page, outgoing: tuple[str, ...]) -> tuple[Any, ...]:
|
|
141
|
+
return (
|
|
142
|
+
page.title,
|
|
143
|
+
page.order,
|
|
144
|
+
page.hidden,
|
|
145
|
+
page.draft,
|
|
146
|
+
page.aliases,
|
|
147
|
+
page.meta.get("search"),
|
|
148
|
+
bool(page.meta.get("_has_mermaid")),
|
|
149
|
+
tuple(page.headings),
|
|
150
|
+
outgoing,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class WatchSession:
|
|
155
|
+
"""Coordinates initial builds, incremental fast-path updates, and full rebuilds."""
|
|
156
|
+
|
|
157
|
+
def __init__(
|
|
158
|
+
self,
|
|
159
|
+
config: Config,
|
|
160
|
+
*,
|
|
161
|
+
path_arg: Path | str = ".",
|
|
162
|
+
config_file: Path | str | None = None,
|
|
163
|
+
drafts: bool = False,
|
|
164
|
+
) -> None:
|
|
165
|
+
self.config = config
|
|
166
|
+
self.path_arg = path_arg
|
|
167
|
+
self.config_file = Path(config_file).resolve() if config_file else config.config_path
|
|
168
|
+
self.drafts = drafts
|
|
169
|
+
self.last_result: BuildResult | None = None
|
|
170
|
+
self._engine: MarkdownIt = make_engine(config)
|
|
171
|
+
self._outgoing_by_rel: dict[PurePosixPath, tuple[str, ...]] = {}
|
|
172
|
+
|
|
173
|
+
def initial_build(self) -> BuildResult:
|
|
174
|
+
result = run_pipeline(self.config, drafts=self.drafts, write=True)
|
|
175
|
+
self.last_result = result
|
|
176
|
+
self._refresh_outgoing_cache(result.site)
|
|
177
|
+
return result
|
|
178
|
+
|
|
179
|
+
def _refresh_outgoing_cache(self, site: Site) -> None:
|
|
180
|
+
self._outgoing_by_rel = {p.rel: _extract_outgoing_targets(p.tokens) for p in site.pages}
|
|
181
|
+
|
|
182
|
+
def handle_changes(
|
|
183
|
+
self, changed_paths: set[Path]
|
|
184
|
+
) -> tuple[BuildResult | None, bool, str | None]:
|
|
185
|
+
"""Process a coalesced batch of changed paths.
|
|
186
|
+
|
|
187
|
+
Returns ``(result, was_incremental, error_message)``. On mid-edit
|
|
188
|
+
config/syntax errors, keeps the last good build intact and returns an
|
|
189
|
+
error string instead of raising.
|
|
190
|
+
"""
|
|
191
|
+
t0 = time.perf_counter()
|
|
192
|
+
resolved_changes = {p.resolve() for p in changed_paths}
|
|
193
|
+
|
|
194
|
+
# Config changed -> reload and full rebuild
|
|
195
|
+
if self.config_file is not None and self.config_file.resolve() in resolved_changes:
|
|
196
|
+
try:
|
|
197
|
+
new_cfg = load_config(self.path_arg, config_file=self.config_file)
|
|
198
|
+
# Preserve CLI overrides like --out or --mode if they differed from loaded file
|
|
199
|
+
if self.config.output_dir != new_cfg.output_dir and self.config_file is None:
|
|
200
|
+
pass
|
|
201
|
+
self.config = new_cfg
|
|
202
|
+
self._engine = make_engine(self.config)
|
|
203
|
+
except (ConfigError, OSError) as exc:
|
|
204
|
+
return None, False, f"Config error (serving previous build): {exc}"
|
|
205
|
+
|
|
206
|
+
if self.last_result is None:
|
|
207
|
+
result = self.initial_build()
|
|
208
|
+
return result, False, None
|
|
209
|
+
|
|
210
|
+
# Attempt incremental fast path when exactly 1 existing Markdown page changed
|
|
211
|
+
if len(resolved_changes) == 1:
|
|
212
|
+
changed_file = next(iter(resolved_changes))
|
|
213
|
+
if changed_file.suffix.lower() in _MD_EXTENSIONS and changed_file.is_file():
|
|
214
|
+
target_page = next(
|
|
215
|
+
(p for p in self.last_result.site.pages if p.src == changed_file),
|
|
216
|
+
None,
|
|
217
|
+
)
|
|
218
|
+
if target_page is not None:
|
|
219
|
+
inc_result = self._try_incremental(target_page, t0)
|
|
220
|
+
if inc_result is not None:
|
|
221
|
+
return inc_result, True, None
|
|
222
|
+
|
|
223
|
+
try:
|
|
224
|
+
result = run_pipeline(self.config, drafts=self.drafts, write=True)
|
|
225
|
+
self.last_result = result
|
|
226
|
+
self._refresh_outgoing_cache(result.site)
|
|
227
|
+
return result, False, None
|
|
228
|
+
except (ConfigError, OSError) as exc:
|
|
229
|
+
return None, False, f"Build error (serving previous build): {exc}"
|
|
230
|
+
|
|
231
|
+
def _try_incremental(self, target_page: Page, t0: float) -> BuildResult | None:
|
|
232
|
+
"""Re-render a single page + search index if structure/links are unchanged."""
|
|
233
|
+
assert self.last_result is not None
|
|
234
|
+
try:
|
|
235
|
+
raw_text = target_page.src.read_bytes().decode("utf-8-sig", errors="replace")
|
|
236
|
+
except OSError:
|
|
237
|
+
return None
|
|
238
|
+
|
|
239
|
+
meta, body, _offset, fm_err = split_front_matter(raw_text)
|
|
240
|
+
if fm_err is not None:
|
|
241
|
+
return None
|
|
242
|
+
|
|
243
|
+
new_title = page_title(meta, body, target_page.rel.name)
|
|
244
|
+
raw_order = meta.get("order")
|
|
245
|
+
new_order = (
|
|
246
|
+
float(raw_order)
|
|
247
|
+
if isinstance(raw_order, (int, float)) and not isinstance(raw_order, bool)
|
|
248
|
+
else None
|
|
249
|
+
)
|
|
250
|
+
new_hidden = bool(meta.get("hidden", False))
|
|
251
|
+
new_draft = bool(meta.get("draft", False))
|
|
252
|
+
raw_aliases = meta.get("aliases")
|
|
253
|
+
new_aliases = (
|
|
254
|
+
tuple(str(x) for x in raw_aliases if x is not None)
|
|
255
|
+
if isinstance(raw_aliases, list)
|
|
256
|
+
else ((raw_aliases,) if isinstance(raw_aliases, str) and raw_aliases else ())
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
probe = Page(
|
|
260
|
+
src=target_page.src,
|
|
261
|
+
rel=target_page.rel,
|
|
262
|
+
out_rel=target_page.out_rel,
|
|
263
|
+
title=new_title,
|
|
264
|
+
order=new_order,
|
|
265
|
+
hidden=new_hidden,
|
|
266
|
+
draft=new_draft,
|
|
267
|
+
aliases=new_aliases,
|
|
268
|
+
tags=target_page.tags,
|
|
269
|
+
meta=dict(meta),
|
|
270
|
+
)
|
|
271
|
+
parse(probe, raw_text, self._engine)
|
|
272
|
+
new_outgoing = _extract_outgoing_targets(probe.tokens)
|
|
273
|
+
|
|
274
|
+
old_outgoing = self._outgoing_by_rel.get(target_page.rel, ())
|
|
275
|
+
if _page_signature(probe, new_outgoing) != _page_signature(target_page, old_outgoing):
|
|
276
|
+
return None
|
|
277
|
+
|
|
278
|
+
# Structural metadata, headings, and outgoing links match -> incremental update
|
|
279
|
+
target_page.tokens = probe.tokens
|
|
280
|
+
target_page.text = probe.text
|
|
281
|
+
target_page.meta = probe.meta
|
|
282
|
+
|
|
283
|
+
site = self.last_result.site
|
|
284
|
+
target_file = target_page.rel.as_posix()
|
|
285
|
+
preserved_diags = [
|
|
286
|
+
d for d in site.diagnostics if d.file != target_file or d.code == "MD2S008"
|
|
287
|
+
]
|
|
288
|
+
single_site = Site(
|
|
289
|
+
config=site.config,
|
|
290
|
+
pages=site.pages,
|
|
291
|
+
nav=site.nav,
|
|
292
|
+
by_rel=dict(site.by_rel),
|
|
293
|
+
assets=list(site.assets),
|
|
294
|
+
diagnostics=preserved_diags,
|
|
295
|
+
)
|
|
296
|
+
resolve_site(single_site)
|
|
297
|
+
|
|
298
|
+
written: list[Path] = []
|
|
299
|
+
skipped = 0
|
|
300
|
+
body_html = render(target_page, self._engine)
|
|
301
|
+
full_html = render_page(site, target_page, body_html)
|
|
302
|
+
dest_html = self.config.output_dir / target_page.out_rel
|
|
303
|
+
if write_if_changed(dest_html, full_html.encode("utf-8")):
|
|
304
|
+
written.append(dest_html)
|
|
305
|
+
else:
|
|
306
|
+
skipped += 1
|
|
307
|
+
|
|
308
|
+
if self.config.search.enabled:
|
|
309
|
+
search_js = build_search_index_js(site)
|
|
310
|
+
dest_idx = self.config.output_dir / "assets" / "search-index.js"
|
|
311
|
+
if write_if_changed(dest_idx, search_js.encode("utf-8")):
|
|
312
|
+
written.append(dest_idx)
|
|
313
|
+
else:
|
|
314
|
+
skipped += 1
|
|
315
|
+
|
|
316
|
+
site.diagnostics = single_site.diagnostics
|
|
317
|
+
duration_ms = int((time.perf_counter() - t0) * 1000)
|
|
318
|
+
result = BuildResult(
|
|
319
|
+
site=site,
|
|
320
|
+
diagnostics=list(site.diagnostics),
|
|
321
|
+
written_files=written,
|
|
322
|
+
skipped_count=skipped,
|
|
323
|
+
removed_files=[],
|
|
324
|
+
duration_ms=duration_ms,
|
|
325
|
+
)
|
|
326
|
+
self.last_result = result
|
|
327
|
+
return result
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class _WatchdogHandler(FileSystemEventHandler):
|
|
331
|
+
"""Forwards non-ignored watchdog events into ``EventDebouncer``."""
|
|
332
|
+
|
|
333
|
+
def __init__(self, config: Config, debouncer: EventDebouncer) -> None:
|
|
334
|
+
self._config = config
|
|
335
|
+
self._debouncer = debouncer
|
|
336
|
+
|
|
337
|
+
def _maybe_push(self, raw_path: str | bytes) -> None:
|
|
338
|
+
path_str = (
|
|
339
|
+
raw_path.decode("utf-8", errors="replace") if isinstance(raw_path, bytes) else raw_path
|
|
340
|
+
)
|
|
341
|
+
path = Path(path_str)
|
|
342
|
+
if not should_ignore_path(path, self._config):
|
|
343
|
+
self._debouncer.push(path)
|
|
344
|
+
|
|
345
|
+
def on_modified(self, event: FileSystemEvent) -> None:
|
|
346
|
+
if not event.is_directory:
|
|
347
|
+
self._maybe_push(event.src_path)
|
|
348
|
+
|
|
349
|
+
def on_created(self, event: FileSystemEvent) -> None:
|
|
350
|
+
if not event.is_directory:
|
|
351
|
+
self._maybe_push(event.src_path)
|
|
352
|
+
|
|
353
|
+
def on_deleted(self, event: FileSystemEvent) -> None:
|
|
354
|
+
if not event.is_directory:
|
|
355
|
+
self._maybe_push(event.src_path)
|
|
356
|
+
|
|
357
|
+
def on_moved(self, event: FileSystemEvent) -> None:
|
|
358
|
+
if not event.is_directory:
|
|
359
|
+
self._maybe_push(event.src_path)
|
|
360
|
+
dest = getattr(event, "dest_path", None)
|
|
361
|
+
if dest:
|
|
362
|
+
self._maybe_push(dest)
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def watch_and_serve(
|
|
366
|
+
config: Config,
|
|
367
|
+
*,
|
|
368
|
+
path_arg: Path | str = ".",
|
|
369
|
+
config_file: Path | str | None = None,
|
|
370
|
+
host: str = "127.0.0.1",
|
|
371
|
+
port: int = 8000,
|
|
372
|
+
open_browser: bool = False,
|
|
373
|
+
emit_msg: Callable[[str], None] | None = None,
|
|
374
|
+
) -> int:
|
|
375
|
+
"""Build, serve with SSE live reload, and watch for changes until Ctrl-C."""
|
|
376
|
+
|
|
377
|
+
def _log(msg: str) -> None:
|
|
378
|
+
if emit_msg is not None:
|
|
379
|
+
emit_msg(msg)
|
|
380
|
+
|
|
381
|
+
session = WatchSession(config, path_arg=path_arg, config_file=config_file)
|
|
382
|
+
initial = session.initial_build()
|
|
383
|
+
_print_watch_diagnostics(
|
|
384
|
+
_log, initial.diagnostics, initial.duration_ms, len(initial.site.pages)
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
server, thread = start_server(config.output_dir, host=host, port=port)
|
|
388
|
+
flat = flatten(initial.site.nav)
|
|
389
|
+
first_rel = flat[0].out_rel if flat else PurePosixPath("index.html")
|
|
390
|
+
url = first_page_url(server, first_rel)
|
|
391
|
+
_log(f"Serving {config.output_dir} at {url} (Ctrl-C to stop)")
|
|
392
|
+
|
|
393
|
+
if open_browser:
|
|
394
|
+
webbrowser.open(url)
|
|
395
|
+
|
|
396
|
+
def _on_debounced(paths: set[Path]) -> None:
|
|
397
|
+
result, incremental, err = session.handle_changes(paths)
|
|
398
|
+
if err is not None:
|
|
399
|
+
_log(err)
|
|
400
|
+
return
|
|
401
|
+
if result is not None:
|
|
402
|
+
mode = "incremental" if incremental else "full"
|
|
403
|
+
_print_watch_diagnostics(
|
|
404
|
+
_log,
|
|
405
|
+
result.diagnostics,
|
|
406
|
+
result.duration_ms,
|
|
407
|
+
len(result.site.pages),
|
|
408
|
+
mode=mode,
|
|
409
|
+
)
|
|
410
|
+
server.broadcaster.broadcast("reload")
|
|
411
|
+
|
|
412
|
+
debouncer = EventDebouncer(_on_debounced, delay_s=0.15)
|
|
413
|
+
handler = _WatchdogHandler(config, debouncer)
|
|
414
|
+
observer = Observer()
|
|
415
|
+
observer.schedule(handler, str(config.docs_dir.resolve()), recursive=True)
|
|
416
|
+
if config.config_path is not None:
|
|
417
|
+
cfg_dir = config.config_path.resolve().parent
|
|
418
|
+
docs_res = config.docs_dir.resolve()
|
|
419
|
+
if cfg_dir != docs_res and docs_res not in cfg_dir.parents:
|
|
420
|
+
observer.schedule(handler, str(cfg_dir), recursive=False)
|
|
421
|
+
observer.start()
|
|
422
|
+
|
|
423
|
+
try:
|
|
424
|
+
while True:
|
|
425
|
+
time.sleep(0.5)
|
|
426
|
+
except KeyboardInterrupt:
|
|
427
|
+
_log("Stopping watch server...")
|
|
428
|
+
finally:
|
|
429
|
+
observer.stop()
|
|
430
|
+
observer.join(timeout=2.0)
|
|
431
|
+
debouncer.stop()
|
|
432
|
+
stop_server(server, thread)
|
|
433
|
+
|
|
434
|
+
return 0
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def _print_watch_diagnostics(
|
|
438
|
+
log: Callable[[str], None],
|
|
439
|
+
diagnostics: list[Diagnostic],
|
|
440
|
+
duration_ms: int,
|
|
441
|
+
pages_count: int,
|
|
442
|
+
*,
|
|
443
|
+
mode: str = "initial",
|
|
444
|
+
) -> None:
|
|
445
|
+
if diagnostics:
|
|
446
|
+
log(format_diagnostics(diagnostics))
|
|
447
|
+
log(f"[{mode}] {pages_count} pages built in {duration_ms} ms ({len(diagnostics)} diagnostics)")
|