diff options
author | John Estabrook <jestabro@vyos.io> | 2024-06-19 20:37:23 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2024-09-11 11:09:31 -0500 |
commit | a79237bb168e611d2965031479d0786b8380e438 (patch) | |
tree | 65c264ac2504214bd63be496a2237671d0675aa0 /python/vyos/utils | |
parent | 98314d5c7513b97495e9199baa0be39b6f43f17f (diff) | |
download | vyos-1x-a79237bb168e611d2965031479d0786b8380e438.tar.gz vyos-1x-a79237bb168e611d2965031479d0786b8380e438.zip |
migration: T6007: use load_as_module_source for files without extension
(cherry picked from commit 8a57e7b14c818c93655819757d99b69747c9b2ca)
Diffstat (limited to 'python/vyos/utils')
-rw-r--r-- | python/vyos/utils/system.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/python/vyos/utils/system.py b/python/vyos/utils/system.py index 55813a5f7..cfd5b142c 100644 --- a/python/vyos/utils/system.py +++ b/python/vyos/utils/system.py @@ -98,3 +98,15 @@ def load_as_module(name: str, path: str): mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod + +def load_as_module_source(name: str, path: str): + """ Necessary modification of load_as_module for files without *.py + extension """ + import importlib.util + from importlib.machinery import SourceFileLoader + + loader = SourceFileLoader(name, path) + spec = importlib.util.spec_from_loader(name, loader) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod |