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
No related branches found
No related tags found
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!167Sync Graph
Pipeline #50994 passed with warnings
......@@ -23,13 +23,14 @@
from __future__ import annotations
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 yaml
from linkahead.common.models import _ParentList, _Properties, Parent
from linkahead.common.models import Parent, _ParentList, _Properties
from .exceptions import ImpossibleMergeError
if TYPE_CHECKING:
from .identifiable import Identifiable
......@@ -40,8 +41,8 @@ class TempID(int):
pass
class SyncNode():
""" represents the information of an Entity as it shall be created in LinkAhead
class SyncNode:
"""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
object is updated using the `update` member function:
......@@ -60,8 +61,9 @@ class SyncNode():
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] =
None) -> None:
def __init__(
self, entity: db.Entity, registered_identifiable: Optional[db.RecordType] = None
) -> None:
# db.Entity properties
self.id: Union[int, TempID, str] = entity.id
self.role = entity.role
......@@ -83,12 +85,16 @@ class SyncNode():
"""
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(
"The SyncNode that is used with update must have an equivalent"
f" identifiable. The identifiables where:\n"
f"{self.identifiable.get_representation()}\n"
f"and\n{other.identifiable.get_representation()}.")
f"and\n{other.identifiable.get_representation()}."
)
if other.identifiable:
self.identifiable = other.identifiable
......@@ -105,7 +111,7 @@ class SyncNode():
self.properties.append(p)
def export_entity(self) -> db.Entity:
""" create a db.Entity object from this SyncNode
"""create a db.Entity object from this SyncNode
Properties are only added once (based on id or name). If values do not match, an Error is
raised. If values are SyncNode objects with IDs, they are considered equal if their IDs are
......@@ -150,15 +156,17 @@ class SyncNode():
unequal = True
if unequal:
logger.error("The Crawler is trying to create an entity,"
" but there are have conflicting property values."
f"Problematic Property: {p.name}\n"
f"First value:\n{entval}\n"
f"Second value:\n{pval}\n"
f"{self}"
)
ime = ImpossibleMergeError("Cannot merge Entities", pname=p.name,
values=(entval, pval))
logger.error(
"The Crawler is trying to create an entity,"
" but there are have conflicting property values."
f"Problematic Property: {p.name}\n"
f"First value:\n{entval}\n"
f"Second value:\n{pval}\n"
f"{self}"
)
ime = ImpossibleMergeError(
"Cannot merge Entities", pname=p.name, values=(entval, pval)
)
raise ime
return ent
......@@ -168,8 +176,14 @@ class SyncNode():
res += f"user: {self._metadata['user']}\n"
res += f"json: {self._metadata['json']}\n"
res += "---------------------------------------------------\n"
res += yaml.dump({"id": self.id, "name": self.name,
"parents": [el.name for el in self.parents]}, allow_unicode=True)
res += yaml.dump(
{
"id": self.id,
"name": self.name,
"parents": [el.name for el in self.parents],
},
allow_unicode=True,
)
res += "---------------------------------------------------\n"
res += "properties:\n"
d: dict[str, Any] = {}
......@@ -180,18 +194,28 @@ class SyncNode():
v = [v]
for el in v:
if isinstance(el, SyncNode):
d[p.name].append({"id": el.id, "name": el.name, "parents": [e.name for e in
el.parents]})
d[p.name].append(
{
"id": el.id,
"name": el.name,
"parents": [e.name for e in el.parents],
}
)
else:
d[p.name].append(el)
return (res + yaml.dump(d, allow_unicode=True)
+ "=====================================================\n")
return (
res
+ yaml.dump(d, allow_unicode=True)
+ "=====================================================\n"
)
def is_unidentifiable(self) -> bool:
"""returns whether this is an unidentifiable Node"""
return (self.registered_identifiable is not None and
self.registered_identifiable.get_property("no-ident") is not None)
return (
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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment