From f22ae56477c466d42307839b78c785b0fe109dcf Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 21 Sep 2024 14:04:07 +0200 Subject: [PATCH] Drop _emerge/getloadavg.py Portage's custom getloadavg.py wrapper was added with 8607a39dc9d9 ("If necessary, use /proc/loadavg to emulate os.getloadavg()."). All platforms we care about provide os.getloadavg() now, so this can be dropped. Zac did a nice analysis of the historical background in https://github.com/gentoo/portage/pull/1383#issuecomment-2375471855 to summarize: python on uclibc did not had os.getloadavg() in the past, but uclibc (and uclibc-ng) where retired in gentoo [1]. 1: https://www.gentoo.org/support/news-items/2021-08-18-uclibc-ng-retirement.html Signed-off-by: Florian Schmaus --- lib/_emerge/JobStatusDisplay.py | 5 ++--- lib/_emerge/PollScheduler.py | 5 ++--- lib/_emerge/Scheduler.py | 4 ++-- lib/_emerge/getloadavg.py | 29 ----------------------------- lib/_emerge/meson.build | 1 - 5 files changed, 6 insertions(+), 38 deletions(-) delete mode 100644 lib/_emerge/getloadavg.py diff --git a/lib/_emerge/JobStatusDisplay.py b/lib/_emerge/JobStatusDisplay.py index b98d4a8327..585712f512 100644 --- a/lib/_emerge/JobStatusDisplay.py +++ b/lib/_emerge/JobStatusDisplay.py @@ -4,6 +4,7 @@ import io import sys import time +import os import portage import portage.util.formatter as formatter @@ -12,8 +13,6 @@ from portage import _unicode_encode from portage.output import xtermTitle -from _emerge.getloadavg import getloadavg - class JobStatusDisplay: # Used as maximum display width and default fallback value. @@ -192,7 +191,7 @@ def _property_change(self, name, old_value, new_value): def _load_avg_str(self): try: - avg = getloadavg() + avg = os.getloadavg() except OSError: return "unknown" diff --git a/lib/_emerge/PollScheduler.py b/lib/_emerge/PollScheduler.py index fdf88dd04d..4e0d803845 100644 --- a/lib/_emerge/PollScheduler.py +++ b/lib/_emerge/PollScheduler.py @@ -2,13 +2,12 @@ # Distributed under the terms of the GNU General Public License v2 import threading +import os from portage.util.futures import asyncio from portage.util._async.SchedulerInterface import SchedulerInterface from portage.util._eventloop.global_event_loop import global_event_loop -from _emerge.getloadavg import getloadavg - class PollScheduler: # max time between loadavg checks (seconds) @@ -182,7 +181,7 @@ def _can_add_job(self): and self._running_job_count() >= 1 ): try: - avg1, avg5, avg15 = getloadavg() + avg1, avg5, avg15 = os.getloadavg() except OSError: return False diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py index 7d9023b0b9..b967f58dd0 100644 --- a/lib/_emerge/Scheduler.py +++ b/lib/_emerge/Scheduler.py @@ -12,6 +12,7 @@ import warnings import weakref import zlib +import os import portage from portage import os @@ -50,7 +51,6 @@ from _emerge.EbuildPhase import EbuildPhase from _emerge.emergelog import emergelog from _emerge.FakeVartree import FakeVartree -from _emerge.getloadavg import getloadavg from _emerge._find_deep_system_runtime_deps import _find_deep_system_runtime_deps from _emerge._flush_elog_mod_echo import _flush_elog_mod_echo from _emerge.JobStatusDisplay import JobStatusDisplay @@ -1962,7 +1962,7 @@ def _job_delay(self): self._sigcont_time = None try: - avg1, avg5, avg15 = getloadavg() + avg1, avg5, avg15 = os.getloadavg() except OSError: return False diff --git a/lib/_emerge/getloadavg.py b/lib/_emerge/getloadavg.py deleted file mode 100644 index f36d57e0e7..0000000000 --- a/lib/_emerge/getloadavg.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 1999-2013 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -from portage import os - -getloadavg = getattr(os, "getloadavg", None) -if getloadavg is None: - - def getloadavg(): - """ - Uses /proc/loadavg to emulate os.getloadavg(). - Raises OSError if the load average was unobtainable. - """ - try: - with open("/proc/loadavg") as f: - loadavg_str = f.readline() - except OSError: - # getloadavg() is only supposed to raise OSError, so convert - raise OSError("unknown") - loadavg_split = loadavg_str.split() - if len(loadavg_split) < 3: - raise OSError("unknown") - loadavg_floats = [] - for i in range(3): - try: - loadavg_floats.append(float(loadavg_split[i])) - except ValueError: - raise OSError("unknown") - return tuple(loadavg_floats) diff --git a/lib/_emerge/meson.build b/lib/_emerge/meson.build index fd463e5c27..01fc1c50b4 100644 --- a/lib/_emerge/meson.build +++ b/lib/_emerge/meson.build @@ -81,7 +81,6 @@ py.install_sources( 'create_world_atom.py', 'depgraph.py', 'emergelog.py', - 'getloadavg.py', 'help.py', 'is_valid_package_atom.py', 'main.py',