Skip to content
Snippets Groups Projects
Commit c2b7f892 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

STY: automatic code formatting and removal of unused imports

parent 2bd769df
Branches
Tags
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!167Sync Graph
Pipeline #50994 passed with warnings
...@@ -23,13 +23,14 @@ ...@@ -23,13 +23,14 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING from typing import TYPE_CHECKING, Any, Optional, Union
import linkahead as db import linkahead as db
import yaml import yaml
from linkahead.common.models import _ParentList, _Properties, Parent from linkahead.common.models import Parent, _ParentList, _Properties
from .exceptions import ImpossibleMergeError from .exceptions import ImpossibleMergeError
if TYPE_CHECKING: if TYPE_CHECKING:
from .identifiable import Identifiable from .identifiable import Identifiable
...@@ -40,7 +41,7 @@ class TempID(int): ...@@ -40,7 +41,7 @@ class TempID(int):
pass pass
class SyncNode(): class SyncNode:
"""represents the information of an Entity as it shall be created in LinkAhead """represents the information of an Entity as it shall be created in LinkAhead
The following information is taken from an db.Entity object during initialization or when the The following information is taken from an db.Entity object during initialization or when the
...@@ -60,8 +61,9 @@ class SyncNode(): ...@@ -60,8 +61,9 @@ class SyncNode():
3. A db.Entity object is created (`export_entity`) that contains the combined information. 3. A db.Entity object is created (`export_entity`) that contains the combined information.
""" """
def __init__(self, entity: db.Entity, registered_identifiable: Optional[db.RecordType] = def __init__(
None) -> None: self, entity: db.Entity, registered_identifiable: Optional[db.RecordType] = None
) -> None:
# db.Entity properties # db.Entity properties
self.id: Union[int, TempID, str] = entity.id self.id: Union[int, TempID, str] = entity.id
self.role = entity.role self.role = entity.role
...@@ -83,12 +85,16 @@ class SyncNode(): ...@@ -83,12 +85,16 @@ class SyncNode():
""" """
if other.identifiable is not None and self.identifiable is not None: if other.identifiable is not None and self.identifiable is not None:
if (other.identifiable.get_representation() != self.identifiable.get_representation()): if (
other.identifiable.get_representation()
!= self.identifiable.get_representation()
):
raise ValueError( raise ValueError(
"The SyncNode that is used with update must have an equivalent" "The SyncNode that is used with update must have an equivalent"
f" identifiable. The identifiables where:\n" f" identifiable. The identifiables where:\n"
f"{self.identifiable.get_representation()}\n" f"{self.identifiable.get_representation()}\n"
f"and\n{other.identifiable.get_representation()}.") f"and\n{other.identifiable.get_representation()}."
)
if other.identifiable: if other.identifiable:
self.identifiable = other.identifiable self.identifiable = other.identifiable
...@@ -150,15 +156,17 @@ class SyncNode(): ...@@ -150,15 +156,17 @@ class SyncNode():
unequal = True unequal = True
if unequal: if unequal:
logger.error("The Crawler is trying to create an entity," logger.error(
"The Crawler is trying to create an entity,"
" but there are have conflicting property values." " but there are have conflicting property values."
f"Problematic Property: {p.name}\n" f"Problematic Property: {p.name}\n"
f"First value:\n{entval}\n" f"First value:\n{entval}\n"
f"Second value:\n{pval}\n" f"Second value:\n{pval}\n"
f"{self}" f"{self}"
) )
ime = ImpossibleMergeError("Cannot merge Entities", pname=p.name, ime = ImpossibleMergeError(
values=(entval, pval)) "Cannot merge Entities", pname=p.name, values=(entval, pval)
)
raise ime raise ime
return ent return ent
...@@ -168,8 +176,14 @@ class SyncNode(): ...@@ -168,8 +176,14 @@ class SyncNode():
res += f"user: {self._metadata['user']}\n" res += f"user: {self._metadata['user']}\n"
res += f"json: {self._metadata['json']}\n" res += f"json: {self._metadata['json']}\n"
res += "---------------------------------------------------\n" res += "---------------------------------------------------\n"
res += yaml.dump({"id": self.id, "name": self.name, res += yaml.dump(
"parents": [el.name for el in self.parents]}, allow_unicode=True) {
"id": self.id,
"name": self.name,
"parents": [el.name for el in self.parents],
},
allow_unicode=True,
)
res += "---------------------------------------------------\n" res += "---------------------------------------------------\n"
res += "properties:\n" res += "properties:\n"
d: dict[str, Any] = {} d: dict[str, Any] = {}
...@@ -180,18 +194,28 @@ class SyncNode(): ...@@ -180,18 +194,28 @@ class SyncNode():
v = [v] v = [v]
for el in v: for el in v:
if isinstance(el, SyncNode): if isinstance(el, SyncNode):
d[p.name].append({"id": el.id, "name": el.name, "parents": [e.name for e in d[p.name].append(
el.parents]}) {
"id": el.id,
"name": el.name,
"parents": [e.name for e in el.parents],
}
)
else: else:
d[p.name].append(el) d[p.name].append(el)
return (res + yaml.dump(d, allow_unicode=True) return (
+ "=====================================================\n") res
+ yaml.dump(d, allow_unicode=True)
+ "=====================================================\n"
)
def is_unidentifiable(self) -> bool: def is_unidentifiable(self) -> bool:
"""returns whether this is an unidentifiable Node""" """returns whether this is an unidentifiable Node"""
return (self.registered_identifiable is not None and return (
self.registered_identifiable.get_property("no-ident") is not None) self.registered_identifiable is not None
and self.registered_identifiable.get_property("no-ident") is not None
)
def parent_in_list(parent: Parent, plist: _ParentList) -> bool: def parent_in_list(parent: Parent, plist: _ParentList) -> bool:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment