Skip to content

Commit 88853ec

Browse files
committed
formatted with black
1 parent 0085b83 commit 88853ec

9 files changed

+79
-101
lines changed

build.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
include_instances = True # to speed up the build during development, set this to False
1717

1818
parser = argparse.ArgumentParser(prog=sys.argv[0], description="Generate Python package for openMINDS")
19-
parser.add_argument('--branch', help="The branch to build from ('main' or 'development')", default="main")
19+
parser.add_argument("--branch", help="The branch to build from ('main' or 'development')", default="main")
2020
args = parser.parse_args()
2121

2222
print("*******************************************************************************")
@@ -59,13 +59,14 @@
5959
class_to_module_map = {}
6060
for schema_file_path in schemas_file_paths:
6161
emb, lnk = PythonBuilder(schema_file_path, schema_loader.schemas_sources).get_edges()
62-
class_to_module_map=PythonBuilder(schema_file_path, schema_loader.schemas_sources).update_class_to_module_map(class_to_module_map)
62+
class_to_module_map = PythonBuilder(
63+
schema_file_path, schema_loader.schemas_sources
64+
).update_class_to_module_map(class_to_module_map)
6365
embedded.update(emb)
6466
linked.update(lnk)
6567
conflicts = linked.intersection(embedded)
6668
if conflicts:
67-
print(f"Found schema(s) in version {schema_version} "
68-
f"that are both linked and embedded: {conflicts}")
69+
print(f"Found schema(s) in version {schema_version} " f"that are both linked and embedded: {conflicts}")
6970
# conflicts should not happen in new versions.
7071
# There is one conflict in v1.0, QuantitativeValue,
7172
# which we treat as embedded
@@ -79,7 +80,7 @@
7980
schema_loader.schemas_sources,
8081
instances=instances.get(schema_version, None),
8182
additional_methods=additional_methods,
82-
).build(embedded=embedded,class_to_module_map=class_to_module_map)
83+
).build(embedded=embedded, class_to_module_map=class_to_module_map)
8384

8485
parts = module_path.split(".")
8586
parent_path = ".".join(parts[:-1])
@@ -109,10 +110,7 @@
109110
with open(init_file_path, "w") as fp:
110111
fp.write(f"from . import ({', '.join(sorted(module_list))})\n")
111112

112-
env = Environment(
113-
loader=FileSystemLoader(os.path.dirname(os.path.realpath(__file__))),
114-
autoescape=select_autoescape()
115-
)
113+
env = Environment(loader=FileSystemLoader(os.path.dirname(os.path.realpath(__file__))), autoescape=select_autoescape())
116114
context = {
117115
"version": "0.3.0",
118116
}

pipeline/src/base.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def value_to_jsonld(value, include_empty_properties=True, embed_linked_nodes=Tru
2727
)
2828
else:
2929
if hasattr(value, "id") and value.id is None:
30-
raise ValueError(
31-
"Exporting as a stand-alone JSON-LD document requires @id to be defined."
32-
)
30+
raise ValueError("Exporting as a stand-alone JSON-LD document requires @id to be defined.")
3331
item = {"@id": value.id}
3432
elif isinstance(value, EmbeddedMetadata):
3533
item = value.to_jsonld(
@@ -64,9 +62,7 @@ def has_property(self, name):
6462
return True
6563
return False
6664

67-
def to_jsonld(
68-
self, include_empty_properties=True, embed_linked_nodes=True, with_context=True
69-
):
65+
def to_jsonld(self, include_empty_properties=True, embed_linked_nodes=True, with_context=True):
7066
"""
7167
Return a represention of this metadata node as a dictionary that can be directly serialized to JSON-LD.
7268
"""

pipeline/src/collection.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ def save(self, path, individual_files=False, include_empty_properties=False):
8585
# we first re-add all child nodes to the collection.
8686
# This is probably not the most elegant or fast way to do this, but it is simple and robust.
8787
for node in tuple(self.nodes.values()):
88-
88+
8989
if node.type_.startswith("https://openminds.ebrains.eu/"):
9090
data_context = {"@vocab": "https://openminds.ebrains.eu/vocab/"}
9191
else:
9292
data_context = {"@vocab": "https://openminds.om-i.org/props/"}
93-
93+
9494
for linked_node in node.links:
9595
self._add_node(linked_node)
9696
# Now we can actually save the nodes
@@ -118,7 +118,9 @@ def save(self, path, individual_files=False, include_empty_properties=False):
118118
if not os.path.exists(path):
119119
os.makedirs(path, exist_ok=True)
120120
if not os.path.isdir(path):
121-
raise OSError(f"If saving to multiple files, `path` must be a directory. path={path}, pwd={os.getcwd()}")
121+
raise OSError(
122+
f"If saving to multiple files, `path` must be a directory. path={path}, pwd={os.getcwd()}"
123+
)
122124
output_paths = []
123125
for node in self:
124126
if node.id.startswith("http"):
@@ -161,12 +163,12 @@ def load(self, *paths):
161163
data = json.load(fp)
162164
if "@graph" in data:
163165
if data["@context"]["@vocab"].startswith("https://openminds.ebrains.eu/"):
164-
version="v3"
166+
version = "v3"
165167
else:
166-
version="latest"
168+
version = "latest"
167169
for item in data["@graph"]:
168170
if "@type" in item:
169-
cls = lookup_type(item["@type"],version=version)
171+
cls = lookup_type(item["@type"], version=version)
170172
node = cls.from_jsonld(item)
171173
else:
172174
# allow links to metadata instances outside this collection

pipeline/src/properties.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def validate(self, value, ignore=None):
118118
failures["type"].append(
119119
f"{self.name}: Expected {', '.join(t.__name__ for t in self.types)}, "
120120
f"value contains {type(item)}"
121-
)
121+
)
122122
elif isinstance(item, (Node, IRI)):
123123
failures.update(item.validate(ignore=ignore))
124124
if self.min_items:
@@ -148,7 +148,8 @@ def validate(self, value, ignore=None):
148148
elif not isinstance(value, self.types):
149149
if "type" not in ignore:
150150
failures["type"].append(
151-
f"{self.name}: Expected {', '.join(t.__name__ for t in self.types)}, " f"value is {type(value)}"
151+
f"{self.name}: Expected {', '.join(t.__name__ for t in self.types)}, "
152+
f"value is {type(value)}"
152153
)
153154
elif isinstance(value, (Node, IRI)):
154155
failures.update(value.validate(ignore=ignore))

