projects/guix·blob javascript-team · refs

134 lines · 4.6 KiB

1From 0094f13cf133c575d26b61a0b23351e085fb6142 Mon Sep 17 00:00:00 2001
2Message-ID: <0094f13cf133c575d26b61a0b23351e085fb6142.1769464831.git.ngraves@ngraves.fr>
3From: Nicolas Graves <[email protected]>
4Date: Mon, 26 Jan 2026 22:59:33 +0100
5Subject: [PATCH] Replace imp with importlib
6
7Combining
8https://sourceforge.net/p/dblatex/patches/12/attachment/dblatex-0.3.12-replace-imp-by-importlib.patch
9https://sourceforge.net/p/dblatex/patches/13/attachment/dblatex-0.3.12-adjust-submodule-imports.patch
10---
11 lib/dbtexmf/core/dbtex.py | 20 ++++++++++----------
12 lib/dbtexmf/dblatex/grubber/plugins.py | 20 ++++++++++----------
13 lib/dbtexmf/xslt/xslt.py | 24 +++++++++++++-----------
14 3 files changed, 33 insertions(+), 31 deletions(-)
15
16diff --git a/lib/dbtexmf/core/dbtex.py b/lib/dbtexmf/core/dbtex.py
17index b3ec732..4cf9591 100644
18--- a/lib/dbtexmf/core/dbtex.py
19+++ b/lib/dbtexmf/core/dbtex.py
20@@ -15,7 +15,8 @@ try:
21 except ImportError:
22 from urllib.request import pathname2url
23 import glob
24-import imp
25+import importlib.machinery
26+import importlib.util
27 from optparse import OptionParser
28 from io import open
29
30@@ -540,15 +541,14 @@ class DbTexCommand:
31
32 def load_plugin(self, pathname):
33 moddir, modname = os.path.split(pathname)
34- try:
35- filemod, path, descr = imp.find_module(modname, [moddir])
36- except ImportError:
37- try:
38- filemod, path, descr = imp.find_module(modname)
39- except ImportError:
40- failed_exit("Error: '%s' module not found" % modname)
41- mod = imp.load_module(modname, filemod, path, descr)
42- filemod.close()
43+ spec = importlib.machinery.PathFinder.find_spec(modname, [moddir])
44+ if not spec:
45+ spec = importlib.machinery.PathFinder.find_spec(modname)
46+ if not spec:
47+ failed_exit("Error: '%s' module not found" % modname)
48+ mod = importlib.util.module_from_spec(spec)
49+ spec.loader.exec_module(mod)
50+ sys.modules[modname] = mod
51 return mod
52
53 def run_setup(self, options):
54diff --git a/lib/dbtexmf/dblatex/grubber/plugins.py b/lib/dbtexmf/dblatex/grubber/plugins.py
55index 9e333c9..6b4ecb4 100644
56--- a/lib/dbtexmf/dblatex/grubber/plugins.py
57+++ b/lib/dbtexmf/dblatex/grubber/plugins.py
58@@ -4,7 +4,8 @@
59 Mechanisms to dynamically load extra modules to help the LaTeX compilation.
60 All the modules must be derived from the TexModule class.
61 """
62-import imp
63+import importlib.machinery
64+import importlib.util
65
66 from os.path import *
67 from dbtexmf.dblatex.grubber.msg import _, msg
68@@ -108,17 +109,16 @@ class Plugins (object):
69 """
70 if name in self.modules:
71 return 2
72- try:
73- file, path, descr = imp.find_module(name, [""])
74- except ImportError:
75+ spec = importlib.machinery.PathFinder.find_spec(name, [""])
76+ if not spec:
77 if not self.path:
78 return 0
79- try:
80- file, path, descr = imp.find_module(name, self.path)
81- except ImportError:
82- return 0
83- module = imp.load_module(name, file, path, descr)
84- file.close()
85+ spec = importlib.machinery.PathFinder.find_spec(name, self.path)
86+ if not spec:
87+ return 0
88+ module = importlib.util.module_from_spec(spec)
89+ spec.loader.exec_module(module)
90+ sys.modules[name] = module
91 self.modules[name] = module
92 return 1
93
94diff --git a/lib/dbtexmf/xslt/xslt.py b/lib/dbtexmf/xslt/xslt.py
95index 0350e30..7cc2038 100644
96--- a/lib/dbtexmf/xslt/xslt.py
97+++ b/lib/dbtexmf/xslt/xslt.py
98@@ -2,20 +2,22 @@
99 # Very simple plugin loader for Xslt classes
100 #
101 import os
102-import imp
103+import importlib.machinery
104+import importlib.util
105 import glob
106+import sys
107
108 def load(modname):
109- try:
110- file, path, descr = imp.find_module(modname, [""])
111- except ImportError:
112- try:
113- file, path, descr = imp.find_module(modname,
114- [os.path.dirname(__file__)])
115- except ImportError:
116- raise ValueError("Xslt '%s' not found" % modname)
117- mod = imp.load_module(modname, file, path, descr)
118- file.close()
119+ spec = importlib.machinery.PathFinder.find_spec(modname, [""])
120+ if not spec:
121+ spec = importlib.machinery.PathFinder.find_spec(modname,
122+ [os.path.dirname(__file__)])
123+ if not spec:
124+ raise ValueError("Xslt '%s' not found" % modname)
125+
126+ mod = importlib.util.module_from_spec(spec)
127+ spec.loader.exec_module(mod)
128+ sys.modules[modname] = mod
129 o = mod.Xslt()
130 return o
131
132--
1332.52.0
134