From 01538f590ba177865a7db93b8761ff8fb518eabb Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Tue, 7 Nov 2023 11:02:56 +0100 Subject: [PATCH] chore(ruff): configure ruff --- .github/workflows/nucypher-core.yml | 6 +- .../nucypher_core/__init__.pyi | 72 +++++++++++++------ nucypher-core-python/nucypher_core/ferveo.pyi | 6 +- nucypher-core-python/nucypher_core/umbral.pyi | 8 ++- nucypher-core-python/pyproject.toml | 4 ++ 5 files changed, 69 insertions(+), 27 deletions(-) diff --git a/.github/workflows/nucypher-core.yml b/.github/workflows/nucypher-core.yml index 9d571959..000069e0 100644 --- a/.github/workflows/nucypher-core.yml +++ b/.github/workflows/nucypher-core.yml @@ -147,12 +147,16 @@ jobs: working-directory: nucypher-core-python - name: Install pip dependencies - run: pip install mypy + run: pip install mypy ruff - name: Run mypy.stubtest run: python -m mypy.stubtest nucypher_core --allowlist stubtest-allowlist.txt working-directory: nucypher-core-python + - name: Run ruff + run: ruff check nucypher_core + working-directory: nucypher-core-python + trigger-wheels: runs-on: ubuntu-latest needs: test diff --git a/nucypher-core-python/nucypher_core/__init__.pyi b/nucypher-core-python/nucypher_core/__init__.pyi index eb41e920..f515df52 100644 --- a/nucypher-core-python/nucypher_core/__init__.pyi +++ b/nucypher-core-python/nucypher_core/__init__.pyi @@ -1,23 +1,22 @@ -from typing import List, Dict, Sequence, Optional, Mapping, Tuple, Set, final - -from .umbral import ( - SecretKey, - PublicKey, - Signer, - Capsule, - VerifiedKeyFrag, - VerifiedCapsuleFrag, - RecoverableSignature -) +from typing import Dict, List, Mapping, Optional, Sequence, Set, Tuple, final from .ferveo import ( Ciphertext, CiphertextHeader, DkgPublicKey, FerveoPublicKey, - FerveoVariant, SharedSecret, + FerveoVariant, + SharedSecret, +) +from .umbral import ( + Capsule, + PublicKey, + RecoverableSignature, + SecretKey, + Signer, + VerifiedCapsuleFrag, + VerifiedKeyFrag, ) - @final class Address: @@ -235,7 +234,12 @@ class ReencryptionRequest: @final class ReencryptionResponse: - def __init__(self, signer: Signer, capsules_and_vcfrags: Sequence[Tuple[Capsule, VerifiedCapsuleFrag]]): + def __init__( + self, + signer: Signer, + capsules_and_vcfrags: + Sequence[Tuple[Capsule, VerifiedCapsuleFrag]] + ): ... def verify( @@ -374,7 +378,11 @@ class NodeMetadata: @final class FleetStateChecksum: - def __init__(self, other_nodes: Sequence[NodeMetadata], this_node: Optional[NodeMetadata]): + def __init__( + self, + other_nodes: Sequence[NodeMetadata], + this_node: Optional[NodeMetadata] + ): ... def __bytes__(self) -> bytes: @@ -452,7 +460,12 @@ class AuthenticatedData: ... -def encrypt_for_dkg(data: bytes, public_key: DkgPublicKey, conditions: Conditions) -> Tuple[Ciphertext, AuthenticatedData]: +def encrypt_for_dkg( + data: bytes, + public_key: DkgPublicKey, + conditions: Conditions +) -> Tuple[ + Ciphertext, AuthenticatedData]: ... @@ -478,6 +491,7 @@ class AccessControlPolicy: def __bytes__(self) -> bytes: ... + @final class ThresholdMessageKit: @@ -502,7 +516,14 @@ class ThresholdMessageKit: @final class ThresholdDecryptionRequest: - def __init__(self, ritual_id: int, variant: FerveoVariant, ciphertext_header: CiphertextHeader, acp: AccessControlPolicy, context: Optional[Context]): + def __init__( + self, + ritual_id: int, + variant: FerveoVariant, + ciphertext_header: CiphertextHeader, + acp: AccessControlPolicy, + context: Optional[Context] + ): ... ritual_id: int @@ -515,8 +536,11 @@ class ThresholdDecryptionRequest: ciphertext_header: CiphertextHeader - def encrypt(self, shared_secret: SessionSharedSecret, - requester_public_key: SessionStaticKey) -> EncryptedThresholdDecryptionRequest: + def encrypt( + self, + shared_secret: SessionSharedSecret, + requester_public_key: SessionStaticKey + ) -> EncryptedThresholdDecryptionRequest: ... @staticmethod @@ -557,7 +581,10 @@ class ThresholdDecryptionResponse: ritual_id: int - def encrypt(self, shared_secret: SessionSharedSecret) -> EncryptedThresholdDecryptionResponse: + def encrypt( + self, + shared_secret: SessionSharedSecret + ) -> EncryptedThresholdDecryptionResponse: ... @staticmethod @@ -612,7 +639,10 @@ class SessionStaticSecret: def public_key(self) -> SessionStaticKey: ... - def derive_shared_secret(self, their_public_key: SessionStaticKey) -> SessionSharedSecret: + def derive_shared_secret( + self, + their_public_key: SessionStaticKey + ) -> SessionSharedSecret: ... diff --git a/nucypher-core-python/nucypher_core/ferveo.pyi b/nucypher-core-python/nucypher_core/ferveo.pyi index 77c1746e..2083fb54 100644 --- a/nucypher-core-python/nucypher_core/ferveo.pyi +++ b/nucypher-core-python/nucypher_core/ferveo.pyi @@ -1,6 +1,5 @@ from typing import Sequence, final - @final class Keypair: @staticmethod @@ -113,7 +112,10 @@ class Dkg: def generate_transcript(self) -> Transcript: ... - def aggregate_transcripts(self, messages: Sequence[ValidatorMessage]) -> AggregatedTranscript: + def aggregate_transcripts( + self, + messages: Sequence[ValidatorMessage] + ) -> AggregatedTranscript: ... diff --git a/nucypher-core-python/nucypher_core/umbral.pyi b/nucypher-core-python/nucypher_core/umbral.pyi index c83e56a4..7ced6724 100644 --- a/nucypher-core-python/nucypher_core/umbral.pyi +++ b/nucypher-core-python/nucypher_core/umbral.pyi @@ -1,5 +1,4 @@ -from typing import Optional, Tuple, List, final, Sequence - +from typing import List, Optional, Tuple, final @final class SecretKey: @@ -55,7 +54,10 @@ class PublicKey: ... @staticmethod - def recover_from_prehash(prehash: bytes, signature: RecoverableSignature) -> PublicKey: + def recover_from_prehash( + prehash: bytes, + signature: RecoverableSignature + ) -> PublicKey: ... diff --git a/nucypher-core-python/pyproject.toml b/nucypher-core-python/pyproject.toml index 31ffe048..50820b39 100644 --- a/nucypher-core-python/pyproject.toml +++ b/nucypher-core-python/pyproject.toml @@ -1,2 +1,6 @@ [build-system] requires = ["setuptools", "wheel", "setuptools-rust"] + +[tool.ruff] +exclude = ["nucypher_core/__init__.py"] # false-positive unused-import +select = ["E", "F", "I"] \ No newline at end of file