diff options
Diffstat (limited to 'testing/mozbase/mozfile')
-rw-r--r-- | testing/mozbase/mozfile/mozfile/mozfile.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/testing/mozbase/mozfile/mozfile/mozfile.py b/testing/mozbase/mozfile/mozfile/mozfile.py index 1f4ffa74af..20d56fe4b2 100644 --- a/testing/mozbase/mozfile/mozfile/mozfile.py +++ b/testing/mozbase/mozfile/mozfile/mozfile.py @@ -22,6 +22,7 @@ __all__ = [ "extract", "is_url", "load", + "load_source", "copy_contents", "match", "move", @@ -629,6 +630,19 @@ def load(resource): return urllib.request.urlopen(resource) +# see https://docs.python.org/3/whatsnew/3.12.html#imp +def load_source(modname, filename): + import importlib.machinery + import importlib.util + + loader = importlib.machinery.SourceFileLoader(modname, filename) + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) + module = importlib.util.module_from_spec(spec) + sys.modules[module.__name__] = module + loader.exec_module(module) + return module + + # We can't depend on mozpack.path here, so copy the 'match' function over. re_cache = {} |