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

Restyle feat: Add stubgen to produce typings for cython modules. #98

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
.mypy_cache
# TODO(iphydf): Remove once .gen is removed from the name.
*.gen.pyx
__pycache__
19 changes: 0 additions & 19 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ load("//tools/project:build_defs.bzl", "project")

project(license = "gpl3-https")

#genrule(
# name = "pytox/core",
# srcs = [
# "pytox/src/core.pyx",
# "//c-toxcore:tox/tox.h",
# ],
# outs = ["pytox/core.pyx"],
# cmd = "$(location //py_toxcore_c/tools:gen_api) $(location pytox/src/core.pyx) $(location //c-toxcore:tox/tox.h) > $@",
# tools = ["//py_toxcore_c/tools:gen_api"],
#)

pyx_library(
name = "pytox",
srcs = glob(
Expand All @@ -34,11 +23,3 @@ pyx_library(
tags = ["no-cross"],
visibility = ["//visibility:public"],
)

genrule(
name = "pytox_stubs",
outs = [mod[:-4] + ".pyi" for mod in glob(["pytox/**/*.pyx"])],
cmd = "$(location //py_toxcore_c/tools:stubgen) -o $(GENDIR)/py_toxcore_c" + " ".join([" -m %s" % mod[:-4].replace("/", ".") for mod in glob(["pytox/**/*.pyx"])]),
tags = ["manual"],
tools = ["//py_toxcore_c/tools:stubgen"],
)
8 changes: 4 additions & 4 deletions pytox/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from enum import Enum
import enum
from typing import Sized
from typing import TypeVar

Expand All @@ -10,7 +10,7 @@ class PytoxException(Exception):


class ApiException(PytoxException):
def __init__(self, err: Enum):
def __init__(self, err: enum.Enum):
super().__init__(err.name)
self.error = err

Expand All @@ -20,13 +20,13 @@ class LengthException(PytoxException):


class UseAfterFreeException(Exception):
def __init__(self):
def __init__(self) -> None:
super().__init__(
"object used after it was killed/freed (or it was never initialised)"
)


def _check_len(name: str, data: T, expected_length: int) -> T:
def check_len(name: str, data: T, expected_length: int) -> T:
if len(data) < expected_length:
raise LengthException(
f"parameter '{name}' received bytes of invalid"
Expand Down
84 changes: 84 additions & 0 deletions pytox/toxav/toxav.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# pytox.toxav.toxav
from array import array
from pytox.toxcore.tox import Tox_Ptr
from types import TracebackType
from typing import Any
from typing import Self
import enum
import pytox.common
class Tox_Conference_Number: ...
class Tox_Conference_Peer_Number: ...
class Tox_File_Number: ...
class Tox_Friend_Message_Id: ...
class Tox_Friend_Number: ...
class Tox_Group_Message_Id: ...
class Tox_Group_Number: ...
class Tox_Group_Peer_Number: ...
class ApiException(pytox.common.ApiException): ...
class Toxav_Call_Control(enum.Enum): ...
class Toxav_Err_Answer(enum.Enum): ...
class Toxav_Err_Bit_Rate_Set(enum.Enum): ...
class Toxav_Err_Call(enum.Enum): ...
class Toxav_Err_Call_Control(enum.Enum): ...
class Toxav_Err_New(enum.Enum): ...
class Toxav_Err_Send_Frame(enum.Enum): ...
class Toxav_Friend_Call_State(enum.Enum): ...
class Toxav_Ptr:
def __enter__(self) -> Self: ...
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_traceback: TracebackType | None) -> None: ...
def __init__(self, tox: Tox_Ptr) -> None: ...
def handle_audio_bit_rate(self, friend_number: int, audio_bit_rate: int) -> None: ...
def handle_audio_receive_frame(self, friend_number: int, pcm: array[Any], channels: int, sampling_rate: int) -> None: ...
def handle_call(self, friend_number: int, audio_enabled: bool, video_enabled: bool) -> None: ...
def handle_call_state(self, friend_number: int, state: int) -> None: ...
def handle_video_bit_rate(self, friend_number: int, video_bit_rate: int) -> None: ...
def handle_video_receive_frame(self, friend_number: int, width: int, height: int, y: bytes, u: bytes, v: bytes, ystride: int, ustride: int, vstride: int) -> None: ...
TOXAV_CALL_CONTROL_CANCEL: Toxav_Call_Control
TOXAV_CALL_CONTROL_HIDE_VIDEO: Toxav_Call_Control
TOXAV_CALL_CONTROL_MUTE_AUDIO: Toxav_Call_Control
TOXAV_CALL_CONTROL_PAUSE: Toxav_Call_Control
TOXAV_CALL_CONTROL_RESUME: Toxav_Call_Control
TOXAV_CALL_CONTROL_SHOW_VIDEO: Toxav_Call_Control
TOXAV_CALL_CONTROL_UNMUTE_AUDIO: Toxav_Call_Control
TOXAV_ERR_ANSWER_CODEC_INITIALIZATION: Toxav_Err_Answer
TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING: Toxav_Err_Answer
TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND: Toxav_Err_Answer
TOXAV_ERR_ANSWER_INVALID_BIT_RATE: Toxav_Err_Answer
TOXAV_ERR_ANSWER_OK: Toxav_Err_Answer
TOXAV_ERR_ANSWER_SYNC: Toxav_Err_Answer
TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND: Toxav_Err_Bit_Rate_Set
TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL: Toxav_Err_Bit_Rate_Set
TOXAV_ERR_BIT_RATE_SET_INVALID_BIT_RATE: Toxav_Err_Bit_Rate_Set
TOXAV_ERR_BIT_RATE_SET_OK: Toxav_Err_Bit_Rate_Set
TOXAV_ERR_BIT_RATE_SET_SYNC: Toxav_Err_Bit_Rate_Set
TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND: Toxav_Err_Call
TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL: Toxav_Err_Call
TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION: Toxav_Err_Call
TOXAV_ERR_CALL_CONTROL_OK: Toxav_Err_Call
TOXAV_ERR_CALL_CONTROL_SYNC: Toxav_Err_Call
TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL: Toxav_Err_Call
TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED: Toxav_Err_Call
TOXAV_ERR_CALL_FRIEND_NOT_FOUND: Toxav_Err_Call
TOXAV_ERR_CALL_INVALID_BIT_RATE: Toxav_Err_Call
TOXAV_ERR_CALL_MALLOC: Toxav_Err_Call
TOXAV_ERR_CALL_OK: Toxav_Err_Call
TOXAV_ERR_CALL_SYNC: Toxav_Err_Call
TOXAV_ERR_NEW_MALLOC: Toxav_Err_New
TOXAV_ERR_NEW_MULTIPLE: Toxav_Err_New
TOXAV_ERR_NEW_NULL: Toxav_Err_New
TOXAV_ERR_NEW_OK: Toxav_Err_New
TOXAV_ERR_SEND_FRAME_FRIEND_NOT_FOUND: Toxav_Err_Send_Frame
TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL: Toxav_Err_Send_Frame
TOXAV_ERR_SEND_FRAME_INVALID: Toxav_Err_Send_Frame
TOXAV_ERR_SEND_FRAME_NULL: Toxav_Err_Send_Frame
TOXAV_ERR_SEND_FRAME_OK: Toxav_Err_Send_Frame
TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED: Toxav_Err_Send_Frame
TOXAV_ERR_SEND_FRAME_RTP_FAILED: Toxav_Err_Send_Frame
TOXAV_ERR_SEND_FRAME_SYNC: Toxav_Err_Send_Frame
TOXAV_FRIEND_CALL_STATE_ACCEPTING_A: Toxav_Friend_Call_State
TOXAV_FRIEND_CALL_STATE_ACCEPTING_V: Toxav_Friend_Call_State
TOXAV_FRIEND_CALL_STATE_ERROR: Toxav_Friend_Call_State
TOXAV_FRIEND_CALL_STATE_FINISHED: Toxav_Friend_Call_State
TOXAV_FRIEND_CALL_STATE_NONE: Toxav_Friend_Call_State
TOXAV_FRIEND_CALL_STATE_SENDING_A: Toxav_Friend_Call_State
TOXAV_FRIEND_CALL_STATE_SENDING_V: Toxav_Friend_Call_State
1 change: 1 addition & 0 deletions pytox/toxav/toxav.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ cdef class Toxav_Ptr:
def handle_video_receive_frame(self, friend_number: int, width: int, height: int, y: bytes, u: bytes, v: bytes, ystride: int, ustride: int, vstride: int) -> None: pass

def __init__(self, tox.Tox_Ptr tox):
"""Create new Toxav object."""
self._ptr = self._new(tox)
install_handlers(self, self._ptr)
Loading
Loading