Skip to content

Commit 3ec7b1f

Browse files
authored
Add stubs for D3DShot (#8652)
1 parent 34383fc commit 3ec7b1f

18 files changed

+664
-0
lines changed

stubs/D3DShot/METADATA.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version = "0.1.*"
2+
requires = ["types-Pillow"]
3+
4+
[tool.stubtest]
5+
# The library only works on Windows; we currently only run stubtest on Ubuntu for third-party stubs in CI.
6+
# See #8660
7+
skip = true

stubs/D3DShot/d3dshot/__init__.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from d3dshot.capture_output import CaptureOutputs as CaptureOutputs
2+
from d3dshot.d3dshot import D3DShot as D3DShot
3+
4+
pil_is_available: bool
5+
numpy_is_available: bool
6+
pytorch_is_available: bool
7+
pytorch_gpu_is_available: bool
8+
capture_output_mapping: dict[str, CaptureOutputs]
9+
capture_outputs: list[str]
10+
11+
def determine_available_capture_outputs() -> list[CaptureOutputs]: ...
12+
def create(capture_output: str = ..., frame_buffer_size: int = ...) -> D3DShot: ...
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import enum
2+
from _typeshed import Incomplete
3+
from collections.abc import Sequence
4+
from ctypes import _CVoidConstPLike
5+
from typing_extensions import Literal, TypeAlias
6+
7+
from PIL import Image
8+
9+
_Frame: TypeAlias = Image.Image | Incomplete
10+
# TODO: Complete types once we can import non-types dependencies
11+
# See: #5768
12+
# from torch import Tensor
13+
# from comtypes import IUnknown
14+
# import numpy.typing as npt
15+
# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor
16+
17+
class CaptureOutputs(enum.Enum):
18+
PIL: int
19+
NUMPY: int
20+
NUMPY_FLOAT: int
21+
PYTORCH: int
22+
PYTORCH_FLOAT: int
23+
PYTORCH_GPU: int
24+
PYTORCH_FLOAT_GPU: int
25+
26+
class CaptureOutputError(BaseException): ...
27+
28+
# All CaptureOutput methods just reference the backend. Making this both a base class and a wrapper.
29+
class CaptureOutput:
30+
# `backend` is a subclass of CaptureOutput based on the CaptureOutputs enum passed to __init__
31+
backend: CaptureOutput
32+
def __init__(self, backend: CaptureOutputs = ...) -> None: ...
33+
def process(
34+
self,
35+
pointer: _CVoidConstPLike,
36+
pitch: int,
37+
size: int,
38+
width: int,
39+
height: int,
40+
region: tuple[int, int, int, int],
41+
rotation: int,
42+
) -> _Frame: ...
43+
def to_pil(self, frame: _Frame) -> Image.Image: ...
44+
def stack(self, frames: Sequence[_Frame], stack_dimension: Literal["first", "last"]) -> _Frame: ...

stubs/D3DShot/d3dshot/capture_outputs/__init__.pyi

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Sequence
3+
from ctypes import _CVoidConstPLike
4+
from typing_extensions import Literal, TypeAlias
5+
6+
from d3dshot.capture_output import CaptureOutput
7+
from PIL import Image
8+
9+
# TODO: Complete types once we can import non-types dependencies
10+
# See: #5768
11+
# import numpy as np
12+
# import numpy.typing as npt
13+
# _NDArray: TypeAlias = npt.NDArray[np.int32]
14+
_NDArray: TypeAlias = Incomplete
15+
16+
class NumpyCaptureOutput(CaptureOutput):
17+
def __init__(self) -> None: ...
18+
def process(
19+
self,
20+
pointer: _CVoidConstPLike,
21+
pitch: int,
22+
size: int,
23+
width: int,
24+
height: int,
25+
region: tuple[int, int, int, int],
26+
rotation: int,
27+
) -> _NDArray: ...
28+
def to_pil(self, frame: _NDArray) -> Image.Image: ...
29+
def stack(self, frames: Sequence[_NDArray] | _NDArray, stack_dimension: Literal["first", "last"]) -> _NDArray: ...
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from d3dshot.capture_outputs.numpy_capture_output import NumpyCaptureOutput
2+
3+
# TODO: Once we can import non-types dependencies, this CaptureOutput should be float based
4+
# See: #5768
5+
class NumpyFloatCaptureOutput(NumpyCaptureOutput): ...
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from collections.abc import Sequence
2+
from ctypes import _CVoidConstPLike
3+
from typing import TypeVar
4+
from typing_extensions import TypeAlias
5+
6+
from d3dshot.capture_output import CaptureOutput
7+
from PIL import Image
8+
9+
_Unused: TypeAlias = object
10+
_ImageT = TypeVar("_ImageT", bound=Image.Image)
11+
12+
class PILCaptureOutput(CaptureOutput):
13+
def __init__(self) -> None: ...
14+
def process(
15+
self,
16+
pointer: _CVoidConstPLike,
17+
pitch: int,
18+
size: int,
19+
width: int,
20+
height: int,
21+
region: tuple[int, int, int, int],
22+
rotation: int,
23+
) -> Image.Image: ...
24+
def to_pil(self, frame: _ImageT) -> _ImageT: ...
25+
def stack(self, frames: Sequence[_ImageT], stack_dimension: _Unused) -> Sequence[_ImageT]: ...
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Sequence
3+
from ctypes import _CVoidConstPLike
4+
from typing_extensions import Literal, TypeAlias
5+
6+
from d3dshot.capture_output import CaptureOutput
7+
from PIL import Image
8+
9+
# TODO: Complete types once we can import non-types dependencies
10+
# See: https://github.com/python/typeshed/issues/5768
11+
# from torch import Tensor
12+
_Tensor: TypeAlias = Incomplete
13+
14+
class PytorchCaptureOutput(CaptureOutput):
15+
def __init__(self) -> None: ...
16+
def process(
17+
self,
18+
pointer: _CVoidConstPLike,
19+
pitch: int,
20+
size: int,
21+
width: int,
22+
height: int,
23+
region: tuple[int, int, int, int],
24+
rotation: int,
25+
) -> _Tensor: ...
26+
def to_pil(self, frame: _Tensor) -> Image.Image: ...
27+
def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput
2+
3+
class PytorchFloatCaptureOutput(PytorchCaptureOutput): ...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from d3dshot.capture_outputs.pytorch_gpu_capture_output import PytorchGPUCaptureOutput
2+
3+
class PytorchFloatGPUCaptureOutput(PytorchGPUCaptureOutput): ...

0 commit comments

Comments
 (0)