Skip to content

Commit

Permalink
fix absolute paths in translated imports
Browse files Browse the repository at this point in the history
  • Loading branch information
detjensrobert committed Sep 14, 2023
1 parent c939da9 commit b2a1687
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions tosca-package/tosca/yaml2python.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ def convert_import(self, imp: dict[str, str]) -> Tuple[str, str]:
# file is required by TOSCA spec, so crash and burn if we don't have it
assert file, "file is required for TOSCA imports"

# print(f"OCDEBUG:: ---")

# figure out loading path
filepath = PurePath(file)
dirname = filepath.parent
Expand All @@ -328,36 +330,47 @@ def convert_import(self, imp: dict[str, str]) -> Tuple[str, str]:
module_name, _import_path = self.find_repository(repo)
import_path = PurePath(_import_path)

# print(f"OCDEBUG: repo {module_name=}, {import_path=}")
# print(f"OCDEBUG: {import_path.parts=}, {dirname.parts=}")
# print(f"OCDEBUG:: is repo")
# print(f"OCDEBUG:: {module_name=}, {import_path=}")
# print(f"OCDEBUG:: {import_path.parts=}, {dirname.parts=}")

# import should be path.to.repo.path.to.file
module_name = ".".join(
['' if d == '..' else d for d in [
*import_path.parts,
*dirname.parts
]]
)
# # import should be path.to.repo.path.to.file
# module_name = ".".join(
# ['' if d == '..' else d for d in [
# # *import_path.parts,
# module_name,
# *dirname.parts
# ]]
# )

else:
# otherwise assume local path
import_path = PurePath(self.template.path).parent
# prefix module_name with . if relative path
# module_name = "" if import_path.is_absolute() else "."

# print(f"OCDEBUG: non-repo {module_name=}, {import_path=}")
print(f"OCDEBUG: {import_path.parts=}, {dirname.parts=}")

# import should be .path.to.file
module_name = ".".join(
['' if d == '..' else d for d in [
'', # for leading dot
# *import_path.parts,
*dirname.parts
]]
)
module_name = ""

# print(f"OCDEBUG:: non-repo")
# print(f"OCDEBUG:: {module_name=}, {import_path=}")
# print(f"OCDEBUG:: {import_path.parts=}, {dirname.parts=}")

# # import should be .path.to.file
# module_name = ".".join(
# ['' if d == '..' else d for d in [
# '', # for leading dot
# # *import_path.parts,
# *dirname.parts
# ]]
# )

# import should be .path.to.file
module_name = ".".join(
['' if d == '..' else d for d in [
module_name,
*dirname.parts
]]
)

# print(f"OCDEBUG: after translation {module_name=}")
# print(f"OCDEBUG:: after translation {module_name=}")

# handle tosca namespace prefixes
if namespace:
Expand Down

0 comments on commit b2a1687

Please sign in to comment.