Skip to content

Commit b3933d5

Browse files
authored
Add async clients support (#326)
* feat: Async functions support for the existing backends; Additional tests; Documentation update * feat: Class async methods tests * Organize test directories by cache backend; Add async pickle and memory tests * fix: Attempt to fix the Mongo versioning across multiple versions of Mongo driver / server * fix: Level code coverage
1 parent 66bd714 commit b3933d5

43 files changed

Lines changed: 1870 additions & 135 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@ backend = _update_with_defaults(backend, "backend")
9191
mongetter = _update_with_defaults(mongetter, "mongetter")
9292
if callable(mongetter):
9393
backend = "mongo"
94-
...
94+
95+
if backend == "pickle":
96+
core = _PickleCore(...)
97+
elif backend == "mongo":
98+
core = _MongoCore(...)
99+
elif backend == "memory":
100+
core = _MemoryCore(...)
101+
elif backend == "sql":
102+
core = _SQLCore(...)
95103
elif backend == "redis":
96104
core = _RedisCore(
97105
hash_func=hash_func,

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ jobs:
118118
- name: Unit tests (SQL/Postgres)
119119
if: matrix.backend == 'postgres'
120120
env:
121-
SQLALCHEMY_DATABASE_URL: postgresql://testuser:testpass@localhost:5432/testdb
121+
SQLALCHEMY_DATABASE_URL: postgresql+psycopg://testuser:testpass@localhost:5432/testdb
122122
run: pytest -m sql --cov=cachier --cov-report=term --cov-report=xml:cov.xml
123123

124124
- name: Start Redis in docker

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repos:
2323
- id: detect-private-key
2424

2525
- repo: https://github.com/crate-ci/typos
26-
rev: v1
26+
rev: v1.43.1
2727
hooks:
2828
- id: typos
2929
# empty to do not write fixes
@@ -55,7 +55,7 @@ repos:
5555
args: ["--print-width=79"]
5656

5757
- repo: https://github.com/astral-sh/ruff-pre-commit
58-
rev: v0.14.10
58+
rev: v0.15.0
5959
hooks:
6060
# use black formatting
6161
- id: ruff-format
@@ -73,11 +73,11 @@ repos:
7373
files: "src/.*"
7474

7575
- repo: https://github.com/tox-dev/pyproject-fmt
76-
rev: v2.11.1
76+
rev: v2.12.1
7777
hooks:
7878
- id: pyproject-fmt
7979
additional_dependencies: [tox]
8080
- repo: https://github.com/abravalheri/validate-pyproject
81-
rev: v0.24.1
81+
rev: v0.25
8282
hooks:
8383
- id: validate-pyproject

AGENTS.md

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ ______________________________________________________________________
112112
- **Others:** Memory, MongoDB, SQL, Redis
113113
- **Adding a backend:** Implement in `src/cachier/cores/`, subclass `BaseCore`, add tests with appropriate markers, update docs, and CI matrix if needed.
114114
- **Optional dependencies:** Code/tests must gracefully skip if backend deps are missing. Install backend-specific deps via `tests/requirements_*.txt`.
115-
- **Requirements files:** `tests/sql_requirements.txt`, `tests/redis_requirements.txt` for backend-specific dependencies.
115+
- **Requirements files:** `tests/requirements_mongodb.txt`, `tests/requirements_postgres.txt`, `tests/requirements_redis.txt` for backend-specific dependencies.
116116

117117
### 3. **Decorator Usage**
118118

@@ -167,7 +167,15 @@ backend = _update_with_defaults(backend, "backend")
167167
mongetter = _update_with_defaults(mongetter, "mongetter")
168168
if callable(mongetter):
169169
backend = "mongo"
170-
...
170+
171+
if backend == "pickle":
172+
core = _PickleCore(...)
173+
elif backend == "mongo":
174+
core = _MongoCore(...)
175+
elif backend == "memory":
176+
core = _MemoryCore(...)
177+
elif backend == "sql":
178+
core = _SQLCore(...)
171179
elif backend == "redis":
172180
core = _RedisCore(
173181
hash_func=hash_func,
@@ -399,7 +407,7 @@ ______________________________________________________________________
399407
- **Build package:** `python -m build`
400408
- **Check docs:** `python setup.py checkdocs`
401409
- **Run example:** `python examples/redis_example.py`
402-
- **Update requirements:** Edit `tests/requirements_*.txt` as needed (sql_requirements.txt, redis_requirements.txt).
410+
- **Update requirements:** Edit `tests/requirements_*.txt` as needed (`requirements_mongodb.txt`, `requirements_postgres.txt`, `requirements_redis.txt`).
403411

404412
### Local Testing with Docker
405413

@@ -528,25 +536,25 @@ ______________________________________________________________________
528536

529537
## 🧭 Quick Reference
530538

531-
| Task | Command/Location |
532-
| -------------------------- | ---------------------------------- |
533-
| Run all tests | `pytest` |
534-
| Run backend-specific tests | `pytest -m <backend>` |
535-
| Test multiple backends | `pytest -m "redis or sql"` |
536-
| Exclude backends | `pytest -m "not mongo"` |
537-
| Lint | `ruff check .` |
538-
| Type check | `mypy src/cachier/` |
539-
| Format code | `ruff format .` |
540-
| Build package | `python -m build` |
541-
| Check docs | `python setup.py checkdocs` |
542-
| Backend requirements | `tests/sql_requirements.txt`, etc. |
543-
| Main decorator | `src/cachier/core.py` |
544-
| Backends | `src/cachier/cores/` |
545-
| Global config | `src/cachier/config.py` |
546-
| Tests | `tests/` |
547-
| Examples | `examples/` |
548-
| Documentation | `README.rst` |
549-
| Contributor guidelines | `.github/copilot-instructions.md` |
539+
| Task | Command/Location |
540+
| -------------------------- | --------------------------------- |
541+
| Run all tests | `pytest` |
542+
| Run backend-specific tests | `pytest -m <backend>` |
543+
| Test multiple backends | `pytest -m "redis or sql"` |
544+
| Exclude backends | `pytest -m "not mongo"` |
545+
| Lint | `ruff check .` |
546+
| Type check | `mypy src/cachier/` |
547+
| Format code | `ruff format .` |
548+
| Build package | `python -m build` |
549+
| Check docs | `python setup.py checkdocs` |
550+
| Backend requirements | `tests/requirements_*.txt` |
551+
| Main decorator | `src/cachier/core.py` |
552+
| Backends | `src/cachier/cores/` |
553+
| Global config | `src/cachier/config.py` |
554+
| Tests | `tests/` |
555+
| Examples | `examples/` |
556+
| Documentation | `README.rst` |
557+
| Contributor guidelines | `.github/copilot-instructions.md` |
550558

551559
______________________________________________________________________
552560

CLAUDE.md

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ ______________________________________________________________________
112112
- **Others:** Memory, MongoDB, SQL, Redis
113113
- **Adding a backend:** Implement in `src/cachier/cores/`, subclass `BaseCore`, add tests with appropriate markers, update docs, and CI matrix if needed.
114114
- **Optional dependencies:** Code/tests must gracefully skip if backend deps are missing. Install backend-specific deps via `tests/requirements_*.txt`.
115-
- **Requirements files:** `tests/sql_requirements.txt`, `tests/redis_requirements.txt` for backend-specific dependencies.
115+
- **Requirements files:** `tests/requirements_mongodb.txt`, `tests/requirements_postgres.txt`, `tests/requirements_redis.txt` for backend-specific dependencies.
116116

117117
### 3. **Decorator Usage**
118118

@@ -191,7 +191,15 @@ backend = _update_with_defaults(backend, "backend")
191191
mongetter = _update_with_defaults(mongetter, "mongetter")
192192
if callable(mongetter):
193193
backend = "mongo"
194-
...
194+
195+
if backend == "pickle":
196+
core = _PickleCore(...)
197+
elif backend == "mongo":
198+
core = _MongoCore(...)
199+
elif backend == "memory":
200+
core = _MemoryCore(...)
201+
elif backend == "sql":
202+
core = _SQLCore(...)
195203
elif backend == "redis":
196204
core = _RedisCore(
197205
hash_func=hash_func,
@@ -423,7 +431,7 @@ ______________________________________________________________________
423431
- **Build package:** `python -m build`
424432
- **Check docs:** `python setup.py checkdocs`
425433
- **Run example:** `python examples/redis_example.py`
426-
- **Update requirements:** Edit `tests/requirements_*.txt` as needed (sql_requirements.txt, redis_requirements.txt).
434+
- **Update requirements:** Edit `tests/requirements_*.txt` as needed (`requirements_mongodb.txt`, `requirements_postgres.txt`, `requirements_redis.txt`).
427435

428436
### Local Testing with Docker
429437

@@ -552,25 +560,25 @@ ______________________________________________________________________
552560

553561
## 🧭 Quick Reference
554562

555-
| Task | Command/Location |
556-
| -------------------------- | ---------------------------------- |
557-
| Run all tests | `pytest` |
558-
| Run backend-specific tests | `pytest -m <backend>` |
559-
| Test multiple backends | `pytest -m "redis or sql"` |
560-
| Exclude backends | `pytest -m "not mongo"` |
561-
| Lint | `ruff check .` |
562-
| Type check | `mypy src/cachier/` |
563-
| Format code | `ruff format .` |
564-
| Build package | `python -m build` |
565-
| Check docs | `python setup.py checkdocs` |
566-
| Backend requirements | `tests/sql_requirements.txt`, etc. |
567-
| Main decorator | `src/cachier/core.py` |
568-
| Backends | `src/cachier/cores/` |
569-
| Global config | `src/cachier/config.py` |
570-
| Tests | `tests/` |
571-
| Examples | `examples/` |
572-
| Documentation | `README.rst` |
573-
| Contributor guidelines | `.github/copilot-instructions.md` |
563+
| Task | Command/Location |
564+
| -------------------------- | --------------------------------- |
565+
| Run all tests | `pytest` |
566+
| Run backend-specific tests | `pytest -m <backend>` |
567+
| Test multiple backends | `pytest -m "redis or sql"` |
568+
| Exclude backends | `pytest -m "not mongo"` |
569+
| Lint | `ruff check .` |
570+
| Type check | `mypy src/cachier/` |
571+
| Format code | `ruff format .` |
572+
| Build package | `python -m build` |
573+
| Check docs | `python setup.py checkdocs` |
574+
| Backend requirements | `tests/requirements_*.txt` |
575+
| Main decorator | `src/cachier/core.py` |
576+
| Backends | `src/cachier/cores/` |
577+
| Global config | `src/cachier/config.py` |
578+
| Tests | `tests/` |
579+
| Examples | `examples/` |
580+
| Documentation | `README.rst` |
581+
| Contributor guidelines | `.github/copilot-instructions.md` |
574582

575583
______________________________________________________________________
576584

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ install-dev:
5252
install-all:
5353
pip install -e .[all]
5454
pip install -r tests/requirements.txt
55-
pip install -r tests/mongodb_requirements.txt
56-
pip install -r tests/redis_requirements.txt
57-
pip install -r tests/sql_requirements.txt
55+
pip install -r tests/requirements_mongodb.txt
56+
pip install -r tests/requirements_redis.txt
57+
pip install -r tests/requirements_postgres.txt
5858

5959
# Testing targets
6060
test:

README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Cachier supports a generic SQL backend via SQLAlchemy, allowing you to use SQLit
418418

419419
.. code-block:: python
420420
421-
@cachier(backend="sql", sql_engine="postgresql://user:pass@localhost/dbname")
421+
@cachier(backend="sql", sql_engine="postgresql+psycopg://user:pass@localhost/dbname")
422422
def my_func(x):
423423
return x * 2
424424
@@ -530,9 +530,9 @@ Each additional core (MongoDB, Redis, SQL) requires additional dependencies. To
530530

531531
.. code-block:: bash
532532
533-
pip install -r tests/mongodb_requirements.txt
534-
pip install -r tests/redis_requirements.txt
535-
pip install -r tests/sql_requirements.txt
533+
pip install -r tests/requirements_mongodb.txt
534+
pip install -r tests/requirements_redis.txt
535+
pip install -r tests/requirements_postgres.txt
536536
537537
Running the tests
538538
-----------------
@@ -661,8 +661,8 @@ Adding documentation
661661

662662
This project is documented using the `numpy docstring conventions`_, which were chosen as they are perhaps the most widely-spread conventions that are both supported by common tools such as Sphinx and result in human-readable docstrings (in my personal opinion, of course). When documenting code you add to this project, please follow `these conventions`_.
663663

664-
.. _`numpy docstring conventions`: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
665-
.. _`these conventions`: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
664+
.. _`numpy docstring conventions`: https://numpydoc.readthedocs.io/en/latest/format.html
665+
.. _`these conventions`: https://numpydoc.readthedocs.io/en/latest/format.html
666666

667667
Additionally, if you update this ``README.rst`` file, use ``python setup.py checkdocs`` to validate it compiles.
668668

pyproject.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ markers = [
181181
"asyncio: marks tests as async",
182182
]
183183

184+
[tool.coverage.report]
185+
show_missing = true
186+
# Regexes for lines to exclude from consideration
187+
exclude_lines = [
188+
"pragma: no cover", # Have to re-enable the standard pragma
189+
"raise NotImplementedError", # Don't complain if tests don't hit defensive assertion code:
190+
"if TYPE_CHECKING:", # Is only true when running mypy, not tests
191+
]
184192
# --- coverage ---
185193

186194
[tool.coverage.run]
@@ -192,11 +200,3 @@ omit = [
192200
"src/cachier/__init__.py",
193201
"**/scripts/**",
194202
]
195-
[tool.coverage.report]
196-
show_missing = true
197-
# Regexes for lines to exclude from consideration
198-
exclude_lines = [
199-
"pragma: no cover", # Have to re-enable the standard pragma
200-
"raise NotImplementedError", # Don't complain if tests don't hit defensive assertion code:
201-
"if TYPE_CHECKING:", # Is only true when running mypy, not tests
202-
]

scripts/README-local-testing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ make services-start
107107
# Run tests manually
108108
CACHIER_TEST_HOST=localhost CACHIER_TEST_PORT=27017 CACHIER_TEST_VS_DOCKERIZED_MONGO=true \
109109
CACHIER_TEST_REDIS_HOST=localhost CACHIER_TEST_REDIS_PORT=6379 CACHIER_TEST_VS_DOCKERIZED_REDIS=true \
110-
SQLALCHEMY_DATABASE_URL="postgresql://testuser:testpass@localhost:5432/testdb" \
110+
SQLALCHEMY_DATABASE_URL="postgresql+psycopg://testuser:testpass@localhost:5432/testdb" \
111111
pytest -m "mongo or redis or sql"
112112

113113
# Stop all services
@@ -146,7 +146,7 @@ The script automatically sets the required environment variables:
146146

147147
### SQL/PostgreSQL
148148

149-
- `SQLALCHEMY_DATABASE_URL=postgresql://testuser:testpass@localhost:5432/testdb`
149+
- `SQLALCHEMY_DATABASE_URL=postgresql+psycopg://testuser:testpass@localhost:5432/testdb`
150150

151151
## Prerequisites
152152

scripts/docker-compose.all-cores.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ networks:
7676
# docker-compose -f scripts/docker-compose.all-cores.yml up -d
7777
# CACHIER_TEST_HOST=localhost CACHIER_TEST_PORT=27017 CACHIER_TEST_VS_DOCKERIZED_MONGO=true \
7878
# CACHIER_TEST_REDIS_HOST=localhost CACHIER_TEST_REDIS_PORT=6379 CACHIER_TEST_VS_DOCKERIZED_REDIS=true \
79-
# SQLALCHEMY_DATABASE_URL="postgresql://testuser:testpass@localhost:5432/testdb" \
79+
# SQLALCHEMY_DATABASE_URL="postgresql+psycopg://testuser:testpass@localhost:5432/testdb" \
8080
# pytest -m "mongo or redis or sql"
8181
# docker-compose -f scripts/docker-compose.all-cores.yml down

0 commit comments

Comments
 (0)