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

⬆️ update black and ruff and 🎨 apply formatting #86

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🎨 apply ruff format
Signed-off-by: ff137 <[email protected]>
ff137 committed Mar 26, 2024
commit 0bfde31624f0f5b44d18bf5f252cc26590ea54ec
1 change: 1 addition & 0 deletions pydid/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common components."""

import re

DID_REGEX = "did:([a-z0-9]+):((?:[a-zA-Z0-9._%-]*:)*[a-zA-Z0-9._%-]+)"
1 change: 1 addition & 0 deletions pydid/did_url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""DID URL Object."""

from typing import Dict, Optional, TYPE_CHECKING
from urllib.parse import parse_qsl, urlencode, urlparse

22 changes: 9 additions & 13 deletions pydid/doc/builder.py
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ def __init__(
did: DID,
*,
id_base: str = None,
methods: Optional[List[VerificationMethod]] = None
methods: Optional[List[VerificationMethod]] = None,
):
"""Initialize builder."""
self._did = did
@@ -42,7 +42,7 @@ def add(
type_: Type[VerificationMethod],
ident: Optional[str] = None,
controller: DID = None,
**kwargs
**kwargs,
):
"""Add verification method from parts and context."""
ident = ident or next(self._id_generator)
@@ -64,7 +64,7 @@ def __init__(
did: DID,
id_base: str,
*,
methods: Optional[List[Union[VerificationMethod, DIDUrl]]] = None
methods: Optional[List[Union[VerificationMethod, DIDUrl]]] = None,
):
"""Initialize builder."""
super().__init__(did, id_base=id_base)
@@ -132,7 +132,7 @@ def add(
id=self._did.ref(ident),
type=type_,
service_endpoint=service_endpoint,
**extra
**extra,
)
self.services.append(service)
return service
@@ -146,7 +146,7 @@ def add_didcomm(
priority: Optional[int] = None,
type_: Optional[str] = None,
ident: Optional[str] = None,
accept: Optional[List[str]] = None
accept: Optional[List[str]] = None,
):
"""Add DIDComm Service."""
ident = ident or next(self._id_generator)
@@ -184,7 +184,7 @@ def __init__(
context: List[str] = None,
*,
also_known_as: List[str] = None,
controller: Union[List[str], List[DID]] = None
controller: Union[List[str], List[DID]] = None,
):
"""Initliaze builder."""
self.id: DID = DID(id)
@@ -195,12 +195,8 @@ def __init__(
self.authentication = RelationshipBuilder(self.id, "auth")
self.assertion_method = RelationshipBuilder(self.id, "assert")
self.key_agreement = RelationshipBuilder(self.id, "key-agreement")
self.capability_invocation = RelationshipBuilder(
self.id, "capability-invocation"
)
self.capability_delegation = RelationshipBuilder(
self.id, "capability-delegation"
)
self.capability_invocation = RelationshipBuilder(self.id, "capability-invocation")
self.capability_delegation = RelationshipBuilder(self.id, "capability-delegation")
self.service = ServiceBuilder(self.id)
self.extra = {}

@@ -252,5 +248,5 @@ def build(self) -> DIDDocument:
capability_invocation=self.capability_invocation.methods or None,
capability_delegation=self.capability_delegation.methods or None,
service=self.service.services or None,
**self.extra
**self.extra,
)
8 changes: 2 additions & 6 deletions pydid/doc/doc.py
Original file line number Diff line number Diff line change
@@ -32,9 +32,7 @@ class IDNotFoundError(DIDDocumentError):
class DIDDocumentRoot(Resource):
"""Representation of DID Document."""

context: Annotated[
List[Union[str, dict]], Field(alias="@context")
] = [ # noqa: F722
context: Annotated[List[Union[str, dict]], Field(alias="@context")] = [ # noqa: F722
"https://www.w3.org/ns/did/v1"
]
id: DID
@@ -100,9 +98,7 @@ def _indexer(item):
assert isinstance(item, (VerificationMethod, Service))
if item.id in self._index and item != self._index[item.id]:
raise IdentifiedResourceMismatch(
"ID {} already found in Index and Items do not match".format(
item.id
)
"ID {} already found in Index and Items do not match".format(item.id)
)

if not item.id.did:
5 changes: 2 additions & 3 deletions pydid/resource.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Resource class that forms the base of all DID Document components."""

from abc import ABC, abstractmethod
import json
from typing import Any, Dict, Type, TypeVar
@@ -130,9 +131,7 @@ def dereference_as(self, typ: Type[ResourceType], reference: str) -> ResourceTyp
return parse_obj_as(typ, resource.dict())
except ValueError as error:
raise ValueError(
"Dereferenced resource {} could not be parsed as {}".format(
resource, typ
)
"Dereferenced resource {} could not be parsed as {}".format(resource, typ)
) from error

@classmethod
6 changes: 3 additions & 3 deletions pydid/service.py
Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@ class Config:

extra = Extra.forbid

type: Literal[
"IndyAgent", "did-communication", "DIDCommMessaging"
] = "did-communication"
type: Literal["IndyAgent", "did-communication", "DIDCommMessaging"] = (
"did-communication"
)
service_endpoint: EndpointStrings
recipient_keys: List[DIDUrl]
routing_keys: List[DIDUrl] = []
4 changes: 1 addition & 3 deletions pydid/validation.py
Original file line number Diff line number Diff line change
@@ -25,9 +25,7 @@ def _require_group(_model, values: dict):
key for key, value in values.items() if value is not None
}
if len(defined_props) < 1:
raise ValueError(
"At least one of {} was required; none found".format(props)
)
raise ValueError("At least one of {} was required; none found".format(props))
return values

return root_validator(allow_reuse=True)(_require_group)
8 changes: 2 additions & 6 deletions tests/doc/test_doc.py
Original file line number Diff line number Diff line change
@@ -531,9 +531,7 @@ def test_all_relationship_builders():
builder.authentication.reference(vmethod.id)
builder.authentication.embed(ExampleVerificationMethod, public_key_example="auth")
builder.assertion_method.reference(vmethod.id)
builder.assertion_method.embed(
ExampleVerificationMethod, public_key_example="assert"
)
builder.assertion_method.embed(ExampleVerificationMethod, public_key_example="assert")
builder.key_agreement.reference(vmethod.id)
builder.key_agreement.embed(
ExampleVerificationMethod, public_key_example="key_agreement"
@@ -615,9 +613,7 @@ def test_relationship_builder_ref_x():
def test_builder_from_doc():
doc = DIDDocument.deserialize(DOC6)
builder = DIDDocumentBuilder.from_doc(doc)
builder.verification_method.add(
ExampleVerificationMethod, public_key_example="1234"
)
builder.verification_method.add(ExampleVerificationMethod, public_key_example="1234")
assert len(builder.build().serialize()["verificationMethod"]) == 2


1 change: 1 addition & 0 deletions tests/test_corrections.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test DID Document corrections."""

import pytest

from pydid.doc.corrections import insert_missing_ids