File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 2828import importlib
2929from importlib import machinery
3030import inspect
31+ import functools
3132
3233from . import pythonmonkey as pm
3334
@@ -247,7 +248,12 @@ def createRequire(filename):
247248})""" )
248249 return createRequireInner (filename )
249250
251+ # We cache the return value of createRequire to always use the same require for the same filename
252+ @functools .lru_cache (maxsize = None ) # unbounded function cache that won't remove any old values
253+ def _getRequire (filename : str ):
254+ return createRequire (filename )
255+
250256def require (moduleIdentifier : str ):
251257 # Retrieve the caller’s filename from the call stack
252258 filename = inspect .stack ()[1 ].filename
253- return createRequire (filename )(moduleIdentifier )
259+ return _getRequire (filename )(moduleIdentifier )
You can’t perform that action at this time.
0 commit comments