diff --git a/cwlprov/prov.py b/cwlprov/prov.py index a1099f7..430c59e 100644 --- a/cwlprov/prov.py +++ b/cwlprov/prov.py @@ -55,12 +55,13 @@ ProvSpecialization, ProvStart, ProvUsage, - QualifiedNameCandidate, ) from .utils import first, prov_type if TYPE_CHECKING: + from prov.model import QualifiedNameCandidate + from .ro import ResearchObject CWLPROV = Namespace("cwlprov", "https://w3id.org/cwl/prov#") @@ -225,10 +226,10 @@ def __repr__(self) -> str: def __str__(self) -> str: return self.record.get_provn() - def _prov_attr(self, attr: QualifiedNameCandidate) -> Optional[QualifiedName]: + def _prov_attr(self, attr: "QualifiedNameCandidate") -> Optional[QualifiedName]: return first(self._prov_attrs(attr)) - def _prov_attrs(self, attr: QualifiedNameCandidate) -> set[QualifiedName]: + def _prov_attrs(self, attr: "QualifiedNameCandidate") -> set[QualifiedName]: return self.record.get_attribute(attr) diff --git a/mypy-stubs/prov/__init__.pyi b/mypy-stubs/prov/__init__.pyi index 64d4e8d..3f8d5df 100644 --- a/mypy-stubs/prov/__init__.pyi +++ b/mypy-stubs/prov/__init__.pyi @@ -1,13 +1,8 @@ -import os -from prov.model import ProvDocument - -__all__ = ["Error", "model", "read"] +from _typeshed import Incomplete class Error(Exception): ... -def read( - source: str | bytes | os.PathLike[str], format: str | None = None -) -> ProvDocument | None: ... +# def read(source, format: Incomplete | None = ...): ... # Names in __all__ with no definition: # model diff --git a/mypy-stubs/prov/constants.py b/mypy-stubs/prov/constants.py new file mode 100644 index 0000000..0e414b4 --- /dev/null +++ b/mypy-stubs/prov/constants.py @@ -0,0 +1,215 @@ +from prov.identifier import Namespace + +__author__ = "Trung Dong Huynh" +__email__ = "trungdong@donggiang.com" + + +XSD = Namespace("xsd", "http://www.w3.org/2001/XMLSchema#") +PROV = Namespace("prov", "http://www.w3.org/ns/prov#") +XSI = Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance") + +# C1. Entities/Activities +PROV_ENTITY = PROV["Entity"] +PROV_ACTIVITY = PROV["Activity"] +PROV_GENERATION = PROV["Generation"] +PROV_USAGE = PROV["Usage"] +PROV_COMMUNICATION = PROV["Communication"] +PROV_START = PROV["Start"] +PROV_END = PROV["End"] +PROV_INVALIDATION = PROV["Invalidation"] + +# C2. Derivations +PROV_DERIVATION = PROV["Derivation"] + +# C3. Agents/Responsibility +PROV_AGENT = PROV["Agent"] +PROV_ATTRIBUTION = PROV["Attribution"] +PROV_ASSOCIATION = PROV["Association"] +PROV_DELEGATION = PROV["Delegation"] +PROV_INFLUENCE = PROV["Influence"] +# C4. Bundles +PROV_BUNDLE = PROV["Bundle"] +# C5. Alternate +PROV_ALTERNATE = PROV["Alternate"] +PROV_SPECIALIZATION = PROV["Specialization"] +PROV_MENTION = PROV["Mention"] +# C6. Collections +PROV_MEMBERSHIP = PROV["Membership"] + +PROV_N_MAP = { + PROV_ENTITY: "entity", + PROV_ACTIVITY: "activity", + PROV_GENERATION: "wasGeneratedBy", + PROV_USAGE: "used", + PROV_COMMUNICATION: "wasInformedBy", + PROV_START: "wasStartedBy", + PROV_END: "wasEndedBy", + PROV_INVALIDATION: "wasInvalidatedBy", + PROV_DERIVATION: "wasDerivedFrom", + PROV_AGENT: "agent", + PROV_ATTRIBUTION: "wasAttributedTo", + PROV_ASSOCIATION: "wasAssociatedWith", + PROV_DELEGATION: "actedOnBehalfOf", + PROV_INFLUENCE: "wasInfluencedBy", + PROV_ALTERNATE: "alternateOf", + PROV_SPECIALIZATION: "specializationOf", + PROV_MENTION: "mentionOf", + PROV_MEMBERSHIP: "hadMember", + PROV_BUNDLE: "bundle", +} + +# Records defined as subtypes in PROV-N but top level types in for example +# PROV XML also need a mapping. +ADDITIONAL_N_MAP = { + PROV["Revision"]: "wasRevisionOf", + PROV["Quotation"]: "wasQuotedFrom", + PROV["PrimarySource"]: "hadPrimarySource", + PROV["SoftwareAgent"]: "softwareAgent", + PROV["Person"]: "person", + PROV["Organization"]: "organization", + PROV["Plan"]: "plan", + PROV["Collection"]: "collection", + PROV["EmptyCollection"]: "emptyCollection", +} + +# Maps qualified names from the PROV namespace to their base class. If it +# has no baseclass it maps to itsself. This is needed for example for PROV +# XML (de)serializer where extended types are used a lot. +PROV_BASE_CLS = { + PROV_ENTITY: PROV_ENTITY, + PROV_ACTIVITY: PROV_ACTIVITY, + PROV_GENERATION: PROV_GENERATION, + PROV_USAGE: PROV_USAGE, + PROV_COMMUNICATION: PROV_COMMUNICATION, + PROV_START: PROV_START, + PROV_END: PROV_END, + PROV_INVALIDATION: PROV_INVALIDATION, + PROV_DERIVATION: PROV_DERIVATION, + PROV["Revision"]: PROV_DERIVATION, + PROV["Quotation"]: PROV_DERIVATION, + PROV["PrimarySource"]: PROV_DERIVATION, + PROV_AGENT: PROV_AGENT, + PROV["SoftwareAgent"]: PROV_AGENT, + PROV["Person"]: PROV_AGENT, + PROV["Organization"]: PROV_AGENT, + PROV_ATTRIBUTION: PROV_ATTRIBUTION, + PROV_ASSOCIATION: PROV_ASSOCIATION, + PROV["Plan"]: PROV_ENTITY, + PROV_DELEGATION: PROV_DELEGATION, + PROV_INFLUENCE: PROV_INFLUENCE, + PROV_ALTERNATE: PROV_ALTERNATE, + PROV_SPECIALIZATION: PROV_SPECIALIZATION, + PROV_MENTION: PROV_MENTION, + PROV["Collection"]: PROV_ENTITY, + PROV["EmptyCollection"]: PROV_ENTITY, + PROV_MEMBERSHIP: PROV_MEMBERSHIP, + PROV_BUNDLE: PROV_ENTITY, +} + +# Identifiers for PROV's attributes +PROV_ATTR_ENTITY = PROV["entity"] +PROV_ATTR_ACTIVITY = PROV["activity"] +PROV_ATTR_TRIGGER = PROV["trigger"] +PROV_ATTR_INFORMED = PROV["informed"] +PROV_ATTR_INFORMANT = PROV["informant"] +PROV_ATTR_STARTER = PROV["starter"] +PROV_ATTR_ENDER = PROV["ender"] +PROV_ATTR_AGENT = PROV["agent"] +PROV_ATTR_PLAN = PROV["plan"] +PROV_ATTR_DELEGATE = PROV["delegate"] +PROV_ATTR_RESPONSIBLE = PROV["responsible"] +PROV_ATTR_GENERATED_ENTITY = PROV["generatedEntity"] +PROV_ATTR_USED_ENTITY = PROV["usedEntity"] +PROV_ATTR_GENERATION = PROV["generation"] +PROV_ATTR_USAGE = PROV["usage"] +PROV_ATTR_SPECIFIC_ENTITY = PROV["specificEntity"] +PROV_ATTR_GENERAL_ENTITY = PROV["generalEntity"] +PROV_ATTR_ALTERNATE1 = PROV["alternate1"] +PROV_ATTR_ALTERNATE2 = PROV["alternate2"] +PROV_ATTR_BUNDLE = PROV["bundle"] +PROV_ATTR_INFLUENCEE = PROV["influencee"] +PROV_ATTR_INFLUENCER = PROV["influencer"] +PROV_ATTR_COLLECTION = PROV["collection"] + +# Literal properties +PROV_ATTR_TIME = PROV["time"] +PROV_ATTR_STARTTIME = PROV["startTime"] +PROV_ATTR_ENDTIME = PROV["endTime"] + + +PROV_ATTRIBUTE_QNAMES = { + PROV_ATTR_ENTITY, + PROV_ATTR_ACTIVITY, + PROV_ATTR_TRIGGER, + PROV_ATTR_INFORMED, + PROV_ATTR_INFORMANT, + PROV_ATTR_STARTER, + PROV_ATTR_ENDER, + PROV_ATTR_AGENT, + PROV_ATTR_PLAN, + PROV_ATTR_DELEGATE, + PROV_ATTR_RESPONSIBLE, + PROV_ATTR_GENERATED_ENTITY, + PROV_ATTR_USED_ENTITY, + PROV_ATTR_GENERATION, + PROV_ATTR_USAGE, + PROV_ATTR_SPECIFIC_ENTITY, + PROV_ATTR_GENERAL_ENTITY, + PROV_ATTR_ALTERNATE1, + PROV_ATTR_ALTERNATE2, + PROV_ATTR_BUNDLE, + PROV_ATTR_INFLUENCEE, + PROV_ATTR_INFLUENCER, + PROV_ATTR_COLLECTION, +} +PROV_ATTRIBUTE_LITERALS = {PROV_ATTR_TIME, PROV_ATTR_STARTTIME, PROV_ATTR_ENDTIME} + +# Set of formal attributes of PROV records +PROV_ATTRIBUTES = PROV_ATTRIBUTE_QNAMES | PROV_ATTRIBUTE_LITERALS +PROV_RECORD_ATTRIBUTES = list((attr, str(attr)) for attr in PROV_ATTRIBUTES) + +PROV_RECORD_IDS_MAP = { + PROV_N_MAP[rec_type_id]: rec_type_id for rec_type_id in PROV_N_MAP +} +PROV_ID_ATTRIBUTES_MAP = { + prov_id: attribute for (prov_id, attribute) in PROV_RECORD_ATTRIBUTES +} +PROV_ATTRIBUTES_ID_MAP = { + attribute: prov_id for (prov_id, attribute) in PROV_RECORD_ATTRIBUTES +} + +# Extra definition for convenience +PROV_TYPE = PROV["type"] +PROV_LABEL = PROV["label"] +PROV_VALUE = PROV["value"] +PROV_LOCATION = PROV["location"] +PROV_ROLE = PROV["role"] + +PROV_QUALIFIEDNAME = PROV["QUALIFIED_NAME"] + +# XSD DATA TYPES +XSD_ANYURI = XSD["anyURI"] +XSD_QNAME = XSD["QName"] +XSD_DATETIME = XSD["dateTime"] +XSD_TIME = XSD["time"] +XSD_DATE = XSD["date"] +XSD_STRING = XSD["string"] +XSD_BOOLEAN = XSD["boolean"] +# All XSD Integer types +XSD_INTEGER = XSD["integer"] +XSD_LONG = XSD["long"] +XSD_INT = XSD["int"] +XSD_SHORT = XSD["short"] +XSD_BYTE = XSD["byte"] +XSD_NONNEGATIVEINTEGER = XSD["nonNegativeInteger"] +XSD_UNSIGNEDLONG = XSD["unsignedLong"] +XSD_UNSIGNEDINT = XSD["unsignedInt"] +XSD_UNSIGNEDSHORT = XSD["unsignedShort"] +XSD_UNSIGNEDBYTE = XSD["unsignedByte"] +XSD_POSITIVEINTEGER = XSD["positiveInteger"] +XSD_NONPOSITIVEINTEGER = XSD["nonPositiveInteger"] +XSD_NEGATIVEINTEGER = XSD["negativeInteger"] +# All XSD real number types +XSD_FLOAT = XSD["float"] +XSD_DOUBLE = XSD["double"] +XSD_DECIMAL = XSD["decimal"] diff --git a/mypy-stubs/prov/constants.pyi b/mypy-stubs/prov/constants.pyi deleted file mode 100644 index 33bb311..0000000 --- a/mypy-stubs/prov/constants.pyi +++ /dev/null @@ -1,91 +0,0 @@ -from _typeshed import Incomplete -from prov.identifier import Namespace as Namespace - -XSD: Incomplete -PROV: Incomplete -XSI: Incomplete -PROV_ENTITY: Incomplete -PROV_ACTIVITY: Incomplete -PROV_GENERATION: Incomplete -PROV_USAGE: Incomplete -PROV_COMMUNICATION: Incomplete -PROV_START: Incomplete -PROV_END: Incomplete -PROV_INVALIDATION: Incomplete -PROV_DERIVATION: Incomplete -PROV_AGENT: Incomplete -PROV_ATTRIBUTION: Incomplete -PROV_ASSOCIATION: Incomplete -PROV_DELEGATION: Incomplete -PROV_INFLUENCE: Incomplete -PROV_BUNDLE: Incomplete -PROV_ALTERNATE: Incomplete -PROV_SPECIALIZATION: Incomplete -PROV_MENTION: Incomplete -PROV_MEMBERSHIP: Incomplete -PROV_N_MAP: Incomplete -ADDITIONAL_N_MAP: Incomplete -PROV_BASE_CLS: Incomplete -PROV_ATTR_ENTITY: Incomplete -PROV_ATTR_ACTIVITY: Incomplete -PROV_ATTR_TRIGGER: Incomplete -PROV_ATTR_INFORMED: Incomplete -PROV_ATTR_INFORMANT: Incomplete -PROV_ATTR_STARTER: Incomplete -PROV_ATTR_ENDER: Incomplete -PROV_ATTR_AGENT: Incomplete -PROV_ATTR_PLAN: Incomplete -PROV_ATTR_DELEGATE: Incomplete -PROV_ATTR_RESPONSIBLE: Incomplete -PROV_ATTR_GENERATED_ENTITY: Incomplete -PROV_ATTR_USED_ENTITY: Incomplete -PROV_ATTR_GENERATION: Incomplete -PROV_ATTR_USAGE: Incomplete -PROV_ATTR_SPECIFIC_ENTITY: Incomplete -PROV_ATTR_GENERAL_ENTITY: Incomplete -PROV_ATTR_ALTERNATE1: Incomplete -PROV_ATTR_ALTERNATE2: Incomplete -PROV_ATTR_BUNDLE: Incomplete -PROV_ATTR_INFLUENCEE: Incomplete -PROV_ATTR_INFLUENCER: Incomplete -PROV_ATTR_COLLECTION: Incomplete -PROV_ATTR_TIME: Incomplete -PROV_ATTR_STARTTIME: Incomplete -PROV_ATTR_ENDTIME: Incomplete -PROV_ATTRIBUTE_QNAMES: Incomplete -PROV_ATTRIBUTE_LITERALS: Incomplete -PROV_ATTRIBUTES = PROV_ATTRIBUTE_QNAMES | PROV_ATTRIBUTE_LITERALS -PROV_RECORD_ATTRIBUTES: Incomplete -PROV_RECORD_IDS_MAP: Incomplete -PROV_ID_ATTRIBUTES_MAP: Incomplete -PROV_ATTRIBUTES_ID_MAP: Incomplete -PROV_TYPE: Incomplete -PROV_LABEL: Incomplete -PROV_VALUE: Incomplete -PROV_LOCATION: Incomplete -PROV_ROLE: Incomplete -PROV_QUALIFIEDNAME: Incomplete -PROV_INTERNATIONALIZEDSTRING: Incomplete -XSD_ANYURI: Incomplete -XSD_QNAME: Incomplete -XSD_DATETIME: Incomplete -XSD_TIME: Incomplete -XSD_DATE: Incomplete -XSD_STRING: Incomplete -XSD_BOOLEAN: Incomplete -XSD_INTEGER: Incomplete -XSD_LONG: Incomplete -XSD_INT: Incomplete -XSD_SHORT: Incomplete -XSD_BYTE: Incomplete -XSD_NONNEGATIVEINTEGER: Incomplete -XSD_UNSIGNEDLONG: Incomplete -XSD_UNSIGNEDINT: Incomplete -XSD_UNSIGNEDSHORT: Incomplete -XSD_UNSIGNEDBYTE: Incomplete -XSD_POSITIVEINTEGER: Incomplete -XSD_NONPOSITIVEINTEGER: Incomplete -XSD_NEGATIVEINTEGER: Incomplete -XSD_FLOAT: Incomplete -XSD_DOUBLE: Incomplete -XSD_DECIMAL: Incomplete diff --git a/mypy-stubs/prov/dot.pyi b/mypy-stubs/prov/dot.pyi index 38be3a2..02b896e 100644 --- a/mypy-stubs/prov/dot.pyi +++ b/mypy-stubs/prov/dot.pyi @@ -1,41 +1,28 @@ -import pydot from _typeshed import Incomplete -from prov.graph import INFERRED_ELEMENT_CLASS as INFERRED_ELEMENT_CLASS -from prov.identifier import QualifiedName as QualifiedName -from prov.model import ( - Identifier as Identifier, - PROV_ACTIVITY as PROV_ACTIVITY, - PROV_AGENT as PROV_AGENT, - PROV_ALTERNATE as PROV_ALTERNATE, - PROV_ASSOCIATION as PROV_ASSOCIATION, - PROV_ATTRIBUTE_QNAMES as PROV_ATTRIBUTE_QNAMES, - PROV_ATTRIBUTION as PROV_ATTRIBUTION, - PROV_BUNDLE as PROV_BUNDLE, - PROV_COMMUNICATION as PROV_COMMUNICATION, - PROV_DELEGATION as PROV_DELEGATION, - PROV_DERIVATION as PROV_DERIVATION, - PROV_END as PROV_END, - PROV_ENTITY as PROV_ENTITY, - PROV_GENERATION as PROV_GENERATION, - PROV_INFLUENCE as PROV_INFLUENCE, - PROV_INVALIDATION as PROV_INVALIDATION, - PROV_MEMBERSHIP as PROV_MEMBERSHIP, - PROV_MENTION as PROV_MENTION, - PROV_SPECIALIZATION as PROV_SPECIALIZATION, - PROV_START as PROV_START, - PROV_USAGE as PROV_USAGE, - ProvActivity as ProvActivity, - ProvAgent as ProvAgent, - ProvBundle as ProvBundle, - ProvElement as ProvElement, - ProvEntity as ProvEntity, - ProvException as ProvException, - ProvRecord as ProvRecord, - sorted_attributes as sorted_attributes, -) -from typing import Any +from prov.model import PROV_ACTIVITY as PROV_ACTIVITY +from prov.model import PROV_AGENT as PROV_AGENT +from prov.model import PROV_ALTERNATE as PROV_ALTERNATE +from prov.model import PROV_ASSOCIATION as PROV_ASSOCIATION +from prov.model import PROV_ATTRIBUTE_QNAMES as PROV_ATTRIBUTE_QNAMES +from prov.model import PROV_ATTRIBUTION as PROV_ATTRIBUTION +from prov.model import PROV_BUNDLE as PROV_BUNDLE +from prov.model import PROV_COMMUNICATION as PROV_COMMUNICATION +from prov.model import PROV_DELEGATION as PROV_DELEGATION +from prov.model import PROV_DERIVATION as PROV_DERIVATION +from prov.model import PROV_END as PROV_END +from prov.model import PROV_ENTITY as PROV_ENTITY +from prov.model import PROV_GENERATION as PROV_GENERATION +from prov.model import PROV_INFLUENCE as PROV_INFLUENCE +from prov.model import PROV_INVALIDATION as PROV_INVALIDATION +from prov.model import PROV_MEMBERSHIP as PROV_MEMBERSHIP +from prov.model import PROV_MENTION as PROV_MENTION +from prov.model import PROV_SPECIALIZATION as PROV_SPECIALIZATION +from prov.model import PROV_START as PROV_START +from prov.model import PROV_USAGE as PROV_USAGE +from prov.model import Identifier as Identifier +from prov.model import ProvException as ProvException +from prov.model import sorted_attributes as sorted_attributes -GENERIC_NODE_STYLE: dict[type[ProvElement | ProvBundle] | None, dict[str, str]] DOT_PROV_STYLE: Incomplete ANNOTATION_STYLE: Incomplete ANNOTATION_LINK_STYLE: Incomplete @@ -43,12 +30,12 @@ ANNOTATION_START_ROW: str ANNOTATION_ROW_TEMPLATE: str ANNOTATION_END_ROW: str -def htlm_link_if_uri(value: Any) -> str: ... +def htlm_link_if_uri(value): ... def prov_to_dot( - bundle: ProvBundle, - show_nary: bool = True, - use_labels: bool = False, - direction: str = "BT", - show_element_attributes: bool = True, - show_relation_attributes: bool = True, -) -> pydot.Dot: ... + bundle, + show_nary: bool = ..., + use_labels: bool = ..., + direction: str = ..., + show_element_attributes: bool = ..., + show_relation_attributes: bool = ..., +): ... diff --git a/mypy-stubs/prov/graph.pyi b/mypy-stubs/prov/graph.pyi index ad43733..ad8a3c4 100644 --- a/mypy-stubs/prov/graph.pyi +++ b/mypy-stubs/prov/graph.pyi @@ -1,36 +1,28 @@ -import networkx as nx from _typeshed import Incomplete -from prov.model import ( - PROV_ATTR_ACTIVITY as PROV_ATTR_ACTIVITY, - PROV_ATTR_AGENT as PROV_ATTR_AGENT, - PROV_ATTR_ALTERNATE1 as PROV_ATTR_ALTERNATE1, - PROV_ATTR_ALTERNATE2 as PROV_ATTR_ALTERNATE2, - PROV_ATTR_BUNDLE as PROV_ATTR_BUNDLE, - PROV_ATTR_COLLECTION as PROV_ATTR_COLLECTION, - PROV_ATTR_DELEGATE as PROV_ATTR_DELEGATE, - PROV_ATTR_ENDER as PROV_ATTR_ENDER, - PROV_ATTR_ENTITY as PROV_ATTR_ENTITY, - PROV_ATTR_GENERAL_ENTITY as PROV_ATTR_GENERAL_ENTITY, - PROV_ATTR_GENERATED_ENTITY as PROV_ATTR_GENERATED_ENTITY, - PROV_ATTR_INFORMANT as PROV_ATTR_INFORMANT, - PROV_ATTR_INFORMED as PROV_ATTR_INFORMED, - PROV_ATTR_PLAN as PROV_ATTR_PLAN, - PROV_ATTR_RESPONSIBLE as PROV_ATTR_RESPONSIBLE, - PROV_ATTR_SPECIFIC_ENTITY as PROV_ATTR_SPECIFIC_ENTITY, - PROV_ATTR_STARTER as PROV_ATTR_STARTER, - PROV_ATTR_TRIGGER as PROV_ATTR_TRIGGER, - PROV_ATTR_USED_ENTITY as PROV_ATTR_USED_ENTITY, - ProvActivity as ProvActivity, - ProvAgent as ProvAgent, - ProvBundle as ProvBundle, - ProvDocument as ProvDocument, - ProvElement as ProvElement, - ProvEntity as ProvEntity, - ProvRecord as ProvRecord, - ProvRelation as ProvRelation, -) +from prov.model import PROV_ATTR_ACTIVITY as PROV_ATTR_ACTIVITY +from prov.model import PROV_ATTR_AGENT as PROV_ATTR_AGENT +from prov.model import PROV_ATTR_ALTERNATE1 as PROV_ATTR_ALTERNATE1 +from prov.model import PROV_ATTR_ALTERNATE2 as PROV_ATTR_ALTERNATE2 +from prov.model import PROV_ATTR_COLLECTION as PROV_ATTR_COLLECTION +from prov.model import PROV_ATTR_DELEGATE as PROV_ATTR_DELEGATE +from prov.model import PROV_ATTR_ENTITY as PROV_ATTR_ENTITY +from prov.model import PROV_ATTR_GENERAL_ENTITY as PROV_ATTR_GENERAL_ENTITY +from prov.model import PROV_ATTR_GENERATED_ENTITY as PROV_ATTR_GENERATED_ENTITY +from prov.model import PROV_ATTR_INFORMANT as PROV_ATTR_INFORMANT +from prov.model import PROV_ATTR_INFORMED as PROV_ATTR_INFORMED +from prov.model import PROV_ATTR_RESPONSIBLE as PROV_ATTR_RESPONSIBLE +from prov.model import PROV_ATTR_SPECIFIC_ENTITY as PROV_ATTR_SPECIFIC_ENTITY +from prov.model import PROV_ATTR_TRIGGER as PROV_ATTR_TRIGGER +from prov.model import PROV_ATTR_USED_ENTITY as PROV_ATTR_USED_ENTITY +from prov.model import ProvActivity as ProvActivity +from prov.model import ProvAgent as ProvAgent +from prov.model import ProvDocument as ProvDocument +from prov.model import ProvElement as ProvElement +from prov.model import ProvEntity as ProvEntity +from prov.model import ProvRecord as ProvRecord +from prov.model import ProvRelation as ProvRelation INFERRED_ELEMENT_CLASS: Incomplete -def prov_to_graph(prov_document: ProvDocument) -> nx.MultiDiGraph: ... -def graph_to_prov(g: nx.MultiDiGraph) -> ProvDocument: ... +def prov_to_graph(prov_document): ... +def graph_to_prov(g): ... diff --git a/mypy-stubs/prov/identifier.pyi b/mypy-stubs/prov/identifier.pyi index 7beebdc..c344128 100644 --- a/mypy-stubs/prov/identifier.pyi +++ b/mypy-stubs/prov/identifier.pyi @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, Union class Identifier: def __init__(self, uri: str) -> None: ... @@ -9,9 +9,9 @@ class Identifier: def provn_representation(self) -> str: ... class QualifiedName(Identifier): - def __init__(self, namespace: Namespace, localpart: str) -> None: ... + def __init__(self, namespace: str, localpart: str) -> None: ... @property - def namespace(self) -> Namespace: ... + def namespace(self) -> str: ... @property def localpart(self) -> str: ... def __hash__(self) -> int: ... @@ -23,8 +23,8 @@ class Namespace: def uri(self) -> str: ... @property def prefix(self) -> str: ... - def contains(self, identifier: Identifier) -> bool: ... - def qname(self, identifier: str | Identifier) -> QualifiedName | None: ... + def contains(self, identifier: Identifier | str) -> bool: ... + def qname(self, identifier: Identifier | str) -> QualifiedName: ... def __eq__(self, other: Any) -> bool: ... def __ne__(self, other: Any) -> bool: ... def __hash__(self) -> int: ... diff --git a/mypy-stubs/prov/model.pyi b/mypy-stubs/prov/model.pyi index 0ebf3c6..acc1dc7 100644 --- a/mypy-stubs/prov/model.pyi +++ b/mypy-stubs/prov/model.pyi @@ -1,114 +1,66 @@ -from prov.constants import * -import datetime import io -import typing -from _typeshed import Incomplete -from prov import Error as Error, serializers as serializers -from prov.identifier import ( - Identifier as Identifier, - Namespace as Namespace, - QualifiedName as QualifiedName, -) -from typing import Any, Callable, Iterable, Optional, Union -from typing_extensions import TypeAlias +from collections.abc import Iterable +from datetime import datetime import os +from typing import IO, Any, Dict, List, Set, Tuple, Union +from typing_extensions import TypeAlias + +from _typeshed import Incomplete +from prov.constants import * + +# from prov import Error as Error, serializers as serializers +from prov.identifier import Identifier, Namespace, QualifiedName QualifiedNameCandidate: TypeAlias = Union[QualifiedName, str, Identifier] -OptionalID: TypeAlias = Optional[QualifiedNameCandidate] -EntityRef: TypeAlias = Union["ProvEntity", QualifiedNameCandidate] -ActivityRef: TypeAlias = Union["ProvActivity", QualifiedNameCandidate] -AgentRef: TypeAlias = Union[ - "ProvAgent", "ProvEntity", "ProvActivity", QualifiedNameCandidate -] -GenrationRef: TypeAlias = Union["ProvGeneration", QualifiedNameCandidate] -UsageRef: TypeAlias = Union["ProvUsage", QualifiedNameCandidate] -RecordAttributesArg: TypeAlias = Union[ - dict[QualifiedNameCandidate, Any], Iterable[tuple[QualifiedNameCandidate, Any]] -] -NameValuePair: TypeAlias = tuple[QualifiedName, Any] -DatetimeOrStr: TypeAlias = Union[datetime.datetime, str] -NSCollection: TypeAlias = dict[str, str] | Iterable[Namespace] PathLike: TypeAlias = Union[str, bytes, os.PathLike[Any]] -def parse_xsd_datetime(value: str) -> datetime.datetime | None: ... -def parse_boolean(value: str) -> bool | None: ... - -DATATYPE_PARSERS = { - datetime.datetime: parse_xsd_datetime, -} -# Mappings for XSD datatypes to Python standard types -SupportedXSDParsedTypes: TypeAlias = ( - str | datetime.datetime | float | int | bool | Identifier | None -) -XSD_DATATYPE_PARSERS: dict[QualifiedName, Callable[[str], SupportedXSDParsedTypes]] - -def parse_xsd_types(value: str, datatype: QualifiedName) -> SupportedXSDParsedTypes: ... -def first(a_set: set[Any]) -> Any | None: ... -def encoding_provn_value( - value: str | datetime.datetime | float | bool | QualifiedName, -) -> str: ... - -class Literal: - def __init__( - self, - value: Any, - datatype: QualifiedName | None = None, - langtag: str | None = None, - ) -> None: ... - def __eq__(self, other: Any) -> bool: ... - def __ne__(self, other: Any) -> bool: ... - def __hash__(self) -> int: ... - @property - def value(self) -> str: ... - @property - def datatype(self) -> QualifiedName | None: ... - @property - def langtag(self) -> str | None: ... - def has_no_langtag(self) -> bool: ... - def provn_representation(self) -> str: ... +logger: Incomplete -class ProvException(Error): ... -class ProvWarning(Warning): ... +# def parse_xsd_datetime(value): ... -class ProvExceptionInvalidQualifiedName(ProvException): - qname: Incomplete - def __init__(self, qname: Any) -> None: ... +DATATYPE_PARSERS: Incomplete +XSD_DATATYPE_PARSERS: Incomplete -class ProvElementIdentifierRequired(ProvException): ... +# def first(a_set): ... + +_attributes_type = dict[str | Identifier, Any] | list[tuple[str | Identifier, Any]] class ProvRecord: - FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] + FORMAL_ATTRIBUTES: Incomplete def __init__( self, - bundle: ProvBundle, - identifier: QualifiedName | None, - attributes: RecordAttributesArg | None = None, + bundle: str, + identifier: Identifier | str, + attributes: dict[str, str] | None = ..., ) -> None: ... def __hash__(self) -> int: ... def copy(self) -> ProvRecord: ... - def get_type(self) -> QualifiedName: ... - def get_asserted_types(self) -> set[QualifiedName]: ... - def add_asserted_type(self, type_identifier: QualifiedName) -> None: ... + def get_type(self) -> str: ... + def get_asserted_types(self) -> set[str]: ... + def add_asserted_type(self, type_identifier: str | QualifiedName) -> None: ... def get_attribute( self, attr_name: QualifiedNameCandidate ) -> set[QualifiedName]: ... @property - def identifier(self) -> QualifiedName | None: ... + def identifier(self) -> Identifier: ... @property - def attributes(self) -> list[tuple[QualifiedName, Any]]: ... + def attributes(self) -> list[tuple[QualifiedName, Identifier]]: ... @property - def args(self) -> tuple[QualifiedName, ...]: ... + def args(self) -> tuple[str, ...]: ... @property - def formal_attributes(self) -> tuple[tuple[QualifiedName, Any], ...]: ... + def formal_attributes(self) -> tuple[tuple[str, str], ...]: ... @property - def extra_attributes(self) -> tuple[tuple[QualifiedName, Any], ...]: ... + def extra_attributes(self) -> tuple[tuple[str, str], ...]: ... @property - def bundle(self) -> ProvBundle: ... + def bundle(self) -> "ProvBundle": ... @property def label(self) -> str: ... @property - def value(self) -> Any: ... - def add_attributes(self, attributes: RecordAttributesArg) -> None: ... + def value(self) -> str: ... + def add_attributes( + self, + attributes: _attributes_type, + ) -> None: ... def __eq__(self, other: Any) -> bool: ... def get_provn(self) -> str: ... def is_element(self) -> bool: ... @@ -117,9 +69,9 @@ class ProvRecord: class ProvElement(ProvRecord): def __init__( self, - bundle: ProvBundle, - identifier: QualifiedName | None, - attributes: RecordAttributesArg | None = None, + bundle: "ProvBundle", + identifier: str, + attributes: _attributes_type, ) -> None: ... def is_element(self) -> bool: ... @@ -129,68 +81,70 @@ class ProvRelation(ProvRecord): class ProvEntity(ProvElement): def wasGeneratedBy( self, - activity: ActivityRef | None = None, - time: DatetimeOrStr | None = None, - attributes: RecordAttributesArg | None = None, - ) -> ProvEntity: ... + activity: str, + time: datetime | str | None = ..., + attributes: _attributes_type | None = None, + ) -> ProvGeneration: ... def wasInvalidatedBy( self, - activity: ActivityRef | None, - time: DatetimeOrStr | None = None, - attributes: RecordAttributesArg | None = None, - ) -> ProvEntity: ... + activity: str, + time: datetime | str | None = ..., + attributes: _attributes_type | None = None, + ) -> ProvInvalidation: ... def wasDerivedFrom( self, - usedEntity: EntityRef, - activity: ActivityRef | None = None, - generation: GenrationRef | None = None, - usage: UsageRef | None = None, - attributes: RecordAttributesArg | None = None, - ) -> ProvEntity: ... + usedEntity: str, + activity: str | None = ..., + generation: Incomplete | None = ..., + usage: Incomplete | None = ..., + attributes: _attributes_type | None = None, + ) -> ProvDerivation: ... def wasAttributedTo( - self, agent: AgentRef, attributes: RecordAttributesArg | None = None - ) -> ProvEntity: ... - def alternateOf(self, alternate2: EntityRef) -> ProvEntity: ... - def specializationOf(self, generalEntity: EntityRef) -> ProvEntity: ... - def hadMember(self, entity: EntityRef) -> ProvEntity: ... + self, + agent: str, + attributes: _attributes_type | None = None, + ) -> ProvAttribution: ... + def alternateOf(self, alternate2: str) -> ProvElement: ... + def specializationOf(self, generalEntity: str) -> ProvSpecialization: ... + def hadMember(self, entity: str) -> ProvMembership: ... class ProvActivity(ProvElement): FORMAL_ATTRIBUTES: Incomplete def set_time( - self, - startTime: datetime.datetime | None = None, - endTime: datetime.datetime | None = None, + self, startTime: Incomplete | None = ..., endTime: Incomplete | None = ... ) -> None: ... - def get_startTime(self) -> datetime.datetime | None: ... - def get_endTime(self) -> datetime.datetime | None: ... + def get_startTime(self) -> datetime: ... + def get_endTime(self) -> datetime: ... def used( self, - entity: EntityRef, - time: DatetimeOrStr | None = None, - attributes: RecordAttributesArg | None = None, + entity: str, + time: datetime | str | None = ..., + attributes: _attributes_type | None = None, ) -> ProvActivity: ... def wasInformedBy( - self, informant: ActivityRef, attributes: RecordAttributesArg | None = None + self, + informant: str, + attributes: _attributes_type | None = None, ) -> ProvActivity: ... def wasStartedBy( self, - trigger: EntityRef | None, - starter: ActivityRef | None = None, - time: DatetimeOrStr | None = None, - attributes: RecordAttributesArg | None = None, + trigger: str, + starter: str | None = ..., + time: datetime | str | None = ..., + attributes: _attributes_type | None = None, ) -> ProvActivity: ... def wasEndedBy( self, - trigger: EntityRef | None, - ender: ActivityRef | None = None, - time: DatetimeOrStr | None = None, - attributes: RecordAttributesArg | None = None, + trigger: str, + ender: str | None = ..., + time: datetime | str | None = ..., + attributes: _attributes_type | None = None, ) -> ProvActivity: ... def wasAssociatedWith( self, - agent: AgentRef, - plan: EntityRef | None = None, - attributes: RecordAttributesArg | None = None, + agent: str, + plan: str | None = ..., + attributes: _attributes_type | None = None, ) -> ProvActivity: ... class ProvGeneration(ProvRelation): @@ -217,9 +171,9 @@ class ProvDerivation(ProvRelation): class ProvAgent(ProvElement): def actedOnBehalfOf( self, - responsible: AgentRef, - activity: ActivityRef | None = None, - attributes: RecordAttributesArg | None = None, + responsible: str, + activity: str | None = ..., + attributes: _attributes_type | None = ..., ) -> ProvAgent: ... class ProvAttribution(ProvRelation): @@ -235,7 +189,7 @@ class ProvInfluence(ProvRelation): FORMAL_ATTRIBUTES: Incomplete class ProvSpecialization(ProvRelation): - FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] + FORMAL_ATTRIBUTES: Incomplete class ProvAlternate(ProvRelation): FORMAL_ATTRIBUTES: Incomplete @@ -249,32 +203,13 @@ class ProvMembership(ProvRelation): PROV_REC_CLS: Incomplete DEFAULT_NAMESPACES: Incomplete -class NamespaceManager(dict[str, Namespace]): - parent: NamespaceManager | None - def __init__( - self, - namespaces: NSCollection | None = None, - default: str | None = None, - parent: NamespaceManager | None = None, - ) -> None: ... - def get_namespace(self, uri: str) -> Namespace | None: ... - def get_registered_namespaces(self) -> Iterable[Namespace]: ... - def set_default_namespace(self, uri: str) -> None: ... - def get_default_namespace(self) -> Namespace | None: ... - def add_namespace(self, namespace: Namespace) -> Namespace: ... - def add_namespaces(self, namespaces: NSCollection) -> None: ... - def valid_qualified_name( - self, qname: QualifiedNameCandidate - ) -> QualifiedName | None: ... - def get_anonymous_identifier(self, local_prefix: str = "id") -> Identifier: ... - class ProvBundle: def __init__( self, - records: Iterable[ProvRecord] | None = None, - identifier: QualifiedName | None = None, - namespaces: NSCollection | None = None, - document: ProvDocument | None = None, + records: Iterable[ProvRecord] | None = ..., + identifier: str | None = ..., + namespaces: Iterable[Namespace] | None = ..., + document: ProvDocument | None = ..., ) -> None: ... @property def namespaces(self) -> set[Namespace]: ... @@ -283,204 +218,207 @@ class ProvBundle: @property def document(self) -> ProvDocument | None: ... @property - def identifier(self) -> QualifiedName | None: ... + def identifier(self) -> str | None | QualifiedName: ... @property def records(self) -> list[ProvRecord]: ... - def set_default_namespace(self, uri: str) -> None: ... - def get_default_namespace(self) -> Namespace | None: ... + def set_default_namespace(self, uri: Namespace) -> None: ... + def get_default_namespace(self) -> Namespace: ... def add_namespace( - self, namespace_or_prefix: Namespace | str, uri: str | None = None + self, namespace_or_prefix: Namespace | str, uri: str | None = ... ) -> Namespace: ... def get_registered_namespaces(self) -> Iterable[Namespace]: ... def valid_qualified_name( - self, identifier: QualifiedNameCandidate + self, identifier: QualifiedName | tuple[str, Identifier] ) -> QualifiedName | None: ... - def mandatory_valid_qname( - self, identifier: QualifiedNameCandidate - ) -> QualifiedName: ... def get_records( - self, class_or_type_or_tuple: type | tuple[type] | None = None - ) -> Iterable[ProvRecord]: ... - def get_record(self, identifier: QualifiedNameCandidate) -> list[ProvRecord]: ... + self, + class_or_type_or_tuple: ( + type + | type[int | str] + | tuple[type | type[int | str] | tuple[Any, ...], ...] + | None + ) = ..., + ) -> list[ProvRecord]: ... + def get_record(self, identifier: Identifier | None) -> list[ProvRecord] | None: ... def is_document(self) -> bool: ... def is_bundle(self) -> bool: ... def has_bundles(self) -> bool: ... @property def bundles(self) -> Iterable[ProvBundle]: ... - def get_provn(self, _indent_level: int = 0) -> str: ... - def __eq__(self, other: Any) -> bool: ... - def __ne__(self, other: Any) -> bool: ... - __hash__: Incomplete + def get_provn(self, _indent_level: int = ...) -> str: ... def unified(self) -> ProvBundle: ... def update(self, other: ProvBundle) -> None: ... def new_record( self, - record_type: QualifiedName, - identifier: OptionalID, - attributes: RecordAttributesArg | None = None, - other_attributes: RecordAttributesArg | None = None, + record_type: PROV_REC_CLS, + identifier: str, + attributes: _attributes_type | None = None, + other_attributes: _attributes_type | None = None, ) -> ProvRecord: ... def add_record(self, record: ProvRecord) -> ProvRecord: ... def entity( self, - identifier: QualifiedNameCandidate, - other_attributes: RecordAttributesArg | None = None, + identifier: str | QualifiedName, + other_attributes: _attributes_type | None = None, ) -> ProvEntity: ... def activity( self, - identifier: QualifiedNameCandidate, - startTime: DatetimeOrStr | None = None, - endTime: DatetimeOrStr | None = None, - other_attributes: RecordAttributesArg | None = None, + identifier: str | QualifiedName, + startTime: datetime | str | None = ..., + endTime: datetime | str | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvActivity: ... def generation( self, - entity: EntityRef, - activity: ActivityRef | None = None, - time: DatetimeOrStr | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, - ) -> ProvRecord: ... + entity: ProvEntity | str, + activity: ProvActivity | str | None = ..., + time: datetime | str | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, + ) -> ProvGeneration: ... def usage( self, - activity: ActivityRef, - entity: EntityRef | None = None, - time: DatetimeOrStr | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + activity: ProvActivity | str, + entity: ProvEntity | str | None = ..., + time: datetime | str | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvUsage: ... def start( self, - activity: ActivityRef, - trigger: EntityRef | None = None, - starter: ActivityRef | None = None, - time: DatetimeOrStr | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + activity: ProvActivity | ProvAgent | str, + trigger: ProvEntity | None = ..., + starter: ProvActivity | ProvAgent | str | None = ..., + time: datetime | str | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvStart: ... def end( self, - activity: ActivityRef, - trigger: EntityRef | None = None, - ender: ActivityRef | None = None, - time: DatetimeOrStr | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + activity: ProvActivity | str, + trigger: ProvEntity | None = ..., + ender: ProvActivity | str | None = ..., + time: datetime | str | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvEnd: ... def invalidation( self, - entity: EntityRef, - activity: ActivityRef | None = None, - time: DatetimeOrStr | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + entity: ProvEntity | str, + activity: ProvActivity | str | None = ..., + time: datetime | str | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvInvalidation: ... def communication( self, - informed: ActivityRef, - informant: ActivityRef, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + informed: ProvActivity | str, + informant: ProvActivity | str, + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvCommunication: ... def agent( self, - identifier: QualifiedNameCandidate, - other_attributes: RecordAttributesArg | None = None, + identifier: Identifier | str, + other_attributes: _attributes_type | None = None, ) -> ProvAgent: ... def attribution( self, - entity: EntityRef, - agent: AgentRef, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + entity: ProvEntity | str, + agent: ProvAgent | str, + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvAttribution: ... def association( self, - activity: ActivityRef, - agent: AgentRef | None = None, - plan: EntityRef | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + activity: ProvActivity | str, + agent: ProvAgent | str | None = ..., + plan: ProvEntity | str | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvAssociation: ... def delegation( self, - delegate: AgentRef, - responsible: AgentRef, - activity: ActivityRef | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + delegate: ProvAgent | str, + responsible: ProvAgent | str, + activity: ProvActivity | str | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvDelegation: ... def influence( self, - influencee: EntityRef | ActivityRef | AgentRef, - influencer: EntityRef | ActivityRef | AgentRef, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + influencee: ProvEntity | ProvActivity | ProvAgent | str, + influencer: ProvEntity | ProvActivity | ProvAgent | str, + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvInfluence: ... def derivation( self, - generatedEntity: EntityRef, - usedEntity: EntityRef, - activity: ActivityRef | None = None, - generation: GenrationRef | None = None, - usage: UsageRef | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, + generatedEntity: ProvEntity | str, + usedEntity: ProvEntity | str, + activity: ProvActivity | str | None = ..., + generation: ProvActivity | str | None = ..., + usage: Incomplete | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, ) -> ProvDerivation: ... def revision( self, - generatedEntity: EntityRef, - usedEntity: EntityRef, - activity: ActivityRef | None = None, - generation: GenrationRef | None = None, - usage: UsageRef | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, - ) -> ProvDerivation: ... + generatedEntity: ProvEntity | str, + usedEntity: ProvEntity | str, + activity: ProvActivity | str | None = ..., + generation: ProvActivity | str | None = ..., + usage: Incomplete | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, + ) -> ProvRecord: ... def quotation( self, - generatedEntity: EntityRef, - usedEntity: EntityRef, - activity: ActivityRef | None = None, - generation: GenrationRef | None = None, - usage: UsageRef | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, - ) -> ProvDerivation: ... + generatedEntity: ProvEntity | str, + usedEntity: ProvEntity | str, + activity: ProvActivity | str | None = ..., + generation: ProvActivity | str | None = ..., + usage: Incomplete | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, + ) -> ProvRecord: ... def primary_source( self, - generatedEntity: EntityRef, - usedEntity: EntityRef, - activity: ActivityRef | None = None, - generation: GenrationRef | None = None, - usage: UsageRef | None = None, - identifier: OptionalID = None, - other_attributes: RecordAttributesArg | None = None, - ) -> ProvDerivation: ... + generatedEntity: ProvEntity | str, + usedEntity: ProvEntity | str, + activity: ProvActivity | str | None = ..., + generation: ProvActivity | str | None = ..., + usage: Incomplete | None = ..., + identifier: Identifier | None = ..., + other_attributes: _attributes_type | None = None, + ) -> ProvRecord: ... def specialization( - self, specificEntity: EntityRef, generalEntity: EntityRef - ) -> ProvSpecialization: ... + self, specificEntity: ProvEntity | str, generalEntity: ProvEntity | str + ) -> ProvRecord: ... def alternate( - self, alternate1: EntityRef, alternate2: EntityRef - ) -> ProvAlternate: ... + self, alternate1: ProvEntity | str, alternate2: ProvEntity | str + ) -> ProvRecord: ... def mention( - self, specificEntity: EntityRef, generalEntity: EntityRef, bundle: EntityRef - ) -> ProvMention: ... + self, + specificEntity: ProvEntity | str, + generalEntity: ProvEntity | str, + bundle: Incomplete, + ) -> ProvRecord: ... def collection( self, - identifier: QualifiedNameCandidate, - other_attributes: RecordAttributesArg | None = None, - ) -> ProvEntity: ... + identifier: str, + other_attributes: _attributes_type | None, + ) -> ProvRecord: ... def membership( - self, collection: EntityRef, entity: EntityRef - ) -> ProvMembership: ... + self, collection: ProvRecord, entity: ProvEntity | str + ) -> ProvRecord: ... def plot( self, - filename: PathLike | None = None, - show_nary: bool = True, - use_labels: bool = False, - show_element_attributes: bool = True, - show_relation_attributes: bool = True, + filename: str | None = ..., + show_nary: bool = ..., + use_labels: bool = ..., + show_element_attributes: bool = ..., + show_relation_attributes: bool = ..., ) -> None: ... wasGeneratedBy = generation used = usage @@ -504,10 +442,9 @@ class ProvBundle: class ProvDocument(ProvBundle): def __init__( self, - records: Iterable[ProvRecord] | None = None, - namespaces: NSCollection | None = None, + records: Iterable[ProvRecord] | None = ..., + namespaces: Iterable[Namespace] | None = ..., ) -> None: ... - def __eq__(self, other: Any) -> bool: ... def is_document(self) -> bool: ... def is_bundle(self) -> bool: ... def has_bundles(self) -> bool: ... @@ -515,25 +452,20 @@ class ProvDocument(ProvBundle): def bundles(self) -> Iterable[ProvBundle]: ... def flattened(self) -> ProvDocument: ... def unified(self) -> ProvDocument: ... - def update(self, other: ProvBundle) -> None: ... + def update(self, other: ProvDocument | ProvBundle) -> None: ... def add_bundle( - self, bundle: ProvBundle, identifier: QualifiedName | None = None + self, bundle: ProvBundle, identifier: Incomplete | None = ... ) -> None: ... - def bundle(self, identifier: QualifiedNameCandidate) -> ProvBundle: ... + def bundle(self, identifier: Identifier) -> ProvBundle: ... def serialize( - self, - destination: io.IOBase | PathLike | None = None, - format: str = "json", - **args: Any, + self, destination: IO[Any] | None = ..., format: str = ..., **args: Any ) -> str | None: ... @staticmethod def deserialize( source: io.IOBase | PathLike | None = None, - content: str | bytes | None = None, - format: str = "json", + content: str | None = ..., + format: str = ..., **args: Any, ) -> ProvDocument: ... -def sorted_attributes( - element: QualifiedName, attributes: Iterable[NameValuePair] -) -> list[NameValuePair]: ... +def sorted_attributes(element: ProvElement, attributes: list[str]) -> list[str]: ... diff --git a/mypy-stubs/prov/scripts/__init__.pyi b/mypy-stubs/prov/scripts/__init__.pyi deleted file mode 100644 index e69de29..0000000 diff --git a/mypy-stubs/prov/scripts/compare.pyi b/mypy-stubs/prov/scripts/compare.pyi deleted file mode 100644 index 4bef0e6..0000000 --- a/mypy-stubs/prov/scripts/compare.pyi +++ /dev/null @@ -1,16 +0,0 @@ -from _typeshed import Incomplete -from prov.model import ProvDocument as ProvDocument - -logger: Incomplete -__version__: float -__date__: str -__updated__: str -DEBUG: int -TESTRUN: int -PROFILE: int - -class CLIError(Exception): - msg: Incomplete - def __init__(self, msg: str) -> None: ... - -def main(argv: list | None = None) -> int: ... diff --git a/mypy-stubs/prov/scripts/convert.pyi b/mypy-stubs/prov/scripts/convert.pyi deleted file mode 100644 index e0a74cb..0000000 --- a/mypy-stubs/prov/scripts/convert.pyi +++ /dev/null @@ -1,20 +0,0 @@ -import io -from _typeshed import Incomplete -from prov import serializers as serializers -from prov.model import ProvDocument as ProvDocument - -logger: Incomplete -__version__: float -__date__: str -__updated__: str -DEBUG: int -TESTRUN: int -PROFILE: int -GRAPHVIZ_SUPPORTED_FORMATS: Incomplete - -class CLIError(Exception): - msg: Incomplete - def __init__(self, msg: str) -> None: ... - -def convert_file(infile: io.FileIO, outfile: io.FileIO, output_format: str) -> None: ... -def main(argv: list | None = None) -> int: ... diff --git a/mypy-stubs/prov/serializers/__init__.pyi b/mypy-stubs/prov/serializers/__init__.pyi deleted file mode 100644 index 5745739..0000000 --- a/mypy-stubs/prov/serializers/__init__.pyi +++ /dev/null @@ -1,26 +0,0 @@ -import abc -import io -from _typeshed import Incomplete -from abc import ABC, abstractmethod -from prov import Error -from prov.model import ProvDocument -from typing import Any - -__all__ = ["get", "Registry", "Serializer"] - -class Serializer(ABC, metaclass=abc.ABCMeta): - document: Incomplete - def __init__(self, document: ProvDocument | None = None) -> None: ... - @abstractmethod - def serialize(self, stream: io.IOBase, **args: Any) -> None: ... - @abstractmethod - def deserialize(self, stream: io.IOBase, **args: Any) -> ProvDocument: ... - -class DoNotExist(Error): ... - -class Registry: - serializers: dict[str, type[Serializer]] - @staticmethod - def load_serializers() -> None: ... - -def get(format_name: str) -> type[Serializer]: ... diff --git a/mypy-stubs/prov/serializers/provjson.pyi b/mypy-stubs/prov/serializers/provjson.pyi index 7c5ff1b..723c2d4 100644 --- a/mypy-stubs/prov/serializers/provjson.pyi +++ b/mypy-stubs/prov/serializers/provjson.pyi @@ -1,51 +1,42 @@ -from prov.constants import * -import io import json + from _typeshed import Incomplete -from prov import Error as Error -from prov.model import ( - Identifier as Identifier, - Literal as Literal, - Namespace as Namespace, - ProvBundle as ProvBundle, - ProvDocument as ProvDocument, - ProvRecord as ProvRecord, - QualifiedName as QualifiedName, - QualifiedNameCandidate as QualifiedNameCandidate, - first as first, - parse_xsd_datetime as parse_xsd_datetime, -) +from prov.constants import * +from prov.model import Identifier as Identifier +from prov.model import Literal as Literal +from prov.model import Namespace as Namespace +from prov.model import ProvBundle as ProvBundle +from prov.model import ProvDocument as ProvDocument +from prov.model import first as first +from prov.model import parse_xsd_datetime as parse_xsd_datetime +from prov.serializers import Error as Error from prov.serializers import Serializer as Serializer -from typing import Any logger: Incomplete -ProvJSONDict = dict[str, dict[str, Any]] class ProvJSONException(Error): ... class AnonymousIDGenerator: def __init__(self) -> None: ... - def get_anon_id(self, obj: ProvRecord, local_prefix: str = "id") -> Identifier: ... + def get_anon_id(self, obj, local_prefix: str = ...): ... LITERAL_XSDTYPE_MAP: Incomplete class ProvJSONSerializer(Serializer): - def serialize(self, stream: io.IOBase, **args: Any) -> None: ... - def deserialize(self, stream: io.IOBase, **args: Any) -> ProvDocument: ... + def serialize(self, stream, **kwargs) -> None: ... + def deserialize(self, stream, **kwargs): ... class ProvJSONEncoder(json.JSONEncoder): - def default(self, o: Any) -> Any: ... + def default(self, o): ... class ProvJSONDecoder(json.JSONDecoder): - def decode(self, s: str, *args: Any, **kwargs: Any) -> Any: ... - -def valid_qualified_name( - bundle: ProvBundle, value: QualifiedNameCandidate | None -) -> QualifiedName | None: ... -def encode_json_document(document: ProvDocument) -> ProvJSONDict: ... -def encode_json_container(bundle: ProvBundle) -> ProvJSONDict: ... -def decode_json_document(content: ProvJSONDict, document: ProvDocument) -> None: ... -def decode_json_container(jc: ProvJSONDict, bundle: ProvBundle) -> None: ... -def encode_json_representation(value: Any) -> Any: ... -def decode_json_representation(literal: Any, bundle: ProvBundle) -> Any: ... -def literal_json_representation(literal: Literal) -> dict[str, str]: ... + def decode(self, s, *args, **kwargs): ... + +def valid_qualified_name(bundle, value): ... +def encode_json_document(document): ... +def encode_json_container(bundle): ... +def decode_json_document(content, document) -> None: ... +def decode_json_container(jc, bundle) -> None: ... +def encode_json_representation(value): ... +def decode_json_representation(literal, bundle): ... +def literal_json_representation(literal): ... diff --git a/mypy-stubs/prov/serializers/provn.pyi b/mypy-stubs/prov/serializers/provn.pyi index d730561..fa6ac78 100644 --- a/mypy-stubs/prov/serializers/provn.pyi +++ b/mypy-stubs/prov/serializers/provn.pyi @@ -1,8 +1,8 @@ -import io -from prov.model import ProvDocument as ProvDocument +from _typeshed import Incomplete from prov.serializers import Serializer as Serializer -from typing import Any + +logger: Incomplete class ProvNSerializer(Serializer): - def serialize(self, stream: io.IOBase, **args: Any) -> None: ... - def deserialize(self, stream: io.IOBase, **args: Any) -> ProvDocument: ... + def serialize(self, stream, **kwargs) -> None: ... + def deserialize(self, stream, **kwargs) -> None: ... diff --git a/mypy-stubs/prov/serializers/provrdf.pyi b/mypy-stubs/prov/serializers/provrdf.pyi index 2d36317..11e438f 100644 --- a/mypy-stubs/prov/serializers/provrdf.pyi +++ b/mypy-stubs/prov/serializers/provrdf.pyi @@ -1,105 +1,67 @@ -import io -import prov.model as pm +from collections.abc import Generator + from _typeshed import Incomplete -from prov import Error as Error -from prov.constants import ( - PROV as PROV, - PROV_ACTIVITY as PROV_ACTIVITY, - PROV_ALTERNATE as PROV_ALTERNATE, - PROV_ASSOCIATION as PROV_ASSOCIATION, - PROV_ATTR_ENDER as PROV_ATTR_ENDER, - PROV_ATTR_ENDTIME as PROV_ATTR_ENDTIME, - PROV_ATTR_INFORMANT as PROV_ATTR_INFORMANT, - PROV_ATTR_RESPONSIBLE as PROV_ATTR_RESPONSIBLE, - PROV_ATTR_STARTER as PROV_ATTR_STARTER, - PROV_ATTR_STARTTIME as PROV_ATTR_STARTTIME, - PROV_ATTR_TIME as PROV_ATTR_TIME, - PROV_ATTR_TRIGGER as PROV_ATTR_TRIGGER, - PROV_ATTR_USED_ENTITY as PROV_ATTR_USED_ENTITY, - PROV_BASE_CLS as PROV_BASE_CLS, - PROV_COMMUNICATION as PROV_COMMUNICATION, - PROV_DELEGATION as PROV_DELEGATION, - PROV_DERIVATION as PROV_DERIVATION, - PROV_END as PROV_END, - PROV_GENERATION as PROV_GENERATION, - PROV_ID_ATTRIBUTES_MAP as PROV_ID_ATTRIBUTES_MAP, - PROV_INVALIDATION as PROV_INVALIDATION, - PROV_LOCATION as PROV_LOCATION, - PROV_MENTION as PROV_MENTION, - PROV_N_MAP as PROV_N_MAP, - PROV_ROLE as PROV_ROLE, - PROV_START as PROV_START, - PROV_USAGE as PROV_USAGE, - XSD_QNAME as XSD_QNAME, -) -from prov.identifier import QualifiedName as QualifiedName +from prov.constants import PROV as PROV +from prov.constants import PROV_ACTIVITY as PROV_ACTIVITY +from prov.constants import PROV_ALTERNATE as PROV_ALTERNATE +from prov.constants import PROV_ATTR_ENDER as PROV_ATTR_ENDER +from prov.constants import PROV_ATTR_ENDTIME as PROV_ATTR_ENDTIME +from prov.constants import PROV_ATTR_INFORMANT as PROV_ATTR_INFORMANT +from prov.constants import PROV_ATTR_RESPONSIBLE as PROV_ATTR_RESPONSIBLE +from prov.constants import PROV_ATTR_STARTER as PROV_ATTR_STARTER +from prov.constants import PROV_ATTR_STARTTIME as PROV_ATTR_STARTTIME +from prov.constants import PROV_ATTR_TIME as PROV_ATTR_TIME +from prov.constants import PROV_ATTR_TRIGGER as PROV_ATTR_TRIGGER +from prov.constants import PROV_ATTR_USED_ENTITY as PROV_ATTR_USED_ENTITY +from prov.constants import PROV_BASE_CLS as PROV_BASE_CLS +from prov.constants import PROV_COMMUNICATION as PROV_COMMUNICATION +from prov.constants import PROV_DELEGATION as PROV_DELEGATION +from prov.constants import PROV_DERIVATION as PROV_DERIVATION +from prov.constants import PROV_END as PROV_END +from prov.constants import PROV_GENERATION as PROV_GENERATION +from prov.constants import PROV_ID_ATTRIBUTES_MAP as PROV_ID_ATTRIBUTES_MAP +from prov.constants import PROV_INVALIDATION as PROV_INVALIDATION +from prov.constants import PROV_LOCATION as PROV_LOCATION +from prov.constants import PROV_MENTION as PROV_MENTION +from prov.constants import PROV_N_MAP as PROV_N_MAP +from prov.constants import PROV_ROLE as PROV_ROLE +from prov.constants import PROV_START as PROV_START +from prov.constants import PROV_USAGE as PROV_USAGE +from prov.constants import XSD_QNAME as XSD_QNAME +from prov.serializers import Error as Error from prov.serializers import Serializer as Serializer -from rdflib.graph import ConjunctiveGraph -from rdflib.term import Literal as RDFLiteral, URIRef -from typing import Any, Generator class ProvRDFException(Error): ... class AnonymousIDGenerator: def __init__(self) -> None: ... - def get_anon_id(self, obj: pm.ProvRecord, local_prefix: str = "id") -> str: ... + def get_anon_id(self, obj, local_prefix: str = ...): ... LITERAL_XSDTYPE_MAP: Incomplete -RELATION_MAP: Incomplete -PREDICATE_MAP: Incomplete -def attr2rdf(attr: QualifiedName) -> URIRef: ... +def attr2rdf(attr): ... +def valid_qualified_name(bundle, value, xsd_qname: bool = ...): ... class ProvRDFSerializer(Serializer): def serialize( - self, - stream: io.IOBase, - rdf_format: str = "trig", - PROV_N_MAP: dict[pm.QualifiedName, str] = ..., - **kwargs: Any, + self, stream: Incomplete | None = ..., rdf_format: str = ..., **kwargs ) -> None: ... document: Incomplete - def deserialize( - self, - stream: io.IOBase, - rdf_format: str = "trig", - relation_mapper: dict[URIRef, str] = ..., - predicate_mapper: dict[URIRef, pm.QualifiedName] = ..., - **kwargs: Any, - ) -> pm.ProvDocument: ... - def valid_identifier( - self, value: pm.QualifiedNameCandidate - ) -> pm.QualifiedName | None: ... - def encode_rdf_representation(self, value: Any) -> RDFLiteral | URIRef: ... - def decode_rdf_representation( - self, literal: Any, graph: ConjunctiveGraph - ) -> Any: ... - def encode_document( - self, document: pm.ProvDocument, PROV_N_MAP: dict[pm.QualifiedName, str] = ... - ) -> ConjunctiveGraph: ... + def deserialize(self, stream, rdf_format: str = ..., **kwargs): ... + def valid_identifier(self, value): ... + def encode_rdf_representation(self, value): ... + def decode_rdf_representation(self, literal, graph): ... + def encode_document(self, document): ... def encode_container( self, - bundle: pm.ProvBundle, - PROV_N_MAP: dict[pm.QualifiedName, str] = ..., - container: ConjunctiveGraph | None = None, - identifier: str | None = None, - ) -> ConjunctiveGraph: ... - def decode_document( - self, - content: ConjunctiveGraph, - document: pm.ProvDocument, - relation_mapper: dict[URIRef, str] = ..., - predicate_mapper: dict[URIRef, pm.QualifiedName] = ..., - ) -> None: ... - def decode_container( - self, - graph: ConjunctiveGraph, - bundle: pm.ProvBundle, - relation_mapper: dict[URIRef, str] = ..., - predicate_mapper: dict[URIRef, pm.QualifiedName] = ..., - ) -> None: ... + bundle, + container: Incomplete | None = ..., + identifier: Incomplete | None = ..., + ): ... + def decode_document(self, content, document) -> None: ... + def decode_container(self, graph, bundle) -> None: ... def walk( - children: list, level: int = 0, path: dict = None, usename: bool = True -) -> Generator[dict]: ... -def literal_rdf_representation(literal: pm.Literal) -> RDFLiteral: ... + children, level: int = ..., path: Incomplete | None = ..., usename: bool = ... +) -> Generator[Incomplete, None, None]: ... +def literal_rdf_representation(literal): ... diff --git a/mypy-stubs/prov/serializers/provxml.pyi b/mypy-stubs/prov/serializers/provxml.pyi index 0e9f545..693d7f4 100644 --- a/mypy-stubs/prov/serializers/provxml.pyi +++ b/mypy-stubs/prov/serializers/provxml.pyi @@ -1,14 +1,8 @@ -from prov.constants import * -import io -import prov +import prov.identifier from _typeshed import Incomplete -from lxml import etree -from prov.model import ( - DEFAULT_NAMESPACES as DEFAULT_NAMESPACES, - sorted_attributes as sorted_attributes, -) -from prov.serializers import Serializer as Serializer -from typing import Any +from prov.constants import * +from prov.model import DEFAULT_NAMESPACES as DEFAULT_NAMESPACES +from prov.model import sorted_attributes as sorted_attributes logger: Incomplete FULL_NAMES_MAP: Incomplete @@ -17,25 +11,12 @@ XML_XSD_URI: str class ProvXMLException(prov.Error): ... -class ProvXMLSerializer(Serializer): - def serialize( - self, stream: io.IOBase, force_types: bool = False, **kwargs: Any - ) -> None: ... +class ProvXMLSerializer(prov.serializers.Serializer): + def serialize(self, stream, force_types: bool = ..., **kwargs) -> None: ... def serialize_bundle( - self, - bundle: prov.model.ProvBundle, - element: etree._Element | None = None, - force_types: bool = False, - ) -> etree._Element: ... - def deserialize( - self, stream: io.IOBase, **kwargs: Any - ) -> prov.model.ProvDocument: ... - def deserialize_subtree( - self, - xml_doc: etree._Element, - bundle: prov.model.ProvDocument | prov.model.ProvBundle, - ) -> prov.model.ProvDocument | prov.model.ProvBundle: ... + self, bundle, element: Incomplete | None = ..., force_types: bool = ... + ): ... + def deserialize(self, stream, **kwargs): ... + def deserialize_subtree(self, xml_doc, bundle): ... -def xml_qname_to_QualifiedName( - element: etree._Element, qname_str: str -) -> prov.model.QualifiedName: ... +def xml_qname_to_QualifiedName(element, qname_str): ... diff --git a/pyproject.toml b/pyproject.toml index 3730355..fe965db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ classifiers = [ ] requires-python = ">=3.9, <4" dependencies = [ - "prov >= 1.5.1", + "prov == 1.5.1", "bdbag >= 1.4.1", "arcp >= 0.2.0", "rdflib >= 6, <8", diff --git a/requirements.txt b/requirements.txt index d1ac5d8..2439244 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -prov >= 1.5.1 +prov == 1.5.1 bdbag >= 1.4.1 arcp >= 0.2.0 rdflib >= 6, <8