Skip to content

Commit

Permalink
dsl: python to yaml: warn when python module for tosca import wasn't …
Browse files Browse the repository at this point in the history
…loaded.
  • Loading branch information
aszs committed Nov 13, 2024
1 parent 2c5899e commit 0e90f6e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tosca-package/tosca/python2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def find_yaml_import(
self, module_name: str
) -> Tuple[Optional[ModuleType], Optional[Path]]:
"Find the given Python module and corresponding yaml file path"
# Python import should already have happened
module = self.modules.get(module_name)
if not module:
return None, None
Expand Down Expand Up @@ -254,9 +255,7 @@ def _imported_module2yaml(self, module: ModuleType) -> Path:
return yaml_path

# skip leading / and parts corresponding to the module name
base_dir = "/".join(
path.parts[1 : -len(module.__name__.split("."))]
)
base_dir = "/".join(path.parts[1 : -len(module.__name__.split("."))])
with open(path) as sf:
src = sf.read()
namespace: dict = dict(__file__=str(path))
Expand Down Expand Up @@ -387,9 +386,15 @@ def _import_module(
# this type was imported from another module
# instead of converting the type, add an import if missing
module, yaml_path = self.find_yaml_import(module_name)
if not yaml_path and module:
# its a TOSCA object but no yaml file found, convert to yaml now
yaml_path = self._imported_module2yaml(module)
if not yaml_path:
if module:
# its a TOSCA object but no yaml file found, convert to yaml now
yaml_path = self._imported_module2yaml(module)
else:
logger.warning(
f"Import of {module_name} in {current_module} failed, module wasn't loaded."
)
return
if yaml_path:
try:
module_dir = Path(os.path.dirname(module_path))
Expand Down

0 comments on commit 0e90f6e

Please sign in to comment.