Skip to content

Need to upgrade to build on Python 3.14 #175

@gbcox

Description

@gbcox

Created patch here: https://bugzilla.redhat.com/show_bug.cgi?id=2327966
Replace deprecated pkgutil with importlib.util

diff -uNr confuse-2.0.1.orig/confuse/util.py confuse-2.0.1/confuse/util.py
--- confuse-2.0.1.orig/confuse/util.py	2025-07-09 17:02:58.490043755 -0700
+++ confuse-2.0.1/confuse/util.py	2025-07-09 17:05:44.052782093 -0700
@@ -3,7 +3,7 @@
 import argparse
 import optparse
 import platform
-import pkgutil
+import importlib.util
 
 
 UNIX_DIR_FALLBACK = '~/.config'
@@ -110,23 +110,10 @@
 # defaults.
 
 def find_package_path(name):
-    """Returns the path to the package containing the named module or
-    None if the path could not be identified (e.g., if
-    ``name == "__main__"``).
-    """
-    # Based on get_root_path from Flask by Armin Ronacher.
-    loader = pkgutil.get_loader(name)
-    if loader is None or name == '__main__':
+    spec = importlib.util.find_spec(name)
+    if spec is None or spec.origin is None:
         return None
-
-    if hasattr(loader, 'get_filename'):
-        filepath = loader.get_filename(name)
-    else:
-        # Fall back to importing the specified module.
-        __import__(name)
-        filepath = sys.modules[name].__file__
-
-    return os.path.dirname(os.path.abspath(filepath))
+    return os.path.dirname(os.path.abspath(spec.origin))
 
 
 def xdg_config_dirs():diff -uNr confuse-2.0.1.orig/confuse/util.py confuse-2.0.1/confuse/util.py
--- confuse-2.0.1.orig/confuse/util.py	2025-07-09 17:02:58.490043755 -0700
+++ confuse-2.0.1/confuse/util.py	2025-07-09 17:05:44.052782093 -0700
@@ -3,7 +3,7 @@
 import argparse
 import optparse
 import platform
-import pkgutil
+import importlib.util
 
 
 UNIX_DIR_FALLBACK = '~/.config'
@@ -110,23 +110,10 @@
 # defaults.
 
 def find_package_path(name):
-    """Returns the path to the package containing the named module or
-    None if the path could not be identified (e.g., if
-    ``name == "__main__"``).
-    """
-    # Based on get_root_path from Flask by Armin Ronacher.
-    loader = pkgutil.get_loader(name)
-    if loader is None or name == '__main__':
+    spec = importlib.util.find_spec(name)
+    if spec is None or spec.origin is None:
         return None
-
-    if hasattr(loader, 'get_filename'):
-        filepath = loader.get_filename(name)
-    else:
-        # Fall back to importing the specified module.
-        __import__(name)
-        filepath = sys.modules[name].__file__
-
-    return os.path.dirname(os.path.abspath(filepath))
+    return os.path.dirname(os.path.abspath(spec.origin))
 
 
 def xdg_config_dirs():

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions