diff --git a/bindings/python/MANIFEST.in b/bindings/python/MANIFEST.in index 55f93d3..0ed78e9 100644 --- a/bindings/python/MANIFEST.in +++ b/bindings/python/MANIFEST.in @@ -3,6 +3,8 @@ include build.rs include pyproject.toml include rust-toolchain recursive-include src * +include jsonschema_rs/py.typed +recursive-include jsonschema_rs *.pyi recursive-include jsonschema-lib * recursive-exclude jsonschema-lib Cargo.lock recursive-exclude jsonschema-lib/target * diff --git a/bindings/python/jsonschema_rs/__init__.py b/bindings/python/jsonschema_rs/__init__.py new file mode 100644 index 0000000..adcc766 --- /dev/null +++ b/bindings/python/jsonschema_rs/__init__.py @@ -0,0 +1 @@ +from ._jsonschema_rs import * diff --git a/bindings/python/jsonschema_rs/__init__.pyi b/bindings/python/jsonschema_rs/__init__.pyi new file mode 100644 index 0000000..a7a7184 --- /dev/null +++ b/bindings/python/jsonschema_rs/__init__.pyi @@ -0,0 +1,69 @@ +from typing import Any, TypeVar +from collections.abc import Iterator + +_SchemaT = TypeVar('_SchemaT', bool, dict[str, Any]) + + +def is_valid( + schema: _SchemaT, + instance: Any, + draft: int | None = None, + with_meta_schemas: bool | None = None +) -> bool: + pass + +def validate( + schema: _SchemaT, + instance: Any, + draft: int | None = None, + with_meta_schemas: bool | None = None +) -> None: + pass + +def iter_errors( + schema: _SchemaT, + instance: Any, + draft: int | None = None, + with_meta_schemas: bool | None = None +) -> Iterator[ValidationError]: + pass + + +class JSONSchema: + + def __init__( + self, + schema: _SchemaT, + draft: int | None = None, + with_meta_schemas: bool | None = None + ) -> None: + pass + + @classmethod + def from_str( + cls, + schema: str, + draft: int | None = None, + with_meta_schemas: bool | None = None + ) -> 'JSONSchema': + pass + + def is_valid(self, instance: Any) -> bool: + pass + + def validate(self, instance: Any) -> None: + pass + + def iter_errors(self, instance: Any) -> Iterator[ValidationError]: + pass + + +class ValidationError(ValueError): + message: str + schema_path: list[str | int] + instance_path: list[str | int] + + +Draft4: int +Draft6: int +Draft7: int diff --git a/bindings/python/jsonschema_rs/py.typed b/bindings/python/jsonschema_rs/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 51ad034..e507b25 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -21,6 +21,7 @@ def call_setup(): setup( name="jsonschema_rs", version="0.16.1", + packages=["jsonschema_rs"], description="Fast JSON Schema validation for Python implemented in Rust", long_description=open("README.rst", encoding="utf-8").read(), long_description_content_type="text/x-rst", @@ -32,7 +33,8 @@ def call_setup(): python_requires=">=3.7", url="https://github.com/Stranger6667/jsonschema-rs/tree/master/python", license="MIT", - rust_extensions=[RustExtension("jsonschema_rs", binding=Binding.PyO3)], + rust_extensions=[RustExtension("jsonschema_rs._jsonschema_rs", binding=Binding.PyO3)], + include_package_data=True, classifiers=[ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index c6da13f..cdd77e8 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -450,7 +450,7 @@ mod build { /// JSON Schema validation for Python written in Rust. #[pymodule] -fn jsonschema_rs(py: Python<'_>, module: &PyModule) -> PyResult<()> { +fn _jsonschema_rs(py: Python<'_>, module: &PyModule) -> PyResult<()> { // To provide proper signatures for PyCharm, all the functions have their signatures as the // first line in docstrings. The idea is taken from NumPy. types::init(); diff --git a/bindings/python/tests-py/test_jsonschema.py b/bindings/python/tests-py/test_jsonschema.py index afdae45..b029b44 100644 --- a/bindings/python/tests-py/test_jsonschema.py +++ b/bindings/python/tests-py/test_jsonschema.py @@ -65,7 +65,7 @@ def test_validate(func): def test_from_str_error(): with pytest.raises(ValueError, match="Expected string, got int"): - JSONSchema.from_str(42) + JSONSchema.from_str(42) # type: ignore @pytest.mark.parametrize(