refactor: print sizes with one function

core.sizes.size_text replaces readme format_size, release record
size_text, render fmt_size, the large-files notes _mib and the handheld
_size. It prints one decimal in the largest unit reached, as the site
and the installer already did.

The README download table, the release notes and the large-files page
now say 29.2 MB where they said 29 MB, a handheld archive says 85.3 KB
where it said 85 KB, and a large-files asset under 1 MB is given in KB.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 20:03:26 +01:00
1 parent 3a76cf48ba
commit ab0805e6cb
19 files changed
+60 -71

No files matched your search

+3 -2
View File
@@ -797,13 +797,14 @@ class PublishedNumbersShareOneFormat(unittest.TestCase):
the site home as 15.6 GB, and the emulators page `10095 files`."""
def test_generators_format_counts_and_sizes_alike(self):
from core.sizes import size_text
from sitegen import readme as sitegen_readme
readme_source = inspect.getsource(sitegen_readme.generate_readme)
self.assertNotIn("size_mb", readme_source)
self.assertIn("format_size(size)", readme_source)
self.assertIn("size_text(size)", readme_source)
self.assertIn("{total_files:,}", script_source("generate_site.py"))
self.assertEqual(sitegen_readme.format_size(16011 * 1024 * 1024), "15.6 GB")
self.assertEqual(size_text(16011 * 1024 * 1024), "15.6 GB")
def test_the_readme_has_no_bare_large_count(self):
readme = (ROOT / "README.md").read_text(encoding="utf-8")
+3 -3
View File
@@ -18,6 +18,7 @@ import unittest
from functools import cache
from pathlib import Path
from core.sizes import size_text
from model import releaserecord
from sitegen.readme import (
SITE_URL,
@@ -25,7 +26,6 @@ from sitegen.readme import (
contributing_text,
download_links,
download_table,
format_size,
)
REPO_ROOT = Path(__file__).resolve().parent.parent
@@ -380,8 +380,8 @@ class SizesComeFromTheRecord(unittest.TestCase):
if tag != RECORD.get("tag"):
self.skipTest(f"release.json records {RECORD.get('tag')}, not {tag}")
pack = releaserecord.pack_for(platform.lower(), RECORD)
self.assertEqual(download, format_size(pack["download_size"]))
self.assertEqual(extracted, format_size(pack["extracted_size"]))
self.assertEqual(download, size_text(pack["download_size"]))
self.assertEqual(extracted, size_text(pack["extracted_size"]))
class ContributorChecksMatchCi(unittest.TestCase):
+2 -1
View File
@@ -23,6 +23,7 @@ from unittest import mock
from installer_build import port
from model.registry import list_registered_platforms
from core.sizes import size_text
from sitegen import handheld as sitehandheld
from installer_build import handhelds
@@ -91,7 +92,7 @@ class TheSiteServesTheLaunchers(unittest.TestCase):
self.assertTrue((public / target).is_file(), target)
block = text.split(f'href="handheld/{name}"', 1)[1].split("\n\n", 2)[1]
self.assertIn(f"SHA-256: `{digest}`", block)
self.assertIn(sitehandheld._size(len(data)), block)
self.assertIn(size_text(len(data)), block)
self.assertRegex(block, r"- (Copy it to|Unzip it into) .+\.")
self.assertRegex(block, r"- Start it from .+\.")