From 461195c5046da1013a0cb201da917c41daf6f0dc Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Sat, 15 Jun 2024 21:02:39 -0500 Subject: vyos.utils.dict: T5195: fix syntax warning (cherry picked from commit 23356ee435344d8e9272f3a8a2273e00e7fca3ad) --- python/vyos/utils/dict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/vyos/utils') diff --git a/python/vyos/utils/dict.py b/python/vyos/utils/dict.py index 9a4671c5f..1a7a6b96f 100644 --- a/python/vyos/utils/dict.py +++ b/python/vyos/utils/dict.py @@ -34,7 +34,7 @@ def colon_separated_to_dict(data_string, uniquekeys=False): otherwise they are always lists of strings. """ import re - key_value_re = re.compile('([^:]+)\s*\:\s*(.*)') + key_value_re = re.compile(r'([^:]+)\s*\:\s*(.*)') data_raw = re.split('\n', data_string) -- cgit v1.2.3 From a79237bb168e611d2965031479d0786b8380e438 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 19 Jun 2024 20:37:23 -0500 Subject: migration: T6007: use load_as_module_source for files without extension (cherry picked from commit 8a57e7b14c818c93655819757d99b69747c9b2ca) --- python/vyos/compose_config.py | 4 ++-- python/vyos/utils/system.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'python/vyos/utils') diff --git a/python/vyos/compose_config.py b/python/vyos/compose_config.py index b1c277bce..79a8718c5 100644 --- a/python/vyos/compose_config.py +++ b/python/vyos/compose_config.py @@ -23,7 +23,7 @@ from typing import TypeAlias, Union, Callable from vyos.configtree import ConfigTree from vyos.configtree import deep_copy as ct_deep_copy -from vyos.utils.system import load_as_module +from vyos.utils.system import load_as_module_source ConfigObj: TypeAlias = Union[str, ConfigTree] @@ -64,7 +64,7 @@ class ComposeConfig: """ try: mod_name = Path(func_file).stem.replace('-', '_') - mod = load_as_module(mod_name, func_file) + mod = load_as_module_source(mod_name, func_file) func = getattr(mod, func_name) except Exception as e: raise ComposeConfigError(f'Error with {func_file}: {e}') from e 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 -- cgit v1.2.3