Files
cibuildwheel/bin/update_how_it_works_image.py
T

51 lines
1.2 KiB
Python
Raw Normal View History

2022-09-18 16:12:57 +01:00
#!/usr/bin/env python3
import subprocess
import sys
from pathlib import Path
try:
from html2image import Html2Image # type: ignore[import-not-found]
2022-09-18 16:12:57 +01:00
except ImportError:
sys.exit(
"""
html2image not found. Ensure you have Chrome (on Mac/Windows) or
Chromium (on Linux) installed, and then do:
pip install html2image
"""
)
2024-10-22 10:16:59 -04:00
def main() -> None:
subprocess.run(["mkdocs", "build"], check=True)
2022-09-18 16:12:57 +01:00
hti = Html2Image(custom_flags=["--force-device-scale-factor=2"])
html_str = Path("docs/diagram.md").read_text()
css_tags = f"""
<style>{Path("site/css/theme.css").read_text()}</style>
<style>{Path("site/css/theme_extra.css").read_text()}</style>
<style>{Path("site/extra.css").read_text()}</style>
<style>
body {{
background: white;
}}
</style>
"""
html_str = css_tags + html_str
[screenshot, *_] = hti.screenshot(
html_str=html_str,
size=(830, 405),
)
dest_path = Path("docs/data/how-it-works.png")
2025-02-26 10:56:35 -05:00
dest_path.unlink(missing_ok=True)
2022-09-18 16:12:57 +01:00
Path(screenshot).rename(dest_path)
if __name__ == "__main__":
main()