diff options
Diffstat (limited to 'wrapper.py')
-rw-r--r-- | wrapper.py | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -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 | ||
15 | import functools | ||
15 | import importlib.machinery | 16 | import importlib.machinery |
16 | import importlib.util | 17 | import importlib.util |
17 | import os | 18 | import 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 | |||
27 | def Wrapper(): | 26 | def 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 | ||