Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #848

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-json
- id: check-yaml
Expand All @@ -11,13 +11,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort
args: [--profile, black, --filter-files, --line-length, "79"]

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.4.2
hooks:
- id: black
args: [--line-length, "79"]
2 changes: 1 addition & 1 deletion examples/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
}}
"""
)(citizen=OntologyIndividual, age=int)
for (citizen, age) in result:
for citizen, age in result:
print(citizen.name, age)

# Session contents can be exported to RDF,
Expand Down
8 changes: 5 additions & 3 deletions examples/terminological_knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@
print(" - restriction type", restriction.rtype)
print(
" - affected predicate",
restriction.attribute
if restriction.rtype == RESTRICTION_TYPE.ATTRIBUTE_RESTRICTION
else restriction.relationship,
(
restriction.attribute
if restriction.rtype == RESTRICTION_TYPE.ATTRIBUTE_RESTRICTION
else restriction.relationship
),
)
print("\n`Integer` ontology class object from the `emmo` namespace")
composition = tuple(
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/interfaces/dataspace/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The data space store connects SimPhoNy to a data space."""

import os
import pathlib
from base64 import b64encode
Expand Down
14 changes: 9 additions & 5 deletions simphony_osp/interfaces/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Universal interface for wrapper developers."""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -974,12 +975,15 @@ def __call__(self, subject: Node):
if s not in added_subjects and s in tracker.existing_subjects:
deleted_subjects[s] = deleted_subjects.get(s, 0) + 1
deleted_subjects = {
s: True
if count
>= sum(
1 for _ in self.interface.old_graph.triples((s, None, None))
s: (
True
if count
>= sum(
1
for _ in self.interface.old_graph.triples((s, None, None))
)
else False
)
else False
for s, count in deleted_subjects.items()
}
deleted_subjects = {
Expand Down
6 changes: 3 additions & 3 deletions simphony_osp/interfaces/remote/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def __init__(
)
self._interfaces: Dict[UUID, Interface] = dict()
self._directories: Dict[UUID, tempfile.TemporaryDirectory] = dict()
self._interface_generator: Callable[
[str, str], Interface
] = generate_interface
self._interface_generator: Callable[[str, str], Interface] = (
generate_interface
)

def listen(self) -> None:
"""Listen for connections from clients."""
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/namespaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""You can import the installed namespaces from this module."""

from __future__ import annotations

import logging as _logging
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/annotation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An annotation property defined in the ontology."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/attribute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An attribute defined in the ontology."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/composition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This files defines composition of classes."""

from __future__ import annotations

import logging
Expand Down
9 changes: 6 additions & 3 deletions simphony_osp/ontology/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Abstract superclass of any entity in the ontology."""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -348,9 +349,11 @@ def __repr__(self) -> str:
"""Transform the entity into a string."""
header = f"{self.__class__.__name__}"
elements = [
f"{self.label}"
if hasattr(self, "label") and self.label is not None
else None,
(
f"{self.label}"
if hasattr(self, "label") and self.label is not None
else None
),
f"{self.uid}",
]
elements = filter(lambda x: x is not None, elements)
Expand Down
27 changes: 15 additions & 12 deletions simphony_osp/ontology/individual.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An ontology individual."""

from __future__ import annotations

import functools
Expand Down Expand Up @@ -391,11 +392,13 @@ def __iter__(self) -> Iterator[OntologyIndividual]:

if self._uid_filter:
yield from (
self._individual.session.from_identifier_typed(
identifier, typing=OntologyIndividual
(
self._individual.session.from_identifier_typed(
identifier, typing=OntologyIndividual
)
if identifier in connected
else None
)
if identifier in connected
else None
for identifier in identifiers
)
else:
Expand Down Expand Up @@ -1518,7 +1521,7 @@ def get(
)
else:
result = []
for (i, r, t) in relationship_set.iter_low_level():
for i, r, t in relationship_set.iter_low_level():
if not t:
continue
session = self.session
Expand Down Expand Up @@ -1650,16 +1653,16 @@ def iter(
iterator = iter(relationship_set)
else:

def iterator() -> Iterator[
Tuple[OntologyIndividual, OntologyRelationship]
]:
def iterator() -> (
Iterator[Tuple[OntologyIndividual, OntologyRelationship]]
):
"""Helper iterator.
The purpose of defining this iterator is to be able to
return it, instead of using the `yield` keyword on the main
function, as described on the comment above.
"""
for (i, r, t) in relationship_set.iter_low_level():
for i, r, t in relationship_set.iter_low_level():
if not t:
continue
session = self.session
Expand Down Expand Up @@ -2242,9 +2245,9 @@ def relationships_iter(
Iterator with the queried ontology individuals.
"""

