Skip to content

Commit 9e45314

Browse files
Fix stubs, add stub test (#309)
1 parent e214e32 commit 9e45314

7 files changed

Lines changed: 650 additions & 526 deletions

File tree

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ setup:
1313
build-py:
1414
maturin develop -m encoderfile-py/Cargo.toml
1515

16+
.PHONY: stubtest
17+
stubtest:
18+
@echo "Running stubtest..."
19+
@uv run --dev stubtest --allowlist=allowlist.txt encoderfile.encoderfile
20+
1621
.PHONY: format
1722
format:
1823
@echo "Formatting python..."

allowlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ignore missing __all__ in encoderfile
2+
encoderfile.encoderfile.__all__

encoderfile-py/python/encoderfile/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from .encoderfile import * # noqa
1+
# type: ignore
2+
from .encoderfile import * # noqa # type: ignore
23

34

45
__doc__ = encoderfile.__doc__ # noqa # type: ignore
Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
from typing import Optional
1+
from typing import Optional, final
22

3+
@final
34
class EncoderfileBuilder:
45
@classmethod
56
def from_config(
67
cls,
78
config: str,
8-
output_path: Optional[str] = None,
9-
base_binary_path: Optional[str] = None,
10-
platform: Optional[str] = None,
9+
) -> "EncoderfileBuilder": ...
10+
def build(
11+
self,
12+
working_dir: Optional[str] = None,
1113
version: Optional[str] = None,
1214
no_download: bool = False,
13-
directory: Optional[str] = None,
14-
) -> "EncoderfileBuilder": ...
15-
def build(self, cache_dir: Optional[str] = None): ...
15+
): ...
16+
17+
@final
18+
class ModelConfig:
19+
model_type: str
20+
num_labels: Optional[int]
21+
id2label: Optional[dict[int, str]]
22+
label2id: Optional[dict[str, int]]
23+
24+
@final
25+
class EncoderfileConfig:
26+
name: str
27+
version: str
28+
model_type: str
29+
transform: Optional[str]
30+
lua_libs: Optional[list[str]]
31+
32+
@final
33+
class InspectInfo:
34+
model_config: ModelConfig
35+
encoderfile_config: EncoderfileConfig
36+
37+
def inspect(path: str) -> InspectInfo: ...

encoderfile-py/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@ mod encoderfile {
1010

1111
#[pymodule_export]
1212
use super::builder::inspect;
13+
14+
#[pymodule_export]
15+
use super::builder::PyEncoderfileConfig;
16+
17+
#[pymodule_export]
18+
use super::builder::PyModelConfig;
19+
20+
#[pymodule_export]
21+
use super::builder::PyInspectInfo;
1322
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires-python = ">=3.13"
77
dependencies = [ "pip>=25.2", "protobuf>=6.33.0"]
88

99
[dependency-groups]
10-
dev = [ "pre-commit>=4.3.0", "ruff>=0.14.2",]
10+
dev = [ "pre-commit>=4.3.0", "ruff>=0.14.2", "mypy>=1.19"]
1111
docs = [ "mkdocs>=1.6.1", "mkdocs-include-markdown-plugin>=7.2.0", "mkdocs-material>=9.7.0",]
1212
setup = [ "onnxruntime>=1.23.1", "optimum[onnxruntime]>=2.0.0", "transformers>=4.55.0",]
1313
models = [ "torch>=2.9.0", "click", {include-group = "setup"} ]

uv.lock

Lines changed: 602 additions & 517 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)