diff --git a/.gitignore b/.gitignore index 088ba6b..f7f73f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Generated by Cargo # will have compiled files and executables /target/ +*.so # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html @@ -8,3 +9,13 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + +# Python +.venv +.env +__pycache__ +.mypy-cache +.ruff-cache + +# IDE +.idea diff --git a/pyproject.toml b/pyproject.toml index 5cf426b..9530a0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "redis-rs" -requires-python = ">=3.7" +requires-python = ">=3.8" description = "Python wrapper for redis-rs" authors = [ { name = "Alexander Malev", email = "yttrium@somedev.ru" }, @@ -21,7 +21,6 @@ classifiers = [ "Framework :: AsyncIO", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -34,9 +33,29 @@ Issues = "https://github.com/aamalev/redis-rs-py/issues" Documentation = "https://github.com/aamalev/redis-rs-py#using" Changelog = "https://github.com/aamalev/redis-rs-py/releases" +[tool.mypy] +warn_redundant_casts = true +check_untyped_defs = true + +[tool.black] +line-length = 120 +target-version = [ + "py38", + "py39", + "py310", + "py311", +] + +[tool.ruff] +line-length = 120 + [tool.hatch.envs.default] dependencies = [ "maturin", + "mypy", + "black", + "ruff", + "isort", ] [tool.hatch.envs.default.scripts] @@ -44,9 +63,12 @@ build = [ "maturin develop", ] check = [ + "ruff redis_rs", + "mypy redis_rs", "cargo clippy", - "build", ] fmt = [ "cargo fmt", + "isort redis_rs", + "black redis_rs", ] diff --git a/redis_rs/__init__.py b/redis_rs/__init__.py new file mode 100644 index 0000000..2faf498 --- /dev/null +++ b/redis_rs/__init__.py @@ -0,0 +1 @@ +from .redis_rs import * diff --git a/redis_rs/__init__.pyi b/redis_rs/__init__.pyi new file mode 100644 index 0000000..b06a736 --- /dev/null +++ b/redis_rs/__init__.pyi @@ -0,0 +1,59 @@ +from typing import Dict, List, Literal, Optional, Union, overload + +class exceptions: + class PoolError(Exception): ... + class RedisError(Exception): ... + +Encoding = Union[ + Literal["utf-8"], + Literal["utf8"], + Literal["int"], + Literal["float"], +] + +Arg = Union[str, bytes, int, float] +Result = Union[bytes, str, int, float, dict, list] + +class Client: + def status(self) -> Dict: ... + async def __aenter__(self) -> "AsyncClient": ... + async def __aexit__(self, *args, **kwargs): ... + +class AsyncClient: + def status(self) -> Dict: ... + async def execute(self, *args: Arg, encoding: Optional[Encoding] = None) -> Result: ... + async def fetch_bytes(self, *args: Arg) -> bytes: ... + async def fetch_str(self, *args: Arg) -> str: ... + async def fetch_int(self, *args: Arg) -> int: ... + async def fetch_float(self, *args: Arg) -> float: ... + async def fetch_dict(self, *args: Arg, encoding: Optional[Encoding] = None) -> dict: ... + async def fetch_scores(self, *args: Arg) -> Dict[str, float]: ... + async def set(self, key: str, value: Arg): ... + async def get(self, key: str, *, encoding: Optional[Encoding] = None) -> Result: ... + async def hset(self, key: str, field: str, value: Arg): ... + async def hget(self, key: str, field: str, *, encoding: Optional[Encoding] = None) -> Result: ... + async def incr(self, key: str, delta: Union[None, int, float] = None) -> float: ... + async def lpush(self, key: str, value: Arg): ... + async def lpop(self, key: str, *, encoding: Optional[Encoding] = None) -> Result: ... + async def lrange( + self, + key: str, + start: int = 0, + stop: int = -1, + *, + encoding: Optional[Encoding] = None, + ) -> List[Result]: ... + @overload + async def xadd(self, stream: str, id: str, items: Dict[str, Arg]) -> Dict: ... + @overload + async def xadd(self, stream: str, items: Dict[str, Arg]) -> Dict: ... + @overload + async def xadd(self, stream: str, *args: Arg) -> Dict: ... + async def xread( + self, + streams: Dict[str, Union[str, Literal["$"], Literal[0]]], + *, + encoding: Optional[Encoding] = None, + ) -> Dict: ... + +def create_client(*args: str, max_size: Optional[int] = None, cluster: Optional[bool] = None) -> Client: ... diff --git a/redis_rs/py.typed b/redis_rs/py.typed new file mode 100644 index 0000000..e69de29