summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/test_wrapper.py2
-rw-r--r--wrapper.py19
2 files changed, 9 insertions, 12 deletions
diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py
index 2a0e542b..ef879a5d 100644
--- a/tests/test_wrapper.py
+++ b/tests/test_wrapper.py
@@ -38,7 +38,7 @@ class RepoWrapperTestCase(unittest.TestCase):
38 38
39 def setUp(self): 39 def setUp(self):
40 """Load the wrapper module every time.""" 40 """Load the wrapper module every time."""
41 wrapper._wrapper_module = None 41 wrapper.Wrapper.cache_clear()
42 self.wrapper = wrapper.Wrapper() 42 self.wrapper = wrapper.Wrapper()
43 43
44 44
diff --git a/wrapper.py b/wrapper.py
index 65dcf3c6..3099ad5d 100644
--- a/wrapper.py
+++ b/wrapper.py
@@ -12,6 +12,7 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15import functools
15import importlib.machinery 16import importlib.machinery
16import importlib.util 17import importlib.util
17import os 18import os
@@ -21,15 +22,11 @@ def WrapperPath():
21 return os.path.join(os.path.dirname(__file__), 'repo') 22 return os.path.join(os.path.dirname(__file__), 'repo')
22 23
23 24
24_wrapper_module = None 25@functools.lru_cache(maxsize=None)
25
26
27def Wrapper(): 26def Wrapper():
28 global _wrapper_module 27 modname = 'wrapper'
29 if not _wrapper_module: 28 loader = importlib.machinery.SourceFileLoader(modname, WrapperPath())
30 modname = 'wrapper' 29 spec = importlib.util.spec_from_loader(modname, loader)
31 loader = importlib.machinery.SourceFileLoader(modname, WrapperPath()) 30 module = importlib.util.module_from_spec(spec)
32 spec = importlib.util.spec_from_loader(modname, loader) 31 loader.exec_module(module)
33 _wrapper_module = importlib.util.module_from_spec(spec) 32 return module
34 loader.exec_module(_wrapper_module)
35 return _wrapper_module