From a1803bf5ec1e103979d6ee1836e02bf9d8cef5cf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 01:49:04 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v5.0.0) - [github.com/pycqa/isort: 5.10.1 → 5.13.2](https://github.com/pycqa/isort/compare/5.10.1...5.13.2) - [github.com/psf/black: 22.3.0 → 24.10.0](https://github.com/psf/black/compare/22.3.0...24.10.0) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b0b94e26..ed8f8cb5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: check-json - id: check-yaml @@ -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.10.0 hooks: - id: black args: [--line-length, "79"] From 90e532c815d5bc05b7efac1d2f24aa6f04414c43 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 01:49:19 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/sessions.py | 2 +- examples/terminological_knowledge.py | 8 +++-- .../interfaces/dataspace/interface.py | 1 + simphony_osp/interfaces/interface.py | 14 +++++--- simphony_osp/interfaces/remote/server.py | 6 ++-- simphony_osp/namespaces.py | 1 + simphony_osp/ontology/annotation.py | 1 + simphony_osp/ontology/attribute.py | 1 + simphony_osp/ontology/composition.py | 1 + simphony_osp/ontology/entity.py | 9 ++++-- simphony_osp/ontology/individual.py | 27 +++++++++------- simphony_osp/ontology/namespace.py | 1 + simphony_osp/ontology/oclass.py | 1 + simphony_osp/ontology/operations/container.py | 1 + simphony_osp/ontology/operations/file.py | 1 + .../ontology/operations/operations.py | 1 + simphony_osp/ontology/parser/parser.py | 1 + simphony_osp/ontology/relationship.py | 1 + simphony_osp/ontology/restriction.py | 1 + simphony_osp/ontology/utils.py | 18 +++++------ simphony_osp/session/session.py | 1 + simphony_osp/tools/import_export.py | 1 + simphony_osp/tools/pretty_print.py | 32 ++++++++++++------- simphony_osp/utils/datatypes.py | 1 + tests/benchmark.py | 1 + tests/test_api.py | 1 + 26 files changed, 85 insertions(+), 49 deletions(-) diff --git a/examples/sessions.py b/examples/sessions.py index 51808e24..65b7de13 100644 --- a/examples/sessions.py +++ b/examples/sessions.py @@ -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, diff --git a/examples/terminological_knowledge.py b/examples/terminological_knowledge.py index 61c23375..004fd7a4 100644 --- a/examples/terminological_knowledge.py +++ b/examples/terminological_knowledge.py @@ -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( diff --git a/simphony_osp/interfaces/dataspace/interface.py b/simphony_osp/interfaces/dataspace/interface.py index 4457d42b..a39770df 100644 --- a/simphony_osp/interfaces/dataspace/interface.py +++ b/simphony_osp/interfaces/dataspace/interface.py @@ -1,4 +1,5 @@ """The data space store connects SimPhoNy to a data space.""" + import os import pathlib from base64 import b64encode diff --git a/simphony_osp/interfaces/interface.py b/simphony_osp/interfaces/interface.py index 9d737630..7bf215f4 100644 --- a/simphony_osp/interfaces/interface.py +++ b/simphony_osp/interfaces/interface.py @@ -1,4 +1,5 @@ """Universal interface for wrapper developers.""" + from __future__ import annotations import logging @@ -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 = { diff --git a/simphony_osp/interfaces/remote/server.py b/simphony_osp/interfaces/remote/server.py index 1d7629ce..0eee84d2 100644 --- a/simphony_osp/interfaces/remote/server.py +++ b/simphony_osp/interfaces/remote/server.py @@ -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.""" diff --git a/simphony_osp/namespaces.py b/simphony_osp/namespaces.py index 8dae36ae..13eb4507 100644 --- a/simphony_osp/namespaces.py +++ b/simphony_osp/namespaces.py @@ -1,4 +1,5 @@ """You can import the installed namespaces from this module.""" + from __future__ import annotations import logging as _logging diff --git a/simphony_osp/ontology/annotation.py b/simphony_osp/ontology/annotation.py index c4304f6d..2b03aaa4 100644 --- a/simphony_osp/ontology/annotation.py +++ b/simphony_osp/ontology/annotation.py @@ -1,4 +1,5 @@ """An annotation property defined in the ontology.""" + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/attribute.py b/simphony_osp/ontology/attribute.py index e39e110a..aca78c5a 100644 --- a/simphony_osp/ontology/attribute.py +++ b/simphony_osp/ontology/attribute.py @@ -1,4 +1,5 @@ """An attribute defined in the ontology.""" + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/composition.py b/simphony_osp/ontology/composition.py index 473a38b1..518984db 100644 --- a/simphony_osp/ontology/composition.py +++ b/simphony_osp/ontology/composition.py @@ -1,4 +1,5 @@ """This files defines composition of classes.""" + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/entity.py b/simphony_osp/ontology/entity.py index c36e8ea3..fb85f53c 100644 --- a/simphony_osp/ontology/entity.py +++ b/simphony_osp/ontology/entity.py @@ -1,4 +1,5 @@ """Abstract superclass of any entity in the ontology.""" + from __future__ import annotations import logging @@ -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) diff --git a/simphony_osp/ontology/individual.py b/simphony_osp/ontology/individual.py index 0afba601..eb045b45 100644 --- a/simphony_osp/ontology/individual.py +++ b/simphony_osp/ontology/individual.py @@ -1,4 +1,5 @@ """An ontology individual.""" + from __future__ import annotations import functools @@ -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: @@ -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 @@ -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 @@ -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, diff --git a/simphony_osp/ontology/namespace.py b/simphony_osp/ontology/namespace.py index baea1cb5..03168380 100644 --- a/simphony_osp/ontology/namespace.py +++ b/simphony_osp/ontology/namespace.py @@ -1,4 +1,5 @@ """An ontology namespace.""" + from __future__ import annotations import itertools diff --git a/simphony_osp/ontology/oclass.py b/simphony_osp/ontology/oclass.py index 99aaab93..90301aab 100644 --- a/simphony_osp/ontology/oclass.py +++ b/simphony_osp/ontology/oclass.py @@ -1,4 +1,5 @@ """A class defined in the ontology.""" + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/operations/container.py b/simphony_osp/ontology/operations/container.py index df15d0c6..23661da1 100644 --- a/simphony_osp/ontology/operations/container.py +++ b/simphony_osp/ontology/operations/container.py @@ -1,4 +1,5 @@ """Special kind of ontology individual designed to organize entities.""" + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/operations/file.py b/simphony_osp/ontology/operations/file.py index e828bfaa..f0a3926e 100644 --- a/simphony_osp/ontology/operations/file.py +++ b/simphony_osp/ontology/operations/file.py @@ -1,4 +1,5 @@ """Special kind of ontology individual designed to organize entities.""" + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/operations/operations.py b/simphony_osp/ontology/operations/operations.py index 5fb72492..de06bdcd 100644 --- a/simphony_osp/ontology/operations/operations.py +++ b/simphony_osp/ontology/operations/operations.py @@ -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 diff --git a/simphony_osp/ontology/parser/parser.py b/simphony_osp/ontology/parser/parser.py index 68b087b0..82466496 100644 --- a/simphony_osp/ontology/parser/parser.py +++ b/simphony_osp/ontology/parser/parser.py @@ -2,6 +2,7 @@ Also contains a `Parser` class for backwards compatibility. """ + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/relationship.py b/simphony_osp/ontology/relationship.py index aca7c29f..b5fd49ac 100644 --- a/simphony_osp/ontology/relationship.py +++ b/simphony_osp/ontology/relationship.py @@ -1,4 +1,5 @@ """A relationship defined in the ontology.""" + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/restriction.py b/simphony_osp/ontology/restriction.py index bbc28d4f..532491f7 100644 --- a/simphony_osp/ontology/restriction.py +++ b/simphony_osp/ontology/restriction.py @@ -1,4 +1,5 @@ """Restrictions on ontology classes.""" + from __future__ import annotations import logging diff --git a/simphony_osp/ontology/utils.py b/simphony_osp/ontology/utils.py index f78b9eb3..0a78a876 100644 --- a/simphony_osp/ontology/utils.py +++ b/simphony_osp/ontology/utils.py @@ -1,4 +1,5 @@ """Utility resources for the ontology module.""" + from __future__ import annotations import importlib @@ -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 diff --git a/simphony_osp/session/session.py b/simphony_osp/session/session.py index f8b9d019..73277a11 100644 --- a/simphony_osp/session/session.py +++ b/simphony_osp/session/session.py @@ -1,4 +1,5 @@ """Abstract Base Class for all Sessions.""" + from __future__ import annotations import itertools diff --git a/simphony_osp/tools/import_export.py b/simphony_osp/tools/import_export.py index c97a0389..7d4264fe 100644 --- a/simphony_osp/tools/import_export.py +++ b/simphony_osp/tools/import_export.py @@ -1,4 +1,5 @@ """Tools for importing and exporting data.""" + from __future__ import annotations import io diff --git a/simphony_osp/tools/pretty_print.py b/simphony_osp/tools/pretty_print.py index 2cb659a1..209c6617 100644 --- a/simphony_osp/tools/pretty_print.py +++ b/simphony_osp/tools/pretty_print.py @@ -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}", ), ) @@ -241,9 +245,11 @@ 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]), ), ) @@ -251,9 +257,11 @@ def _pp_individual_values(cuds_object, indentation="\n "): 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)), ) ) diff --git a/simphony_osp/utils/datatypes.py b/simphony_osp/utils/datatypes.py index 452e2200..9dd1736a 100644 --- a/simphony_osp/utils/datatypes.py +++ b/simphony_osp/utils/datatypes.py @@ -1,4 +1,5 @@ """This module contains methods for datatype conversions.""" + from __future__ import annotations import logging diff --git a/tests/benchmark.py b/tests/benchmark.py index d9cd2a0d..69e96caa 100644 --- a/tests/benchmark.py +++ b/tests/benchmark.py @@ -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 diff --git a/tests/test_api.py b/tests/test_api.py index 6b3aecd7..d50ab594 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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