Skip to content

Commit

Permalink
dsl: python to yaml: make sure import yaml is generated for imported …
Browse files Browse the repository at this point in the history
…types
  • Loading branch information
aszs committed Sep 29, 2024
1 parent 29d7335 commit 1e7c064
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions tosca-package/tosca/python2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ def add_template(
if module_name:
section[name].setdefault("metadata", {})["module"] = module_name
obj.register_template(module_name, name)
if obj.__class__.__module__ != module_name:
if (
obj.__class__.__module__ != "unfurl.tosca_plugins.tosca_ext"
and not obj.__class__.__module__.startswith("tosca.")
): # skip built-in modules
module_path = self.globals.get("__file__")
self._import_module(
module_name, module_path, obj.__class__.__module__
)
self.templates.append(obj)
return name

Expand Down Expand Up @@ -386,20 +395,22 @@ def _import_module(
import_path = yaml_path.relative_to(module_dir)
else:
import_path = module_dir / yaml_path
self.imports.add(("", import_path))
logger.debug(
f'"{current_module}" is importing "{module_name}": located at "{import_path}", relative to "{module_path}"'
)
_key = ("", import_path)
if _key not in self.imports:
self.imports.add(_key)
logger.debug(
f'"{current_module}" is importing "{module_name}": located at "{import_path}", relative to "{module_path}"'
)
except ValueError:
# not a subpath of the current module, add a repository
ns, repo_path = self._set_repository_for_module(
module_name, yaml_path
)
ns, repo_path = self._set_repository_for_module(module_name, yaml_path)
if repo_path:
logger.debug(
f'"{current_module}" is importing "{module_name}" in package "{ns}": located at "{repo_path}""'
)
self.imports.add((ns, repo_path))
_key = (ns, repo_path)
if _key not in self.imports:
self.imports.add(_key)
logger.debug(
f'"{current_module}" is importing "{module_name}" in package "{ns}": located at "{repo_path}""'
)
else:
if ns:
logger.warning(
Expand Down

0 comments on commit 1e7c064

Please sign in to comment.