commit:     95e8f3b3d418347eaa36aa3eed40de2a6e436d35
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Tue Jan 17 09:07:19 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sun Feb  5 18:08:21 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=95e8f3b3

fix(config): Add deprecation warnings for very old config shims

The context of this is fa90aff05306fb4935604e64645f2d1d2049233e; the
original 'central' manager exposed objecst in the same attr namespace as
it's own internals.  Whilst no conflicts occured, it was possible, so
the configuration objects were moved to .objects to remove the potential.

A compatibility shim was added (CompatConfigManager), but no warnings
were added at the time due to presumably the module not existing.

Either way, it exists, thus add a warning.  There are multiple users
in pkgcore's code (fixed in followup commit).  Pkgcheck and pkgdev are
clean, but it may be wise to wait a release or two before removing the
compatibility shim.  It's been in place 11 years, not like it's going to
kill us to wait another month...

Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcore/config/central.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/pkgcore/config/central.py b/src/pkgcore/config/central.py
index 0cd2f392e..12e0ce13b 100644
--- a/src/pkgcore/config/central.py
+++ b/src/pkgcore/config/central.py
@@ -9,6 +9,7 @@ __all__ = (
 )
 
 import typing
+import warnings
 import weakref
 from collections import defaultdict, deque, namedtuple
 
@@ -255,6 +256,12 @@ class _ConfigObjMap:
 
 
 class CompatConfigManager:
+    """This is a compatibility hack to alias attribute access to the new 
location
+
+    See commit fa90aff05306fb4935604e64645f2d1d2049233e for when this was 
introduced.
+
+    This should be removed once consumers are converted in their access."""
+
     def __init__(self, manager) -> None:
         self._manager = manager
 
@@ -264,6 +271,10 @@ class CompatConfigManager:
         obj = getattr(self._manager, attr, klass.sentinel)
         if obj is klass.sentinel:
             obj = getattr(self._manager.objects, attr)
+            warnings.warn(
+                f"Access to central objects must be done via '.objects.{attr}' 
rather than '.{attr}'",
+                stacklevel=2,
+            )
         return obj
 
     __dir__ = klass.DirProxy("_manager")

Reply via email to