forked from astral-sh/uv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform_readme.py
64 lines (52 loc) · 2.06 KB
/
transform_readme.py
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
"""Transform the README.md to support a specific deployment target.
By default, we assume that our README.md will be rendered on GitHub. However, different
targets have different strategies for rendering light- and dark-mode images. This script
adjusts the images in the README.md to support the given target.
"""
from __future__ import annotations
import argparse
from pathlib import Path
URL = "https://github.com/astral-sh/uv/assets/1309177/{}"
URL_LIGHT = URL.format("629e59c0-9c6e-4013-9ad4-adb2bcf5080d")
URL_DARK = URL.format("03aa9163-1c79-4a87-a31d-7a9311ed9310")
# https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#specifying-the-theme-an-image-is-shown-to
GITHUB = f"""
<p align="center">
<picture align="center">
<source media="(prefers-color-scheme: dark)" srcset="{URL_DARK}">
<source media="(prefers-color-scheme: light)" srcset="{URL_LIGHT}">
<img alt="Shows a bar chart with benchmark results." src="{URL_LIGHT}">
</picture>
</p>
"""
# https://github.com/pypi/warehouse/issues/11251
PYPI = f"""
<p align="center">
<img alt="Shows a bar chart with benchmark results." src="{URL_LIGHT}">
</p>
"""
def main(target: str) -> None:
"""Modify the README.md to support the given target."""
with Path("README.md").open(encoding="utf8") as fp:
content = fp.read()
if GITHUB not in content:
msg = "README.md is not in the expected format."
raise ValueError(msg)
if target == "pypi":
with Path("README.md").open("w", encoding="utf8") as fp:
fp.write(content.replace(GITHUB, PYPI))
else:
msg = f"Unknown target: {target}"
raise ValueError(msg)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Modify the README.md to support a specific deployment target.",
)
parser.add_argument(
"--target",
type=str,
required=True,
choices=("pypi", "mkdocs"),
)
args = parser.parse_args()
main(target=args.target)