Skip to content

Commit 8537706

Browse files
committed
Setup Python type stubs for reclass_rs
We switch to managing the Python package contents ourselves, so we can include the type stubs in a way which makes mypy's `stubtest` happy. Notably `stubtest` will complain about missing type stubs if we don't provide both `__init__.pyi` and `reclass_rs.pyi`.
1 parent 99e8498 commit 8537706

5 files changed

Lines changed: 123 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ dynamic = ["version"]
1414

1515

1616
[tool.maturin]
17+
python-source = "python"
1718
features = ["pyo3/extension-module"]

python/reclass_rs/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .reclass_rs import *
2+
3+
__doc__ = reclass_rs.__doc__
4+
if hasattr(reclass_rs, "__all__"):
5+
__all__ = reclass_rs.__all__

python/reclass_rs/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
reclass_rs.pyi

python/reclass_rs/py.typed

Whitespace-only changes.

python/reclass_rs/reclass_rs.pyi

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
from enum import Enum
2+
from typing import Any, Optional, final
3+
from datetime import datetime
4+
5+
__all__: list[str] = [
6+
"CompatFlag",
7+
"Config",
8+
"Inventory",
9+
"NodeInfo",
10+
"NodeInfoMeta",
11+
"Reclass",
12+
"buildinfo",
13+
]
14+
15+
@final
16+
class CompatFlag(Enum):
17+
ComposeNodeNameLiteralDots = "ComposeNodeNameLiteralDots"
18+
19+
@final
20+
class Config:
21+
@property
22+
def class_mappings(self) -> list[str]: ...
23+
@property
24+
def class_mappings_match_path(self) -> bool: ...
25+
@property
26+
def classes_path(self) -> str: ...
27+
@property
28+
def compatflags(self) -> set[CompatFlag]: ...
29+
@property
30+
def compose_node_name(self) -> bool: ...
31+
@classmethod
32+
def from_dict(
33+
cls, inventory_path: str, config: dict[str, Any], verbose: bool = False
34+
) -> Config: ...
35+
@property
36+
def ignore_class_notfound(self) -> bool: ...
37+
@property
38+
def ignore_class_notfound_regexp(self) -> list[str]: ...
39+
@property
40+
def ignore_overwritten_missing_references(self) -> bool: ...
41+
@property
42+
def inventory_path(self) -> str: ...
43+
@property
44+
def nodes_path(self) -> str: ...
45+
@property
46+
def verbose_warnings(self) -> bool: ...
47+
48+
@final
49+
class NodeInfoMeta:
50+
@property
51+
def environment(self) -> str: ...
52+
@property
53+
def name(self) -> str: ...
54+
@property
55+
def node(self) -> str: ...
56+
@property
57+
def render_time(self) -> datetime: ...
58+
@property
59+
def uri(self) -> str: ...
60+
61+
@final
62+
class NodeInfo:
63+
@property
64+
def __reclass__(self) -> NodeInfoMeta: ...
65+
@property
66+
def applications(self) -> list[str]: ...
67+
def as_dict(self) -> dict[str, Any]: ...
68+
@property
69+
def classes(self) -> list[str]: ...
70+
@property
71+
def exports(self) -> dict[str, Any]: ...
72+
@property
73+
def parameters(self) -> dict[str, Any]: ...
74+
def reclass_as_dict(self) -> dict[str, Any]: ...
75+
76+
@final
77+
class Inventory:
78+
@property
79+
def applications(self) -> dict[str, list[str]]: ...
80+
def as_dict(self) -> dict[str, Any]: ...
81+
@property
82+
def classes(self) -> dict[str, list[str]]: ...
83+
@property
84+
def nodes(self) -> dict[str, NodeInfo]: ...
85+
86+
@final
87+
class Reclass:
88+
@property
89+
def config(self) -> Config: ...
90+
def __new__(
91+
cls,
92+
inventory_path: Optional[str] = ".",
93+
nodes_path: Optional[str] = None,
94+
classes_path: Optional[str] = None,
95+
ignore_class_notfound: Optional[bool] = None,
96+
): ...
97+
@classmethod
98+
def from_config_file(
99+
cls, inventory_path: str, config_file: str, verbose: bool = False
100+
) -> Reclass: ...
101+
@classmethod
102+
def from_config(cls, config: Config) -> Reclass: ...
103+
def nodeinfo(self, nodename: str) -> NodeInfo: ...
104+
def inventory(self) -> Inventory: ...
105+
@classmethod
106+
def set_thread_count(cls, count: int): ...
107+
def set_compat_flag(self, flag: CompatFlag): ...
108+
def unset_compat_flag(self, flag: CompatFlag): ...
109+
def clear_compat_flags(self): ...
110+
@property
111+
def nodes(self) -> dict[str, str]: ...
112+
@property
113+
def classes(self) -> dict[str, str]: ...
114+
def set_ignore_class_notfound_regexp(self, patterns: list[str]): ...
115+
116+
def buildinfo() -> dict[str, str]: ...

0 commit comments

Comments
 (0)