commit:     cbfbdc017247e6e4f71beea67c2400fa56d934fe
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 22 20:43:45 2025 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Nov 27 05:16:25 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=cbfbdc01

_prepare_self_update: remove module preloading

Module preloading is unnecessary since _prepare_self_update updates
sys.path to include a tempory backup of modules for the running
version of portage (see bug 965976). Also, since lazyimport usage
has been replaced with local imports, its preloading mechanism is
essentially useless.

Bug: https://bugs.gentoo.org/951146
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/elog/__init__.py                       | 15 -------------
 lib/portage/mail.py                                | 11 +++------
 lib/portage/package/ebuild/doebuild.py             |  7 +-----
 lib/portage/proxy/lazyimport.py                    | 26 +---------------------
 lib/portage/tests/lazyimport/meson.build           |  1 -
 .../lazyimport/test_preload_portage_submodules.py  | 16 -------------
 6 files changed, 5 insertions(+), 71 deletions(-)

diff --git a/lib/portage/elog/__init__.py b/lib/portage/elog/__init__.py
index 028ac6c75d..4a79cb6e6c 100644
--- a/lib/portage/elog/__init__.py
+++ b/lib/portage/elog/__init__.py
@@ -12,21 +12,6 @@ from portage.localization import _
 from portage import os
 
 
-def _preload_elog_modules(settings):
-    logsystems = settings.get("PORTAGE_ELOG_SYSTEM", "").split()
-    for s in logsystems:
-        # allow per module overrides of PORTAGE_ELOG_CLASSES
-        if ":" in s:
-            s, levels = s.split(":", 1)
-            levels = levels.split(",")
-        # - is nicer than _ for module names, so allow people to use it.
-        s = s.replace("-", "_")
-        try:
-            _load_mod("portage.elog.mod_" + s)
-        except ImportError:
-            pass
-
-
 def _merge_logentries(a, b):
     rValue = {}
     phases = set(a)

diff --git a/lib/portage/mail.py b/lib/portage/mail.py
index 20b139ad37..91c9520f24 100644
--- a/lib/portage/mail.py
+++ b/lib/portage/mail.py
@@ -1,14 +1,9 @@
-# Copyright 1998-2020 Gentoo Authors
+# Copyright 1998-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # Since python ebuilds remove the 'email' module when USE=build
-# is enabled, use a local import so that
-# portage.proxy.lazyimport._preload_portage_submodules()
-# can load this module even though the 'email' module is missing.
-# The elog mail modules won't work, but at least an ImportError
-# won't cause portage to crash during stage builds. Since the
-# 'smtlib' module imports the 'email' module, that's imported
-# locally as well.
+# is enabled, use a local import so that this module can still be
+# imported even though the 'email' module is missing.
 
 import sys
 

diff --git a/lib/portage/package/ebuild/doebuild.py 
b/lib/portage/package/ebuild/doebuild.py
index d23e6d8373..e55a56e7cb 100644
--- a/lib/portage/package/ebuild/doebuild.py
+++ b/lib/portage/package/ebuild/doebuild.py
@@ -71,7 +71,7 @@ from portage.eapi import (
     eapi_has_pkg_pretend,
     _get_eapi_attrs,
 )
-from portage.elog import elog_process, _preload_elog_modules
+from portage.elog import elog_process
 from portage.elog.messages import eerror, eqawarn
 from portage.exception import (
     DigestException,
@@ -3419,11 +3419,6 @@ def _prepare_self_update(settings):
     if portage._bin_path != portage.const.PORTAGE_BIN_PATH:
         return
 
-    # Load lazily referenced portage submodules into memory,
-    # so imports won't fail during portage upgrade/downgrade.
-    _preload_elog_modules(settings)
-    portage.proxy.lazyimport._preload_portage_submodules()
-
     # Make the temp directory inside $PORTAGE_TMPDIR/portage, since
     # it's common for /tmp and /var/tmp to be mounted with the
     # "noexec" option (see bug #346899).

diff --git a/lib/portage/proxy/lazyimport.py b/lib/portage/proxy/lazyimport.py
index c6a934ae93..6823e09d0e 100644
--- a/lib/portage/proxy/lazyimport.py
+++ b/lib/portage/proxy/lazyimport.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2023 Gentoo Authors
+# Copyright 2009-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 __all__ = ["lazyimport"]
@@ -14,30 +14,6 @@ _module_proxies = {}
 _module_proxies_lock = threading.RLock()
 
 
-def _preload_portage_submodules():
-    """
-    Load lazily referenced portage submodules into memory,
-    so imports won't fail during portage upgrade/downgrade.
-    Note that this recursively loads only the modules that
-    are lazily referenced by currently imported modules,
-    so some portage submodules may still remain unimported
-    after this function is called.
-    """
-    imported = set()
-    while True:
-        remaining = False
-        for name in list(_module_proxies):
-            if name.startswith("portage.") or name.startswith("_emerge."):
-                if name in imported:
-                    continue
-                imported.add(name)
-                remaining = True
-                __import__(name)
-                _unregister_module_proxy(name)
-        if not remaining:
-            break
-
-
 def _register_module_proxy(name, proxy):
     _module_proxies_lock.acquire()
     try:

diff --git a/lib/portage/tests/lazyimport/meson.build 
b/lib/portage/tests/lazyimport/meson.build
index b0377dc9ae..67664076d0 100644
--- a/lib/portage/tests/lazyimport/meson.build
+++ b/lib/portage/tests/lazyimport/meson.build
@@ -1,7 +1,6 @@
 py.install_sources(
     [
         'test_lazy_import_portage_baseline.py',
-        'test_preload_portage_submodules.py',
         '__init__.py',
         '__test__.py',
     ],

diff --git a/lib/portage/tests/lazyimport/test_preload_portage_submodules.py 
b/lib/portage/tests/lazyimport/test_preload_portage_submodules.py
deleted file mode 100644
index 123f953426..0000000000
--- a/lib/portage/tests/lazyimport/test_preload_portage_submodules.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# Copyright 2010 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-import portage
-from portage.tests import TestCase
-
-
-class PreloadPortageSubmodulesTestCase(TestCase):
-    def testPreloadPortageSubmodules(self):
-        """
-        Verify that _preload_portage_submodules() doesn't leave any
-        remaining proxies that refer to the portage.* namespace.
-        """
-        portage.proxy.lazyimport._preload_portage_submodules()
-        for name in portage.proxy.lazyimport._module_proxies:
-            self.assertEqual(name.startswith("portage."), False)

Reply via email to