diff --git a/.gitignore b/.gitignore index 1b80eab..45f7a83 100644 --- a/.gitignore +++ b/.gitignore @@ -108,8 +108,9 @@ ENV/ .DS_Store .vscode/ -# pdm +# pdm .pdm-python # ruff -.ruff_cache/* \ No newline at end of file +.ruff_cache/ +_verion.py diff --git a/pyproject.toml b/pyproject.toml index 010c824..b200765 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,6 +67,7 @@ include = [ "tests/**/*.py", "tests/**/*.pyi" ] +exclude = ["tests", "src/mantaray_py/_version.py"] [tool.ruff.lint] preview = true # preview features & checks, use with caution @@ -177,9 +178,10 @@ post-install-commands = ["pre-commit install"] # Lint env dendencies [tool.hatch.envs.lint] dependencies = [ + "pydantic", "mypy", "ruff", -"deptry", + "deptry", ] @@ -227,8 +229,7 @@ build-check = [ [tool.hatch.envs.test] dependencies = [ "pytest", -"pytest-cov", - + "pytest-cov", ] @@ -255,4 +256,4 @@ exclude = [ ] [tool.hatch.build.targets.wheel] -packages = ["src/mantaray_py/"] \ No newline at end of file +packages = ["src/mantaray_py/"] diff --git a/src/mantaray_py/__init__.py b/src/mantaray_py/__init__.py index 1e3109e..0416264 100644 --- a/src/mantaray_py/__init__.py +++ b/src/mantaray_py/__init__.py @@ -3,8 +3,8 @@ from importlib.metadata import PackageNotFoundError, version try: - __version__ = version("mantaray-py") + __version__ = version('mantaray-py') except PackageNotFoundError: # pragma: no cover - __version__ = "unknown" + __version__ = 'unknown' finally: del version, PackageNotFoundError diff --git a/src/mantaray_py/_version.py b/src/mantaray_py/_version.py new file mode 100644 index 0000000..897f4f6 --- /dev/null +++ b/src/mantaray_py/_version.py @@ -0,0 +1,17 @@ +# file generated by setuptools_scm +# don't change, don't track in version control +TYPE_CHECKING = False +if TYPE_CHECKING: + from typing import Tuple, Union + + VERSION_TUPLE = Tuple[Union[int, str], ...] +else: + VERSION_TUPLE = object + +version: str +__version__: str +__version_tuple__: VERSION_TUPLE +version_tuple: VERSION_TUPLE + +__version__ = version = '0.0.post1.dev1+ga17826a' +__version_tuple__ = version_tuple = (0, 0, 'dev1', 'ga17826a') diff --git a/src/mantaray_py/types/types.py b/src/mantaray_py/types/types.py new file mode 100644 index 0000000..a1a912d --- /dev/null +++ b/src/mantaray_py/types/types.py @@ -0,0 +1,51 @@ +from typing import Callable, Literal, Optional, Union + +from pydantic import BaseModel, conlist + +# Equivalent to the 'marshal_versionValues' and 'marshal_version' in TypeScript +marshal_version_values = ('0.1', '0.2') +marshal_version = Literal['0.1', '0.2'] + + +# Equivalent to the 'NodeType' enum in TypeScript +class NodeType: + value = 2 + edge = 4 + with_path_separator = 8 + with_metadata = 16 + mask = 255 + + +# Custom type for Bytes with constrained length +def create_bytes_type(length: int): + return conlist(int, min_items=length, max_items=length) + + +Bytes32 = create_bytes_type(32) +Bytes64 = create_bytes_type(64) +Reference = Union[Bytes32, Bytes64] + + +# Equivalent to the 'metadata_mapping' type in TypeScript +metadata_mapping = dict[str, str] + +# Equivalent to the 'Storage_loader' and 'StorageSaver' in TypeScript +Storage_loader = Callable[[Reference], bytes] +Storage_saver = Callable[[bytes, Optional[dict]], Reference] + + +# Equivalent to the 'StorageHandler' type in TypeScript +class StorageHandler(BaseModel): + load: Storage_loader + save: Storage_saver + + +# Example usage of the defined models and types +class ExampleUsage(BaseModel): + version: marshal_version + reference: Reference + metadata: metadata_mapping + handler: StorageHandler + + class Config: + arbitrary_types_allowed = True diff --git a/tests/test_add.py b/tests/test_add.py index f293f79..ea9b8a4 100644 --- a/tests/test_add.py +++ b/tests/test_add.py @@ -1,9 +1,10 @@ import pytest + from mantaray_py import add @pytest.mark.parametrize( - "a,b,result", + 'a,b,result', [ (0, 0, 0), (1, 1, 2),