commit:     7871d17ae2fa0aacd579c470991af4a4edef7a22
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 27 16:19:16 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Dec 27 20:58:52 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=7871d17a

Scheduler: Print human-readable byte values in "parallelism reduced" warning

Bug: https://bugs.gentoo.org/967853
Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
Part-of: https://github.com/gentoo/portage/pull/1536
Closes: https://github.com/gentoo/portage/pull/1536
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/_emerge/Scheduler.py           | 19 ++++++++++++++++++-
 lib/portage/util/human_readable.py | 23 +++++++++++++++++++++++
 lib/portage/util/meson.build       |  1 +
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py
index b5c283bb09..f3b022e774 100644
--- a/lib/_emerge/Scheduler.py
+++ b/lib/_emerge/Scheduler.py
@@ -1929,7 +1929,24 @@ class Scheduler(PollScheduler):
 
                         if actual_free_bytes < required_free_bytes:
                             if not self._warned_tmpdir_free_space:
-                                msg = f"--- {tmpdir} has not enough free 
space, emerge job parallelism reduced. free: {actual_free_bytes} bytes, 
required {required_free_bytes} bytes"
+                                from portage.util.human_readable import 
bytes_to_human
+
+                                actual_free_bytes_hr = 
bytes_to_human(actual_free_bytes)
+                                required_free_bytes_hr = bytes_to_human(
+                                    required_free_bytes
+                                )
+
+                                actual_free_bytes_debug = ""
+                                required_free_bytes_debug = ""
+                                if "--debug" in self.myopts:
+                                    actual_free_bytes_debug = (
+                                        f" ({actual_free_bytes} bytes)"
+                                    )
+                                    required_free_bytes_debug = (
+                                        f" ({required_free_bytes} bytes)"
+                                    )
+
+                                msg = f"--- {tmpdir} has not enough free 
space, emerge job parallelism reduced. free: 
{actual_free_bytes_hr}{actual_free_bytes_debug}, required 
{required_free_bytes_hr}{required_free_bytes_debug}"
                                 portage.writemsg_stdout(
                                     colorize("WARN", f"\n{msg}\n"), 
noiselevel=-1
                                 )

diff --git a/lib/portage/util/human_readable.py 
b/lib/portage/util/human_readable.py
new file mode 100644
index 0000000000..cbb7514658
--- /dev/null
+++ b/lib/portage/util/human_readable.py
@@ -0,0 +1,23 @@
+# Copyright 2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+__all__ = ["bytes_to_human"]
+
+
+def bytes_to_human(size: int, decimal_places: int = 2) -> str:
+    """
+    Converts a size in bytes to a human-readable format (B, KiB, MiB, GiB, 
TiB, PiB).
+
+    Args:
+        size (int): The size in bytes.
+        decimal_places (int): The number of decimal places for the output.
+
+    Returns:
+        str: Human-readable string.
+    """
+    for unit in ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]:
+        if size < 1024.0 or unit == "PiB":
+            break
+        size /= 1024.0
+
+    return f"{size:.{decimal_places}f} {unit}"

diff --git a/lib/portage/util/meson.build b/lib/portage/util/meson.build
index 8daf3e4512..c910d8e4f4 100644
--- a/lib/portage/util/meson.build
+++ b/lib/portage/util/meson.build
@@ -13,6 +13,7 @@ py.install_sources(
         'file_copy.py',
         'formatter.py',
         'hooks.py',
+        'human_readable.py',
         'install_mask.py',
         'lafilefixer.py',
         'listdir.py',

Reply via email to