Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ jobs:
python3 -m venv .venv
source .venv/bin/activate
pip install reclass-rs --find-links dist --force-reinstall
pip install pytest kapicorp-reclass
pip install pytest mypy kapicorp-reclass
stubtest reclass_rs
mypy --check-untyped-defs --ignore-missing-imports tests/
pytest
- name: pytest
if: ${{ !startsWith(matrix.platform.target, 'x86') && matrix.platform.target != 'ppc64' }}
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ dynamic = ["version"]


[tool.maturin]
python-source = "python"
features = ["pyo3/extension-module"]
5 changes: 5 additions & 0 deletions python/reclass_rs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .reclass_rs import *

__doc__ = reclass_rs.__doc__
if hasattr(reclass_rs, "__all__"):
__all__ = reclass_rs.__all__
1 change: 1 addition & 0 deletions python/reclass_rs/__init__.pyi
Empty file added python/reclass_rs/py.typed
Empty file.
116 changes: 116 additions & 0 deletions python/reclass_rs/reclass_rs.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from enum import Enum
from typing import Any, Optional, final
from datetime import datetime

__all__: list[str] = [
"CompatFlag",
"Config",
"Inventory",
"NodeInfo",
"NodeInfoMeta",
"Reclass",
"buildinfo",
]

@final
class CompatFlag(Enum):
ComposeNodeNameLiteralDots = "ComposeNodeNameLiteralDots"

@final
class Config:
@property
def class_mappings(self) -> list[str]: ...
@property
def class_mappings_match_path(self) -> bool: ...
@property
def classes_path(self) -> str: ...
@property
def compatflags(self) -> set[CompatFlag]: ...
@property
def compose_node_name(self) -> bool: ...
@classmethod
def from_dict(
cls, inventory_path: str, config: dict[str, Any], verbose: bool = False
) -> Config: ...
@property
def ignore_class_notfound(self) -> bool: ...
@property
def ignore_class_notfound_regexp(self) -> list[str]: ...
@property
def ignore_overwritten_missing_references(self) -> bool: ...
@property
def inventory_path(self) -> str: ...
@property
def nodes_path(self) -> str: ...
@property
def verbose_warnings(self) -> bool: ...

@final
class NodeInfoMeta:
@property
def environment(self) -> str: ...
@property
def name(self) -> str: ...
@property
def node(self) -> str: ...
@property
def render_time(self) -> datetime: ...
@property
def uri(self) -> str: ...

@final
class NodeInfo:
@property
def __reclass__(self) -> NodeInfoMeta: ...
@property
def applications(self) -> list[str]: ...
def as_dict(self) -> dict[str, Any]: ...
@property
def classes(self) -> list[str]: ...
@property
def exports(self) -> dict[str, Any]: ...
@property
def parameters(self) -> dict[str, Any]: ...
def reclass_as_dict(self) -> dict[str, Any]: ...

@final
class Inventory:
@property
def applications(self) -> dict[str, list[str]]: ...
def as_dict(self) -> dict[str, Any]: ...
@property
def classes(self) -> dict[str, list[str]]: ...
@property
def nodes(self) -> dict[str, NodeInfo]: ...

@final
class Reclass:
@property
def config(self) -> Config: ...
def __new__(
cls,
inventory_path: Optional[str] = ".",
nodes_path: Optional[str] = None,
classes_path: Optional[str] = None,
ignore_class_notfound: Optional[bool] = None,
): ...
@classmethod
def from_config_file(
cls, inventory_path: str, config_file: str, verbose: bool = False
) -> Reclass: ...
@classmethod
def from_config(cls, config: Config) -> Reclass: ...
def nodeinfo(self, nodename: str) -> NodeInfo: ...
def inventory(self) -> Inventory: ...
@classmethod
def set_thread_count(cls, count: int): ...
def set_compat_flag(self, flag: CompatFlag): ...
def unset_compat_flag(self, flag: CompatFlag): ...
def clear_compat_flags(self): ...
@property
def nodes(self) -> dict[str, str]: ...
@property
def classes(self) -> dict[str, str]: ...
def set_ignore_class_notfound_regexp(self, patterns: list[str]): ...

def buildinfo() -> dict[str, str]: ...
26 changes: 12 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,18 @@ fn buildinfo() -> HashMap<&'static str, &'static str> {
}

#[pymodule]
fn reclass_rs(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
// Register the top-level `Reclass` Python class which is used to configure the library
m.add_class::<Reclass>()?;
// Register the `Config` class and `CompatFlag` enum
m.add_class::<Config>()?;
m.add_class::<CompatFlag>()?;
// Register the NodeInfoMeta and NodeInfo classes
m.add_class::<NodeInfoMeta>()?;
m.add_class::<NodeInfo>()?;
// Register the Inventory class
m.add_class::<Inventory>()?;
// Register the buildinfo method
m.add_function(wrap_pyfunction!(buildinfo, m)?)?;
Ok(())
mod reclass_rs {
#[pymodule_export]
use super::Reclass;
#[pymodule_export]
use super::buildinfo;

#[pymodule_export]
use crate::config::{CompatFlag, Config};
#[pymodule_export]
use crate::inventory::Inventory;
#[pymodule_export]
use crate::node::{NodeInfo, NodeInfoMeta};
}

#[cfg(test)]
Expand Down