File: python3.12-replace-imp-by-importlib.patch

package info (click to toggle)
dblatex 0.3.12py3-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,880 kB
  • sloc: xml: 102,889; python: 8,274; makefile: 117; sh: 48
file content (112 lines) | stat: -rw-r--r-- 3,710 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Description: Python 3.12 compatibility: Replace imp by importlib
Forwarded: https://sourceforge.net/p/dblatex/patches/12/
Author: Miro HronĨok <mhroncok@redhat.com>
Last-Update: 2023-06-15

--- a/lib/dbtexmf/core/dbtex.py
+++ b/lib/dbtexmf/core/dbtex.py
@@ -15,7 +15,7 @@
 except ImportError:
     from urllib.request import pathname2url
 import glob
-import imp
+import importlib
 from optparse import OptionParser
 from io import open
 
@@ -540,15 +540,14 @@
 
     def load_plugin(self, pathname):
         moddir, modname = os.path.split(pathname)
-        try:
-            filemod, path, descr = imp.find_module(modname, [moddir])
-        except ImportError:
-            try:
-                filemod, path, descr = imp.find_module(modname)
-            except ImportError:
-                failed_exit("Error: '%s' module not found" % modname)
-        mod = imp.load_module(modname, filemod, path, descr)
-        filemod.close()
+        spec = importlib.machinery.PathFinder.find_spec(modname, [moddir])
+        if not spec:
+            spec = importlib.machinery.PathFinder.find_spec(modname)
+        if not spec:
+            failed_exit("Error: '%s' module not found" % modname)
+        mod = importlib.util.module_from_spec(spec)
+        spec.loader.exec_module(mod)
+        sys.modules[modname] = mod
         return mod
 
     def run_setup(self, options):
--- a/lib/dbtexmf/dblatex/grubber/plugins.py
+++ b/lib/dbtexmf/dblatex/grubber/plugins.py
@@ -4,7 +4,7 @@
 Mechanisms to dynamically load extra modules to help the LaTeX compilation.
 All the modules must be derived from the TexModule class.
 """
-import imp
+import importlib
 
 from os.path import *
 from dbtexmf.dblatex.grubber.msg import _, msg
@@ -108,17 +108,16 @@
         """
         if name in self.modules:
             return 2
-        try:
-            file, path, descr = imp.find_module(name, [""])
-        except ImportError:
+        spec = importlib.machinery.PathFinder.find_spec(name, [""])
+        if not spec:
             if not self.path:
                 return 0
-            try:
-                file, path, descr = imp.find_module(name, self.path)
-            except ImportError:
-                return 0
-        module = imp.load_module(name, file, path, descr)
-        file.close()
+            spec = importlib.machinery.PathFinder.find_spec(name, self.path)
+        if not spec:
+            return 0
+        module = importlib.util.module_from_spec(spec)
+        spec.loader.exec_module(module)
+        sys.modules[name] = module
         self.modules[name] = module
         return 1
 
--- a/lib/dbtexmf/xslt/xslt.py
+++ b/lib/dbtexmf/xslt/xslt.py
@@ -2,20 +2,21 @@
 # Very simple plugin loader for Xslt classes
 #
 import os
-import imp
+import importlib
 import glob
+import sys
 
 def load(modname):
-    try:
-        file, path, descr = imp.find_module(modname, [""])
-    except ImportError:
-        try:
-            file, path, descr = imp.find_module(modname,
-                                                [os.path.dirname(__file__)])
-        except ImportError:
-            raise ValueError("Xslt '%s' not found" % modname)
-    mod = imp.load_module(modname, file, path, descr)
-    file.close()
+    spec = importlib.machinery.PathFinder.find_spec(modname, [""])
+    if not spec:
+        spec = importlib.machinery.PathFinder.find_spec(modname,
+                                                        [os.path.dirname(__file__)])
+    if not spec:
+        raise ValueError("Xslt '%s' not found" % modname)
+
+    mod = importlib.util.module_from_spec(spec)
+    spec.loader.exec_module(mod)
+    sys.modules[modname] = mod
     o = mod.Xslt()
     return o