Skip to content

Commit

Permalink
fix: minor changes to opossum_model.py
Browse files Browse the repository at this point in the history
* default to treating a Resource as file if the type is undefined and no children present
* provide slightly more information in an error message
  • Loading branch information
abraemer committed Jan 23, 2025
1 parent 31dd40e commit 60f4f48
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/opossum_lib/opossum_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ class Resource(BaseModel):
children: dict[str, Resource] = {}

def to_opossum_file_format(self) -> opossum_file.ResourceInFile:
if self.type == ResourceType.FILE:
return 1
else:
if self.children or self.type == ResourceType.FOLDER:
return {
str(child.path.relative_to(self.path)).replace(
"\\", "/"
): child.to_opossum_file_format()
for child in self.children.values()
}
else:
return 1

def add_resource(self, resource: Resource) -> None:
if not resource.path.is_relative_to(self.path):
Expand Down Expand Up @@ -174,7 +174,10 @@ def _update(self, other: Resource) -> None:
+ f"{self.path} vs. {other.path}"
)
if self.type and other.type and self.type != other.type:
raise RuntimeError("Trying to merge incompatible node types.")
raise RuntimeError(
"Trying to merge incompatible node types. "
+ f"Current node is {self.type}. Other is {other.type}"
)
self.type = self.type or other.type
self.attributions.extend(other.attributions)
for key, child in other.children.items():
Expand Down

0 comments on commit 60f4f48

Please sign in to comment.