forked from NVIDIA/NeMo-Relay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_rust_library_reference.py
More file actions
673 lines (558 loc) · 22.8 KB
/
Copy pathgenerate_rust_library_reference.py
File metadata and controls
673 lines (558 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Generate Fern-compatible Rust library reference pages from rustdoc HTML."""
from __future__ import annotations
import argparse
import json
import os
import posixpath
import re
import subprocess
from dataclasses import dataclass
from html import escape as html_escape
from pathlib import Path
from urllib.parse import urldefrag
from bs4 import BeautifulSoup
from bs4.element import NavigableString, PageElement, Tag
from reference_common import escape_mdx_text, frontmatter, reset_output_dir
CRATES = (
("nemo-relay", "nemo_relay", "Core Rust runtime APIs for NeMo Relay."),
("nemo-relay-adaptive", "nemo_relay_adaptive", "Adaptive runtime primitives and plugin components."),
("nemo-relay-ffi", "nemo_relay_ffi", "C-compatible FFI surface for NeMo Relay."),
)
BASE_URL = "/reference/api/rust-library-reference"
GENERATED_BY = "Generated from `cargo doc --no-deps -p nemo-relay -p nemo-relay-adaptive -p nemo-relay-ffi`."
TRANSLATION_TABLE = str.maketrans(
{
"\xa0": " ",
"\u200b": "",
"\u2010": "-",
"\u2011": "-",
"\u2012": "-",
"\u2013": "-",
"\u2014": "-",
"\u2018": "'",
"\u2019": "'",
"\u201c": '"',
"\u201d": '"',
"\u2026": "...",
"\u2192": "->",
"\u24d8": "",
"\u26a0": "",
"\u2139": "",
"\ufe0f": "",
"\u00a7": "",
"\U0001f52c": "",
}
)
FERN_COMPONENT_TAGS = (
"Tabs",
"Tab",
"CardGroup",
"Cards",
"Card",
"Accordion",
"Note",
"Warning",
"Tip",
"Info",
"Error",
)
FERN_COMPONENT_TAG_PATTERN = re.compile(
rf"<(/?)({'|'.join(re.escape(tag) for tag in FERN_COMPONENT_TAGS)})(?=[\s>/]|$)"
)
@dataclass(frozen=True, slots=True)
class Page:
html_path: Path
output_path: Path
url: str
crate_name: str
crate_dir_name: str
def _ascii(value: str) -> str:
value = value.translate(TRANSLATION_TABLE)
return value.encode("ascii", "xmlcharrefreplace").decode("ascii")
def _escape_text(value: str) -> str:
return escape_mdx_text(value, normalize=_ascii)
def _clean_text(value: str) -> str:
return re.sub(r"[ \t\r\f\v]+", " ", _ascii(value)).replace("\n ", "\n").strip()
def _clean_code(value: str) -> str:
lines = _ascii(value).splitlines()
while lines and not lines[0].strip():
lines.pop(0)
while lines and not lines[-1].strip():
lines.pop()
return "\n".join(line.rstrip() for line in lines)
def _mdx_safe_code(value: str) -> str:
"""Avoid accidental Fern component tags inside generated Rust signatures."""
return FERN_COMPONENT_TAG_PATTERN.sub(
lambda match: f"< {'/' if match.group(1) else ''}{match.group(2)}",
value,
)
def _inline_code(value: str) -> str:
code = _mdx_safe_code(value).replace("`", "\\`")
return f"`{code}`"
def _rust_fence(value: str) -> str:
code = _mdx_safe_code(value)
return f"```rust\n{code}\n```\n\n" if code else ""
def _html_text(value: str) -> str:
return html_escape(_ascii(value), quote=False).replace("{", "{").replace("}", "}")
def _html_attr(value: str) -> str:
return html_escape(_ascii(value), quote=True)
def _slug_part(value: str) -> str:
value = value.replace("!", "-bang")
value = re.sub(r"[^A-Za-z0-9_-]+", "-", value)
value = value.replace("_", "-").strip("-").lower()
return value or "item"
def _rustdoc_path_part(value: str) -> str:
value = value.replace("!", "-bang")
value = re.sub(r"[^A-Za-z0-9_-]+", "-", value)
return value.strip("-").lower() or "item"
def _crate_slug(crate_name: str) -> str:
return crate_name.replace("_", "-")
def _run_cargo_doc(repo_root: Path) -> None:
env = os.environ.copy()
existing = env.get("RUSTDOCFLAGS", "")
cap_lints = "--cap-lints allow"
env["RUSTDOCFLAGS"] = f"{existing} {cap_lints}".strip()
subprocess.run(
[
"cargo",
"doc",
"--no-deps",
"-p",
"nemo-relay",
"-p",
"nemo-relay-adaptive",
"-p",
"nemo-relay-ffi",
],
cwd=repo_root,
env=env,
check=True,
)
def _output_relative(crate_name: str, crate_dir: Path, html_path: Path) -> Path:
crate_slug = _crate_slug(crate_name)
rel = html_path.relative_to(crate_dir)
parent_parts = [_slug_part(part) for part in rel.parent.parts]
if rel.name == "index.html":
return Path(crate_slug, *parent_parts, "index.mdx")
stem = rel.name.removesuffix(".html")
return Path(crate_slug, *parent_parts, f"{_slug_part(stem)}.mdx")
def _url_relative(crate_name: str, crate_dir: Path, html_path: Path) -> Path:
crate_slug = _crate_slug(crate_name)
rel = html_path.relative_to(crate_dir)
parent_parts = [_rustdoc_path_part(part) for part in rel.parent.parts]
if rel.name == "index.html":
return Path(crate_slug, *parent_parts, "index.mdx")
stem = rel.name.removesuffix(".html")
return Path(crate_slug, *parent_parts, f"{_slug_part(stem)}.mdx")
def _page_url(output_rel: Path) -> str:
without_suffix = output_rel.with_suffix("")
parts = list(without_suffix.parts)
if parts[-1] == "index":
parts.pop()
return f"{BASE_URL}/{'/'.join(parts)}"
def _needs_explicit_slug(page: Page) -> bool:
"""Fern drops underscores from auto-discovered folder URLs."""
return "_" in page.url
def _discover_pages(doc_root: Path, output_dir: Path) -> dict[Path, Page]:
pages: dict[Path, Page] = {}
for crate_name, crate_dir_name, _description in CRATES:
crate_dir = doc_root / crate_dir_name
if not crate_dir.is_dir():
raise SystemExit(f"rustdoc crate output not found: {crate_dir}")
for html_path in sorted(crate_dir.rglob("*.html")):
if html_path.name == "all.html":
continue
if 'id="main-content"' not in html_path.read_text(encoding="utf-8", errors="ignore"):
continue
output_rel = _output_relative(crate_name, crate_dir, html_path)
url_rel = _url_relative(crate_name, crate_dir, html_path)
pages[html_path.resolve()] = Page(
html_path=html_path.resolve(),
output_path=output_dir / output_rel,
url=_page_url(url_rel),
crate_name=crate_name,
crate_dir_name=crate_dir_name,
)
return pages
def _resolve_href(page: Page, href: str, pages_by_html: dict[Path, Page]) -> str | None:
if not href or href.startswith("#"):
return None
if href.startswith(("http://", "https://")):
return href
href_no_fragment, _fragment = urldefrag(href)
if href_no_fragment.startswith("../src/") or "/src/" in href_no_fragment:
return None
target = (page.html_path.parent / href_no_fragment).resolve()
target_page = pages_by_html.get(target)
if target_page is None:
return None
return target_page.url
def _tag_classes(node: Tag) -> set[str]:
classes = node.get("class")
if classes is None:
return set()
if isinstance(classes, str):
return set(classes.split())
return {str(class_name) for class_name in classes}
def _tag_href(node: Tag) -> str:
href = node.get("href")
return href if isinstance(href, str) else ""
def _inline_markdown(node: PageElement, page: Page, pages_by_html: dict[Path, Page]) -> str:
if isinstance(node, NavigableString):
return _escape_text(str(node))
if not isinstance(node, Tag):
return ""
classes = _tag_classes(node)
if classes & {"anchor", "doc-anchor", "src"} or node.name in {"script", "style", "wbr", "button"}:
return ""
if node.name == "br":
return "\n"
if node.name == "code":
return _inline_code(_clean_text(node.get_text("", strip=False)))
if node.name == "a":
label = "".join(_inline_markdown(child, page, pages_by_html) for child in node.children).strip()
if not label or label == "Source":
return label
target = _resolve_href(page, _tag_href(node), pages_by_html)
if target is None:
return label
return f"[{label}]({target})"
if node.name == "strong":
content = "".join(_inline_markdown(child, page, pages_by_html) for child in node.children).strip()
return f"**{content}**" if content else ""
if node.name == "em":
content = "".join(_inline_markdown(child, page, pages_by_html) for child in node.children).strip()
return f"*{content}*" if content else ""
return "".join(_inline_markdown(child, page, pages_by_html) for child in node.children)
def _plain_code(node: Tag) -> str:
return _clean_code(node.get_text("", strip=False))
def _heading_text(node: Tag) -> str:
for removable in node.select(".anchor, .doc-anchor, .src, button"):
removable.decompose()
text = _clean_text(node.get_text(" ", strip=True))
return re.sub(r"_\s+", "_", text)
def _signature_link_target(page: Page, href: str, pages_by_html: dict[Path, Page]) -> str | None:
if not href or href.startswith("#"):
return None
target = _resolve_href(page, href, pages_by_html)
if target is None or not target.startswith("/"):
return target
return posixpath.relpath(target, start=posixpath.dirname(page.url))
def _linked_signature_html(node: PageElement, page: Page, pages_by_html: dict[Path, Page]) -> str:
if isinstance(node, NavigableString):
return _html_text(str(node))
if not isinstance(node, Tag):
return ""
classes = _tag_classes(node)
if classes & {"anchor", "doc-anchor", "src"} or node.name in {"script", "style", "wbr", "button"}:
return ""
if node.name == "br":
return "\n"
if node.name == "a":
label = "".join(_linked_signature_html(child, page, pages_by_html) for child in node.children)
if not label:
return ""
target = _signature_link_target(page, _tag_href(node), pages_by_html)
if target is None:
return label
return f'<a href="{_html_attr(target)}">{label}</a>'
return "".join(_linked_signature_html(child, page, pages_by_html) for child in node.children)
def _linked_signature_block(node: Tag, page: Page, pages_by_html: dict[Path, Page]) -> str:
signature = _linked_signature_html(node, page, pages_by_html).strip()
while "\n\n" in signature:
signature = signature.replace("\n\n", "\n​\n")
if not signature:
return ""
payload = json.dumps({"__html": signature})
return f'<pre className="rust-signature"><code dangerouslySetInnerHTML={{{payload}}} /></pre>\n\n'
def _code_header_label(node: Tag) -> str:
if node.name in {"h2", "h3"}:
text = re.sub(r"\s+", " ", _plain_code(node)).strip()
return _inline_code(text) if text else ""
for class_name in (
"fn",
"associatedtype",
"constant",
"struct",
"enum",
"trait",
"type",
"macro",
"derive",
"attribute",
):
link = node.find("a", class_=class_name)
if link is None:
continue
text = _clean_text(link.get_text("", strip=True))
if text:
return _inline_code(text)
text = re.sub(r"\s+", " ", _plain_code(node)).strip()
return _inline_code(text) if text else ""
def _code_header_markdown(node: Tag, page: Page, pages_by_html: dict[Path, Page]) -> str:
level = {"h2": "##", "h3": "###", "h4": "####", "h5": "#####"}[node.name]
label = _code_header_label(node)
if not label:
return _linked_signature_block(node, page, pages_by_html)
return f"{level} {label}\n\n{_linked_signature_block(node, page, pages_by_html)}"
def _block_markdown(node: PageElement, page: Page, pages_by_html: dict[Path, Page], depth: int = 0) -> str:
if isinstance(node, NavigableString):
return ""
if not isinstance(node, Tag):
return ""
classes = _tag_classes(node)
if node.name in {"script", "style", "rustdoc-toolbar"} or classes & {"anchor", "doc-anchor", "src"}:
return ""
if node.name == "div" and "main-heading" in classes:
return ""
if node.name == "span" and "item-info" in classes:
return ""
if node.get("id") in {"synthetic-implementations-list", "blanket-implementations-list"}:
return ""
if node.name in {"h2", "h3", "h4", "h5"} and "code-header" in classes:
return _code_header_markdown(node, page, pages_by_html)
if node.name in {"h2", "h3", "h4", "h5"}:
level = {"h2": "##", "h3": "###", "h4": "####", "h5": "#####"}[node.name]
text = _heading_text(node)
if text in {"Auto Trait Implementations", "Blanket Implementations"}:
return ""
return f"{level} {text}\n\n" if text else ""
if node.name == "span" and "section-header" in classes:
text = _plain_code(node)
return f"### {_inline_code(text)}\n\n" if text else ""
if node.name == "p":
text = re.sub(r"\s+", " ", _inline_markdown(node, page, pages_by_html)).strip()
return f"{text}\n\n" if text else ""
if node.name == "pre":
if node.find("a", href=True) is not None:
return _linked_signature_block(node, page, pages_by_html)
return _rust_fence(_plain_code(node))
if node.name == "ul":
lines: list[str] = []
for li in node.find_all("li", recursive=False):
text = re.sub(r"\s+", " ", _inline_markdown(li, page, pages_by_html)).strip()
if text:
lines.append(f"{' ' * depth}- {text}")
return "\n".join(lines) + ("\n\n" if lines else "")
if node.name == "ol":
lines = []
for index, li in enumerate(node.find_all("li", recursive=False), start=1):
text = re.sub(r"\s+", " ", _inline_markdown(li, page, pages_by_html)).strip()
if text:
lines.append(f"{' ' * depth}{index}. {text}")
return "\n".join(lines) + ("\n\n" if lines else "")
if node.name == "dl":
parts: list[str] = []
children = [child for child in node.children if isinstance(child, Tag)]
index = 0
while index < len(children):
if children[index].name != "dt":
index += 1
continue
term = re.sub(r"\s+", " ", _inline_markdown(children[index], page, pages_by_html)).strip()
description = ""
if index + 1 < len(children) and children[index + 1].name == "dd":
description = re.sub(
r"\s+",
" ",
_inline_markdown(children[index + 1], page, pages_by_html),
).strip()
index += 1
if term:
line = f"- {term}"
if description:
line += f": {description}"
parts.append(line)
index += 1
return "\n".join(parts) + ("\n\n" if parts else "")
if node.name == "table":
rows: list[str] = []
for row in node.find_all("tr"):
cells = [
re.sub(r"\s+", " ", _inline_markdown(cell, page, pages_by_html)).strip()
for cell in row.find_all(["th", "td"], recursive=False)
]
if cells:
rows.append("- " + " | ".join(cell for cell in cells if cell))
return "\n".join(rows) + ("\n\n" if rows else "")
if node.name == "details":
pieces: list[str] = []
summary = node.find("summary", recursive=False)
if isinstance(summary, Tag) and "hideme" not in _tag_classes(summary):
pieces.append(_block_markdown(summary, page, pages_by_html, depth))
for child in node.children:
if child is summary:
continue
pieces.append(_block_markdown(child, page, pages_by_html, depth))
return "".join(pieces)
pieces = [_block_markdown(child, page, pages_by_html, depth) for child in node.children]
return "".join(pieces)
def _remove_noisy_sections(content: Tag) -> None:
for selector in [
"script",
"style",
"rustdoc-toolbar",
".src",
"button",
".item-info",
"#notable-traits-data",
]:
for element in content.select(selector):
element.decompose()
for section_id in ("synthetic-implementations", "blanket-implementations"):
heading = content.find(id=section_id)
if heading is None:
continue
for sibling in list(heading.find_next_siblings()):
if isinstance(sibling, Tag) and sibling.name == "h2":
break
sibling.decompose()
heading.decompose()
def _page_title(soup: BeautifulSoup, page: Page) -> str:
h1 = soup.select_one("#main-content .main-heading h1")
if h1 is not None:
title = _heading_text(h1)
title = re.sub(
r"^(Crate|Module|Function|Struct|Enum|Trait|Type Alias|Constant|Macro)(?=\S)",
r"\1 ",
title,
)
title = re.sub(r"\s+", " ", title)
if title.startswith("Crate "):
return page.crate_name
return title
return page.crate_name
def _remove_duplicate_top_level_sections(markdown: str) -> str:
lines = markdown.splitlines()
seen: set[str] = set()
kept: list[str] = []
index = 0
while index < len(lines):
line = lines[index]
if line.startswith("## ") and not line.startswith("### "):
if line in seen:
index += 1
while index < len(lines) and not (
lines[index].startswith("## ") and not lines[index].startswith("### ")
):
index += 1
continue
seen.add(line)
kept.append(line)
index += 1
return "\n".join(kept).strip()
def _sidebar_title(soup: BeautifulSoup, page: Page) -> str:
topbar = soup.select_one("rustdoc-topbar h2")
if topbar is not None:
text = _clean_text(topbar.get_text("", strip=True))
if text:
if text.startswith("Crate "):
return page.crate_name
if text.startswith("Module "):
return text.removeprefix("Module ")
return text
if page.output_path.name == "index.mdx":
return page.output_path.parent.name
return page.output_path.stem
def _description(soup: BeautifulSoup) -> str:
meta = soup.find("meta", attrs={"name": "description"})
if isinstance(meta, Tag):
value = meta.get("content", "")
if isinstance(value, str):
return _clean_text(value)
first_paragraph = soup.select_one("#main-content .top-doc .docblock p")
if first_paragraph is not None:
return _clean_text(first_paragraph.get_text(" ", strip=True))
return ""
def _render_page(page: Page, pages_by_html: dict[Path, Page], position: int) -> str:
soup = BeautifulSoup(page.html_path.read_text(encoding="utf-8"), "html.parser")
content = soup.select_one("#main-content")
if content is None:
raise SystemExit(f"rustdoc main content not found: {page.html_path}")
_remove_noisy_sections(content)
body = _remove_duplicate_top_level_sections(_block_markdown(content, page, pages_by_html).strip())
description = _description(soup)
lines = [
frontmatter(
_page_title(soup, page),
description,
position,
sidebar_title=_sidebar_title(soup, page),
slug=page.url if _needs_explicit_slug(page) else None,
normalize=_ascii,
),
]
lines.append(f"{GENERATED_BY}\n\n")
if body:
lines.append(body + "\n")
return "".join(lines)
def _item_order(index_html: Path, pages_by_html: dict[Path, Page]) -> dict[Path, int]:
soup = BeautifulSoup(index_html.read_text(encoding="utf-8"), "html.parser")
positions: dict[Path, int] = {}
position = 1
for link in soup.select("#main-content dl.item-table dt a[href]"):
href = link.get("href", "")
if not isinstance(href, str):
continue
target_path = (index_html.resolve().parent / urldefrag(href)[0]).resolve()
if target_path not in pages_by_html:
continue
positions.setdefault(target_path, position)
position += 1
return positions
def _positions(pages_by_html: dict[Path, Page], doc_root: Path) -> dict[Path, int]:
positions: dict[Path, int] = {}
for position, (_crate_name, crate_dir_name, _description) in enumerate(CRATES, start=1):
crate_index = (doc_root / crate_dir_name / "index.html").resolve()
positions[crate_index] = position
for html_path in pages_by_html:
if html_path.name != "index.html":
continue
for target, position in _item_order(html_path, pages_by_html).items():
positions[target] = position
return positions
def _write_index(output_dir: Path) -> None:
lines = [
frontmatter(
"Rust Library Reference",
"Generated Rust API reference for NeMo Relay crates.",
3,
normalize=_ascii,
),
f"{GENERATED_BY}\n\n",
"## Crates\n\n",
]
for crate_name, _crate_dir_name, description in CRATES:
lines.append(f"- [{crate_name}]({BASE_URL}/{_crate_slug(crate_name)}): {_escape_text(description)}\n")
(output_dir / "index.mdx").write_text("".join(lines), encoding="utf-8")
def generate(repo_root: Path, doc_root: Path, output_dir: Path, *, run_cargo_doc: bool) -> int:
if run_cargo_doc:
_run_cargo_doc(repo_root)
pages_by_html = _discover_pages(doc_root, output_dir)
positions = _positions(pages_by_html, doc_root)
reset_output_dir(output_dir)
_write_index(output_dir)
for index, page in enumerate(sorted(pages_by_html.values(), key=lambda page: page.output_path.as_posix()), start=1):
page.output_path.parent.mkdir(parents=True, exist_ok=True)
position = positions.get(page.html_path, index)
page.output_path.write_text(_render_page(page, pages_by_html, position), encoding="utf-8")
return len(pages_by_html)
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--doc-root", type=Path, default=Path("target/doc"))
parser.add_argument(
"--output-dir",
type=Path,
default=Path("docs/reference/api/rust-library-reference"),
)
parser.add_argument("--skip-cargo-doc", action="store_true")
args = parser.parse_args()
repo_root = Path.cwd()
doc_root = args.doc_root.resolve()
output_dir = args.output_dir.resolve()
count = generate(repo_root, doc_root, output_dir, run_cargo_doc=not args.skip_cargo_doc)
print(f"Generated Rust library reference for {count} rustdoc page(s) in {output_dir}")
if __name__ == "__main__":
main()