feat: make orjson an optional dependency (cachekit[json])#196
Conversation
|
Warning Review limit reached
More reviews will be available in 26 minutes and 10 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (11)
Walkthrough
ChangesMake orjson an optional dependency
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
c9485ce to
b996e4b
Compare
orjson backed only the non-default OrjsonSerializer, yet was a hard, eagerly-
imported dependency — unlike its structural twin ArrowSerializer, which is the
optional + lazy `cachekit[data]`. So `import cachekit` pulled orjson even when
only the default (MessagePack) serializer was ever used.
orjson now mirrors Arrow exactly:
- Moved from core dependencies to a new `json` optional extra (cachekit[json]);
kept in the dev dependency-group so tests/doctests/markdown-docs still resolve it.
- Lazy-loaded: SERIALIZER_REGISTRY["orjson"] is None; get_serializer("orjson")
and `from cachekit.serializers import OrjsonSerializer` resolve it on demand via
_get_orjson_serializer() + module __getattr__.
- orjson_serializer.py fails fast with a helpful install hint when orjson is
absent (mirrors arrow_serializer.py's pyarrow guard).
- get_serializer_info()'s optional-dep ImportError branch generalized (was
hardcoded to ArrowSerializer).
`import cachekit` no longer imports orjson — verified by a subprocess regression
guard; the default/std/auto path never needed it. Docs updated to note the
[json] extra (mirroring the [data] treatment).
BREAKING CHANGE: orjson is no longer installed by `pip install cachekit`. To use
the orjson serializer (serializer="orjson" or OrjsonSerializer), install
`cachekit[json]`. Without it, get_serializer("orjson") raises an ImportError with
an actionable install hint.
Patch coverage flagged the two optional-dep-absent paths the in-process suite cannot reach while orjson is installed: - get_serializer_info()'s generalized ImportError branch — now covered by a monkeypatch test asserting a missing orjson is labeled OrjsonSerializer (the mislabeling the generalization fixed), not the old hardcoded ArrowSerializer. - orjson_serializer.py's import guard — marked `# pragma: no cover`: it is only reachable without the [json] extra, and its behavior is already verified by the subprocess regression test in test_serializer_lazy_loading.py (matches how arrow_serializer.py's pyarrow guard is left uncovered).
b996e4b to
dee8428
Compare
…major) (#199) cachekit is still alpha (Development Status :: 3 - Alpha, version 0.x). Without bump-minor-pre-major, release-please escalates any BREAKING CHANGE straight to 1.0.0 — which is why the orjson optional-dependency change (#196) produced a "release 1.0.0" PR (#198). Set bump-minor-pre-major so that while the version is below 1.0.0, breaking changes bump the minor (0.10.1 -> 0.11.0) instead of the major. Once this lands on main, release-please recomputes the pending release PR to 0.11.0.
Why
orjsonbacked only the non-defaultOrjsonSerializer, yet was a hard, eagerly-imported dependency — soimport cachekitpulled orjson even when only the default (MessagePack) serializer was ever used. Its structural twin,ArrowSerializer, is already optional + lazy (cachekit[data]). This brings orjson into line.What changed
orjson now mirrors Arrow exactly:
pyproject.toml): moved orjson out of core[project.dependencies]into a newjsonoptional extra (cachekit[json]). Kept in thedevdependency-group so tests / doctests / markdown-docs still resolve it in CI.serializers/__init__.py):SERIALIZER_REGISTRY["orjson"]is nowNone;get_serializer("orjson")andfrom cachekit.serializers import OrjsonSerializerresolve it on demand via_get_orjson_serializer()+ module__getattr__. Removed the eager top-level import.orjson_serializer.py): guardsimport orjsonwith a helpfulImportError: ... requires the [json] extra: pip install 'cachekit[json]'(mirrorsarrow_serializer.py's pyarrow guard).get_serializer_info(): generalized its optional-dependencyImportErrorbranch (was hardcoded toArrowSerializer, would have mislabeled a missing orjson).[json]extra wherever orjson is presented as a serializer choice, mirroring the existing[data]treatment.Behavior
import cachekitno longer imports orjson (the default/std/auto path never needed it) — verified by a subprocess regression guard.cachekit+ the default serializer still work; onlyget_serializer("orjson")raises the actionable install error.Tests
tests/unit/test_serializer_lazy_loading.py: added orjson mechanism tests mirroring arrow (registry-None,_get_orjson_serializer,get_serializer,__getattr__,get_serializer_info) plus two subprocess guards — (1)import cachekitdoesn't pull orjson, (2) absent orjson yields the helpful[json]-extra error while the default serializer keeps working. Updatedtest_orjson_serializer.py's registry assertion to the new lazy (None) contract.Verification: full unit suite 1607 passed, 8 skipped; src doctests pass; markdown-docs pass (orjson present); ruff + basedpyright clean. Branched off current
main(f35d0cd, 0.10.1).orjsonis no longer installed bypip install cachekit. To use the orjson serializer (serializer="orjson"orOrjsonSerializer), installcachekit[json]. (Greenfield, pre-1.0 — flagged for the changelog so users know to add the extra.)Summary by CodeRabbit
cachekit[json]extra to be installed.orjson, including an actionable[json]install hint.