diff --git a/tosca-package/tosca/loader.py b/tosca-package/tosca/loader.py index 90182ab7..35d5b398 100644 --- a/tosca-package/tosca/loader.py +++ b/tosca-package/tosca/loader.py @@ -81,7 +81,10 @@ def find_spec(cls, fullname: str, path=None, target=None, modules=None): if len(names) == 1: return ModuleSpec(fullname, None, origin=dir_path, is_package=True) else: - origin_path = os.path.join(dir_path, *names[1:]) + ".py" + origin_path = os.path.join(dir_path, *names[1:]) + if os.path.isdir(origin_path): + return ModuleSpec(fullname, None, origin=origin_path, is_package=True) + origin_path += ".py" loader = ToscaYamlLoader(fullname, origin_path, modules) spec = spec_from_loader(fullname, loader, origin=origin_path) return spec @@ -195,14 +198,17 @@ def load_private_module(base_dir: str, modules: Dict[str, ModuleType], name: str if name in ALLOWED_PRIVATE_PACKAGES or parent == "service_template": spec = ModuleSpec(name, None, origin=origin_path, is_package=True) else: - origin_path += ".py" - if not os.path.isfile(origin_path): - raise ModuleNotFoundError( - f"No module named {name} at {origin_path}", name=name - ) - loader = ToscaYamlLoader(name, origin_path, modules) - spec = spec_from_loader(name, loader, origin=origin_path) - assert spec and spec.loader + if os.path.isdir(origin_path): + spec = ModuleSpec(name, None, origin=origin_path, is_package=True) + else: + origin_path += ".py" + if not os.path.isfile(origin_path): + raise ModuleNotFoundError( + f"No module named {name} at {origin_path}", name=name + ) + loader = ToscaYamlLoader(name, origin_path, modules) + spec = spec_from_loader(name, loader, origin=origin_path) + assert spec and spec.loader module = module_from_spec(spec) modules[name] = module if not spec.loader: diff --git a/unfurl/logs.py b/unfurl/logs.py index ce4dd20b..ffa64650 100644 --- a/unfurl/logs.py +++ b/unfurl/logs.py @@ -188,7 +188,8 @@ def filter(self, record: logging.LogRecord) -> bool: else: if record.args is not None: record.args = tuple(self.redact(a) for a in record.args) - record.msg = self.sanitize_urls(record.msg) + if isinstance(record.msg, str): + record.msg = self.sanitize_urls(record.msg) return True @staticmethod