pipeline/src/registry.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def lookup_type(class_type: str, version: str = "latest") -> Node:
6868

6969
class Registry(type):
7070
"""Metaclass for registering Knowledge Graph classes."""
71+
7172
properties: List[Property] = []
7273
type_: Union[str, List[str]]
7374
context: Dict[str, str]
@@ -107,4 +108,3 @@ def property_names(cls) -> List[str]:
107108
@property
108109
def required_property_names(cls) -> List[str]:
109110
return [p.name for p in cls.properties if p.required]
110-

pipeline/tests/test_instantiation.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ def test_json_roundtrip():
5555

5656

5757
def test_IRI():
58-
valid_iris = [
59-
"https://example.com/path/to/my/file.txt",
60-
"file:///path/to/my/file.txt"
61-
]
58+
valid_iris = ["https://example.com/path/to/my/file.txt", "file:///path/to/my/file.txt"]
6259
for value in valid_iris:
6360
iri = IRI(value)
6461
assert iri.value == value
@@ -67,9 +64,7 @@ def test_IRI():
6764
assert not failures
6865
else:
6966
assert failures["value"][0] == "IRI points to a local file path"
70-
invalid_iris = [
71-
"/path/to/my/file.txt"
72-
]
67+
invalid_iris = ["/path/to/my/file.txt"]
7368
for value in invalid_iris:
7469
with pytest.raises(ValueError) as exc_info:
7570
iri = IRI(value)

pipeline/tests/test_regressions.py

+9-29
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_issue_0003():
4444
"format": {
4545
"@type": "https://openminds.om-i.org/types/ContentType",
4646
"name": "application/zip",
47-
},
47+
},
4848
"sourceData": [
4949
{
5050
"@type": "https://openminds.om-i.org/types/File",
@@ -98,15 +98,11 @@ def test_issue0007():
9898
"affiliation": [
9999
{
100100
"@type": "https://openminds.om-i.org/types/Affiliation",
101-
"memberOf": {
102-
"@id": "_:002"
103-
},
101+
"memberOf": {"@id": "_:002"},
104102
},
105103
{
106104
"@type": "https://openminds.om-i.org/types/Affiliation",
107-
"memberOf": {
108-
"@id": "_:003"
109-
},
105+
"memberOf": {"@id": "_:003"},
110106
},
111107
],
112108
}
@@ -128,15 +124,11 @@ def test_issue0007():
128124
"affiliation": [
129125
{
130126
"@type": "https://openminds.om-i.org/types/Affiliation",
131-
"memberOf": {
132-
"@id": "_:002"
133-
},
127+
"memberOf": {"@id": "_:002"},
134128
},
135129
{
136130
"@type": "https://openminds.om-i.org/types/Affiliation",
137-
"memberOf": {
138-
"@id": "_:003"
139-
},
131+
"memberOf": {"@id": "_:003"},
140132
},
141133
],
142134
"familyName": "Professor",
@@ -178,9 +170,7 @@ def test_issue0008():
178170
{
179171
"@type": "https://openminds.om-i.org/types/Affiliation",
180172
"endDate": "2023-09-30",
181-
"memberOf": {
182-
"@id": "_:001"
183-
},
173+
"memberOf": {"@id": "_:001"},
184174
}
185175
],
186176
"familyName": "Professor",
@@ -196,10 +186,7 @@ def test_issue0026():
196186

197187
uni1 = omcore.Organization(full_name="University of This Place", id="_:uthisp")
198188
person = omcore.Person(
199-
given_name="A",
200-
family_name="Professor",
201-
affiliations = [omcore.Affiliation(member_of=uni1)],
202-
id="_:ap"
189+
given_name="A", family_name="Professor", affiliations=[omcore.Affiliation(member_of=uni1)], id="_:ap"
203190
)
204191

205192
c = Collection(person)
@@ -224,16 +211,9 @@ def test_issue0023():
224211

225212
uni1 = omcore.Organization(full_name="University of This Place", id="_:uthisp")
226213
person = omcore.Person(
227-
given_name="A",
228-
family_name="Professor",
229-
affiliations = [omcore.Affiliation(member_of=uni1)],
230-
id="_:ap"
231-
)
232-
dv = omcore.DatasetVersion(
233-
full_name="The name of the dataset version",
234-
custodians=[person],
235-
id="_:dv"
214+
given_name="A", family_name="Professor", affiliations=[omcore.Affiliation(member_of=uni1)], id="_:ap"
236215
)
216+
dv = omcore.DatasetVersion(full_name="The name of the dataset version", custodians=[person], id="_:dv")
237217

238218
c = Collection(dv)
239219

0 commit comments

Comments
 (0)