def individuals_and_relationships() -> Iterator[
OntologyIndividual, OntologyEntity
]:
def individuals_and_relationships() -> (
Iterator[OntologyIndividual, OntologyEntity]
):
for s, p, o in self.session.graph.triples(
(
self.identifier,
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/namespace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An ontology namespace."""

from __future__ import annotations

import itertools
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/oclass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A class defined in the ontology."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/operations/container.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Special kind of ontology individual designed to organize entities."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/operations/file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Special kind of ontology individual designed to organize entities."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/operations/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
individual has an associated instance of the subclass of `Operations` that the
wrapper or package developer has defined.
"""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Also contains a `Parser` class for backwards compatibility.
"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/relationship.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A relationship defined in the ontology."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/ontology/restriction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Restrictions on ontology classes."""

from __future__ import annotations

import logging
Expand Down
18 changes: 8 additions & 10 deletions simphony_osp/ontology/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utility resources for the ontology module."""

from __future__ import annotations

import importlib
Expand Down Expand Up @@ -372,22 +373,19 @@ def recursive_iterator(class_):
else {subclass.rdf_type}
)
for rdf_type in rdf_types:
mapping_rdf_to_python_class[
rdf_type
] = mapping_rdf_to_python_class.get(rdf_type, set()) | {subclass}
mapping_rdf_to_python_class[rdf_type] = (
mapping_rdf_to_python_class.get(rdf_type, set()) | {subclass}
)
rdf_identifiers = (
subclass.rdf_identifier
if isinstance(subclass.rdf_identifier, set)
else {subclass.rdf_identifier}
)
for rdf_identifier in rdf_identifiers:
mapping_identifier_to_python_class[
rdf_identifier
] = mapping_identifier_to_python_class.get(
rdf_identifier, set()
) | {
subclass
}
mapping_identifier_to_python_class[rdf_identifier] = (
mapping_identifier_to_python_class.get(rdf_identifier, set())
| {subclass}
)
return mapping_rdf_to_python_class, mapping_identifier_to_python_class


Expand Down
1 change: 1 addition & 0 deletions simphony_osp/session/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Abstract Base Class for all Sessions."""

from __future__ import annotations

import itertools
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/tools/import_export.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tools for importing and exporting data."""

from __future__ import annotations

import io
Expand Down
32 changes: 20 additions & 12 deletions simphony_osp/tools/pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,19 @@ def _pp_individual_subelements(
"\0"
+ str(
sorted(
class_.label
if class_.label is not None
else class_.identifier
(
class_.label
if class_.label is not None
else class_.identifier
)
for class_ in x[0].classes
)[0]
),
f"\0{x[1].label}"
if x[1].label is not None
else f"{x[1].identifier}",
(
f"\0{x[1].label}"
if x[1].label is not None
else f"{x[1].identifier}"
),
f"\0{x[0].label}" if x[0].label is not None else f"{x[0].uid}",
),
)
Expand Down Expand Up @@ -241,19 +245,23 @@ def _pp_individual_values(cuds_object, indentation="\n "):
sorted_attributes = sorted(
cuds_object.attributes.items(),
key=lambda x: (
f"\0{x[0].label}"
if x[0].label is not None
else f"{x[0].identifier}",
(
f"\0{x[0].label}"
if x[0].label is not None
else f"{x[0].identifier}"
),
str(x[1]),
),
)
for attribute, value in sorted_attributes:
result.append(
"%s: %s"
% (
f"\0{attribute.label}"
if attribute.label is not None
else f"{attribute.identifier}",
(
f"\0{attribute.label}"
if attribute.label is not None
else f"{attribute.identifier}"
),
value if not len(value) == 1 else next(iter(value)),
)
)
Expand Down
1 change: 1 addition & 0 deletions simphony_osp/utils/datatypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains methods for datatype conversions."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Contains an abstract class that serves as a base for defining benchmarks."""

import time
from abc import ABC, abstractmethod
from typing import Union
Expand Down
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The public API methods are the methods that are available to the users,
and available in the user documentation.
"""

import io
import json
import os
Expand Down