Skip to content

Commit cf9bbf0

Browse files
ci: update typing, pre-commit, and add all kwargs to decon func (#48)
* update typing * add all args * style(pre-commit.ci): auto fixes [...] * more typing * fix mypy * style(pre-commit.ci): auto fixes [...] --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a2e6cbb commit cf9bbf0

File tree

9 files changed

+220
-72
lines changed

9 files changed

+220
-72
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ default_install_hook_types: [pre-commit, commit-msg]
77

88
repos:
99
- repo: https://github.com/charliermarsh/ruff-pre-commit
10-
rev: v0.0.262
10+
rev: v0.0.289
1111
hooks:
1212
- id: ruff
1313
args: [--fix]
1414

1515
- repo: https://github.com/psf/black
16-
rev: 23.3.0
16+
rev: 23.9.1
1717
hooks:
1818
- id: black
1919

2020
- repo: https://github.com/abravalheri/validate-pyproject
21-
rev: v0.12.2
21+
rev: v0.14
2222
hooks:
2323
- id: validate-pyproject
2424

25-
# - repo: https://github.com/pre-commit/mirrors-mypy
26-
# rev: v1.2.0
27-
# hooks:
28-
# - id: mypy
29-
# files: "^src/"
30-
# # # you have to add the things you want to type check against here
31-
# additional_dependencies:
32-
# - numpy
33-
# - typing_extensions
25+
- repo: https://github.com/pre-commit/mirrors-mypy
26+
rev: v1.5.1
27+
hooks:
28+
- id: mypy
29+
files: "^src/"
30+
# # you have to add the things you want to type check against here
31+
additional_dependencies:
32+
- numpy
33+
- typing_extensions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readme = "README.md"
1111
requires-python = ">=3.7"
1212
license = { text = "MIT" }
1313
keywords = ["deconvolution", "microscopy", "CUDA"]
14-
authors = [{ email = "talley.lambert@gmail.com" }, { name = "Talley Lambert" }]
14+
authors = [{ email = "talley.lambert@gmail.com", name = "Talley Lambert" }]
1515
classifiers = [
1616
"Development Status :: 4 - Beta",
1717
"Environment :: GPU :: NVIDIA CUDA",

src/pycudadecon/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
try:
22
from importlib.metadata import PackageNotFoundError, version
33
except ImportError:
4-
from importlib_metadata import PackageNotFoundError, version
4+
from importlib_metadata import PackageNotFoundError, version # type: ignore
55

66
try:
77
__version__ = version("pycudadecon")
@@ -15,7 +15,7 @@
1515

1616

1717
try:
18-
from . import _libwrap as lib # noqa: F811
18+
from . import _libwrap as lib
1919
except FileNotFoundError as e:
2020
import warnings
2121

@@ -26,7 +26,7 @@ class _stub:
2626
def __getattr__(self, name):
2727
raise t
2828

29-
lib = _stub()
29+
lib = _stub() # type: ignore
3030

3131

3232
from .affine import affineGPU, deskewGPU, rotateGPU

src/pycudadecon/_ctyped.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
import os
44
from ctypes.util import find_library
55
from inspect import Parameter, signature
6-
from typing import Callable, Optional, Tuple, Type
6+
from typing import TYPE_CHECKING, Callable, Optional, Tuple, Type
77

88
import numpy as np
99
from typing_extensions import Annotated, get_args, get_origin
1010

11+
if TYPE_CHECKING:
12+
from typing import TypeVar
13+
14+
from typing_extensions import ParamSpec
15+
16+
P = ParamSpec("P")
17+
R = TypeVar("R")
18+
1119

1220
class Library:
1321
def __init__(self, name: str, version: Tuple[int, ...] = (0, 0, 0)):
@@ -24,7 +32,7 @@ def __init__(self, name: str, version: Tuple[int, ...] = (0, 0, 0)):
2432
if not self.lib._name:
2533
raise FileNotFoundError(f"Unable to find library: {self.name}")
2634

27-
def function(self, func: Callable) -> Callable:
35+
def function(self, func: "Callable[P, R]") -> "Callable[P, R]":
2836
func_c = getattr(self.lib, func.__name__)
2937

3038
sig = signature(func)
@@ -40,7 +48,7 @@ def __init__(self, func):
4048
def __signature__(self):
4149
return sig
4250

43-
def __call__(self, *args, **kw):
51+
def __call__(self, *args: "P.args", **kw: "P.kwargs") -> "R":
4452
return self._func(*args, **kw)
4553

4654
def __repr__(_self):
@@ -68,5 +76,6 @@ def cast_type(hint: Type) -> Optional[Type]:
6876
float: ctypes.c_float,
6977
int: ctypes.c_int,
7078
str: ctypes.c_char_p,
79+
bytes: ctypes.c_char_p,
7180
np.ndarray: np.ctypeslib.ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
7281
}[hint]

src/pycudadecon/_libwrap.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
22
from pathlib import Path
3+
from typing import Tuple
34

45
import numpy as np
56
from typing_extensions import Annotated
67

78
from ._ctyped import Library
8-
from typing import Tuple
9+
910
# FIXME: ugly... we should export version better from cudadecon
1011
_cudadecon_version: Tuple[int, ...] = (0, 0, 0)
1112
_conda_prefix = os.getenv("CONDA_PREFIX")
@@ -32,12 +33,14 @@
3233

3334

3435
@lib.function
35-
def camcor_interface_init(nx: int, ny: int, nz: int, camparam: np.ndarray) -> int:
36+
def camcor_interface_init( # type: ignore [empty-body]
37+
nx: int, ny: int, nz: int, camparam: np.ndarray
38+
) -> int:
3639
"""Setup for camera corrections."""
3740

3841

3942
@lib.function
40-
def camcor_interface(
43+
def camcor_interface( # type: ignore [empty-body]
4144
raw_data: ndarray_uint16, nx: int, ny: int, nz: int, result: ndarray_uint16
4245
) -> int:
4346
"""Execute camera corrections."""
@@ -46,7 +49,7 @@ def camcor_interface(
4649
if _cudadecon_version < (0, 6):
4750

4851
@lib.function
49-
def RL_interface_init(
52+
def RL_interface_init( # type: ignore [empty-body]
5053
nx: int,
5154
ny: int,
5255
nz: int,
@@ -75,10 +78,10 @@ def RL_interface_init(
7578
OTF_file_name: file name of OTF
7679
"""
7780

78-
else: # include "bSkewDecon" arguement
81+
else: # include "bSkewDecon" arguement
7982

8083
@lib.function
81-
def RL_interface_init(
84+
def RL_interface_init( # type: ignore [empty-body]
8285
nx: int,
8386
ny: int,
8487
nz: int,
@@ -113,7 +116,7 @@ def RL_interface_init(
113116
if _cudadecon_version < (0, 6):
114117

115118
@lib.function
116-
def RL_interface(
119+
def RL_interface( # type: ignore [empty-body]
117120
raw_data: ndarray_uint16,
118121
nx: int,
119122
ny: int,
@@ -135,7 +138,7 @@ def RL_interface(
135138
else:
136139

137140
@lib.function
138-
def RL_interface(
141+
def RL_interface( # type: ignore [empty-body]
139142
raw_data: ndarray_uint16,
140143
nx: int,
141144
ny: int,
@@ -160,17 +163,17 @@ def RL_interface(
160163
# retrieve the post-deskewed image dimensions
161164
# can be used to allocate result buffer before calling RL_interface()
162165
@lib.function
163-
def get_output_nx() -> int:
166+
def get_output_nx() -> int: # type: ignore [empty-body]
164167
...
165168

166169

167170
@lib.function
168-
def get_output_ny() -> int:
171+
def get_output_ny() -> int: # type: ignore [empty-body]
169172
...
170173

171174

172175
@lib.function
173-
def get_output_nz() -> int:
176+
def get_output_nz() -> int: # type: ignore [empty-body]
174177
...
175178

176179

@@ -197,7 +200,7 @@ def cuda_reset() -> None:
197200

198201

199202
@lib.function
200-
def Deskew_interface(
203+
def Deskew_interface( # type: ignore [empty-body]
201204
raw_data: np.ndarray,
202205
nx: int,
203206
ny: int,
@@ -214,7 +217,7 @@ def Deskew_interface(
214217

215218

216219
@lib.function
217-
def Affine_interface(
220+
def Affine_interface( # type: ignore [empty-body]
218221
raw_data: np.ndarray,
219222
nx: int,
220223
ny: int,
@@ -226,7 +229,7 @@ def Affine_interface(
226229

227230

228231
@lib.function
229-
def Affine_interface_RA(
232+
def Affine_interface_RA( # type: ignore [empty-body]
230233
raw_data: np.ndarray,
231234
nx: int,
232235
ny: int,
@@ -251,8 +254,8 @@ def Affine_interface_RA(
251254

252255
@otf_lib.function
253256
def makeOTF(
254-
ifiles: str,
255-
ofiles: str,
257+
ifiles: bytes,
258+
ofiles: bytes,
256259
lambdanm: int = 520,
257260
dz: float = 0.102,
258261
interpkr: int = 10,

src/pycudadecon/affine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ def affineGPU(
165165
# have to calculate this here to know the size of the return array
166166
result = np.empty((nz, ny, nx), dtype=np.float32)
167167
if isinstance(dzyx, (tuple, list)) and len(dzyx) == 3:
168-
_dzyx = tuple(float(i) for i in dzyx[::-1])
168+
dx, dy, dz = (float(i) for i in dzyx[::-1])
169169
# note, dzyx coordinate order is flipped when handing to Affine_interface_RA
170-
lib.Affine_interface_RA(im, nx, ny, nz, *_dzyx, result, tmat)
170+
lib.Affine_interface_RA(im, nx, ny, nz, dx, dy, dz, result, tmat)
171171
else:
172172
lib.Affine_interface(im, nx, ny, nz, result, tmat)
173173
return result

0 commit comments

Comments
 (0)