Skip to content

Commit

Permalink
fix: python typings don't match runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jul 10, 2023
1 parent ffb9b21 commit be90065
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 53 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,17 @@ jobs:
run: python examples/server_api_simple.py
working-directory: ferveo-python

- name: Install pytest
run: pip install pytest
- name: Install pip dependencies
run: pip install pytest mypy

- name: Run pytest
run: pytest
working-directory: ferveo-python

- name: Run mypy.stubtest
run: python -m mypy.stubtest ferveo
working-directory: ferveo-python

codecov:
runs-on: ubuntu-latest
needs: [ test ]
Expand Down
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.10"
1 change: 0 additions & 1 deletion ferveo-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ publish = false

[lib]
crate-type = ["cdylib"]
name = "ferveo_py"

[features]
extension-module = ["pyo3/extension-module"]
Expand Down
11 changes: 11 additions & 0 deletions ferveo-python/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.10"
2 changes: 1 addition & 1 deletion ferveo-python/examples/exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ferveo_py import (
from ferveo import (
Keypair,
Validator,
Dkg,
Expand Down
2 changes: 1 addition & 1 deletion ferveo-python/examples/server_api_precomputed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ferveo_py import (
from ferveo import (
encrypt,
combine_decryption_shares_precomputed,
decrypt_with_shared_secret,
Expand Down
2 changes: 1 addition & 1 deletion ferveo-python/examples/server_api_simple.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ferveo_py import (
from ferveo import (
encrypt,
combine_decryption_shares_simple,
decrypt_with_shared_secret,
Expand Down
2 changes: 1 addition & 1 deletion ferveo-python/ferveo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .ferveo_py import (
from ._ferveo import (
encrypt,
combine_decryption_shares_simple,
combine_decryption_shares_precomputed,
Expand Down
65 changes: 33 additions & 32 deletions ferveo-python/ferveo/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from typing import Sequence

from typing import Sequence, final

@final
class Keypair:
@staticmethod
def random() -> Keypair:
...

@staticmethod
def from_secure_randomness(data: bytes) -> Keypair:
def from_secure_randomness(bytes: bytes) -> Keypair:
...

@staticmethod
def secure_randomness_size(data: bytes) -> int:
def secure_randomness_size() -> int:
...

@staticmethod
def from_bytes(data: bytes) -> Keypair:
def from_bytes(bytes: bytes) -> Keypair:
...

def __bytes__(self) -> bytes:
Expand All @@ -24,10 +24,10 @@ class Keypair:
def public_key(self) -> FerveoPublicKey:
...


@final
class FerveoPublicKey:
@staticmethod
def from_bytes(data: bytes) -> FerveoPublicKey:
def from_bytes(bytes: bytes) -> FerveoPublicKey:
...

def __bytes__(self) -> bytes:
Expand All @@ -36,10 +36,11 @@ class FerveoPublicKey:
def __hash__(self) -> int:
...

def __richcmp__(self, other: FerveoPublicKey, op: int) -> bool:
@staticmethod
def serialized_size() -> int:
...


@final
class Validator:

def __init__(self, address: str, public_key: FerveoPublicKey):
Expand All @@ -49,25 +50,29 @@ class Validator:

public_key: FerveoPublicKey


@final
class Transcript:
@staticmethod
def from_bytes(data: bytes) -> Transcript:
def from_bytes(bytes: bytes) -> Transcript:
...

def __bytes__(self) -> bytes:
...


@final
class DkgPublicKey:
@staticmethod
def from_bytes(data: bytes) -> DkgPublicKey:
def from_bytes(bytes: bytes) -> DkgPublicKey:
...

def __bytes__(self) -> bytes:
...

@staticmethod
def serialized_size() -> int:
...

@final
class ValidatorMessage:

def __init__(
Expand All @@ -80,7 +85,7 @@ class ValidatorMessage:
validator: Validator
transcript: Transcript


@final
class Dkg:

def __init__(
Expand All @@ -101,34 +106,33 @@ class Dkg:
def aggregate_transcripts(self, messages: Sequence[ValidatorMessage]) -> AggregatedTranscript:
...


@final
class Ciphertext:
@staticmethod
def from_bytes(data: bytes) -> Ciphertext:
def from_bytes(bytes: bytes) -> Ciphertext:
...

def __bytes__(self) -> bytes:
...


@final
class DecryptionShareSimple:
@staticmethod
def from_bytes(data: bytes) -> DecryptionShareSimple:
def from_bytes(bytes: bytes) -> DecryptionShareSimple:
...

def __bytes__(self) -> bytes:
...


@final
class DecryptionSharePrecomputed:
@staticmethod
def from_bytes(data: bytes) -> DecryptionSharePrecomputed:
def from_bytes(bytes: bytes) -> DecryptionSharePrecomputed:
...

def __bytes__(self) -> bytes:
...


@final
class AggregatedTranscript:

def __init__(self, messages: Sequence[ValidatorMessage]):
Expand Down Expand Up @@ -156,23 +160,24 @@ class AggregatedTranscript:
...

@staticmethod
def from_bytes(data: bytes) -> AggregatedTranscript:
def from_bytes(bytes: bytes) -> AggregatedTranscript:
...

def __bytes__(self) -> bytes:
...


@final
class SharedSecret:

@staticmethod
def from_bytes(data: bytes) -> SharedSecret:
def from_bytes(bytes: bytes) -> SharedSecret:
...

def __bytes__(self) -> bytes:
...


@final
class FerveoVariant:
@staticmethod
def simple() -> str: ...
Expand All @@ -181,18 +186,18 @@ class FerveoVariant:
def precomputed() -> str: ...


def encrypt(message: bytes, add: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext:
def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext:
...


def combine_decryption_shares_simple(
decryption_shares: Sequence[DecryptionShareSimple],
shares: Sequence[DecryptionShareSimple],
) -> bytes:
...


def combine_decryption_shares_precomputed(
decryption_shares: Sequence[DecryptionSharePrecomputed],
shares: Sequence[DecryptionSharePrecomputed],
) -> SharedSecret:
...

Expand Down Expand Up @@ -267,7 +272,3 @@ class ValidatorPublicKeyMismatch(Exception):

class SerializationError(Exception):
pass


class InvalidVariant(Exception):
pass
26 changes: 15 additions & 11 deletions ferveo-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
[build-system]
requires = ["maturin>=0.14,<0.15"]
build-backend = "maturin"
#[build-system]
#requires = ["maturin>=0.14,<0.15"]
#build-backend = "maturin"
#
#[project]
#name = "ferveo"
#requires-python = ">=3.7"
#classifiers = [
# "Programming Language :: Rust",
# "Programming Language :: Python :: Implementation :: CPython",
# "Programming Language :: Python :: Implementation :: PyPy",
#]
#

[project]
name = "ferveo"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]


2 changes: 1 addition & 1 deletion ferveo-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ use ferveo::bindings_python::*;
use pyo3::prelude::*;

#[pymodule]
fn ferveo_py(py: Python, m: &PyModule) -> PyResult<()> {
fn _ferveo(py: Python, m: &PyModule) -> PyResult<()> {
make_ferveo_py_module(py, m)
}
2 changes: 1 addition & 1 deletion ferveo-python/test/test_ferveo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from ferveo_py import (
from ferveo import (
encrypt,
combine_decryption_shares_simple,
combine_decryption_shares_precomputed,
Expand Down
2 changes: 1 addition & 1 deletion ferveo-python/test/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ferveo_py import (
from ferveo import (
Keypair,
Validator,
Dkg,
Expand Down
1 change: 1 addition & 0 deletions ferveo/src/bindings_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ macro_rules! generate_boxed_bytes_serialization {
#[pymethods]
impl $struct_name {
#[staticmethod]
#[pyo3(signature = (bytes))]
pub fn from_bytes(bytes: &[u8]) -> PyResult<Self> {
Ok($struct_name(
$inner_struct_name::from_bytes(bytes).map_err(|err| {
Expand Down

0 comments on commit be90065

Please sign in to comment.