refactor(client): unify HTTP clients on a shared http_client core (#46)#54
Merged
Conversation
The four camera client variants each duplicated ~15 helper functions (config loading, server discovery, TFLite interpreters, the binary protocol/payload, registration, split inference, result upload) — a fix in http_client.py had to be replicated in four files. Make http_client.py the single source of truth and reduce the camera variants to thin wrappers that import the shared logic and keep only their own frame source and capture loop: - http_clientCAMlaptop / http_clientCAMpi: OpenCV webcam / Picamera2 loops - http_clientCAMlaptopBench / http_clientCAMpiBench: same, plus CLI overrides for benchmark sweeps (--id/--model/--res) and profiler export on shutdown Add http_client.set_model_config() so the benchmark variants can override the TFLite folder / input resolution (with submodel-prefix and layer auto-detection) before interpreters are preloaded. Hardware-only imports (cv2, picamera2) are guarded so the modules load for tooling off-device and fail with a clear error at camera open. The camera capture loops are preserved verbatim; only the duplicated helpers were removed (~2,300 fewer duplicated lines). Existing tests that import http_client pass unchanged.
uv otherwise selects Python 3.14 (requires-python is >=3.13 with no upper bound), but tensorflow only ships wheels up to cp313, so 'uv sync --frozen' fails to resolve. Pinning 3.13 makes CI (and local dev) use a Python that has tensorflow wheels. Repo-wide fix; also unblocks main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #46 — the five HTTP clients duplicated ~15 helper functions each, so a fix
in
http_client.pyhad to be replicated across four files.This PR makes
http_client.pythe single source of truth and reduces the fourcamera variants to thin wrappers that import the shared logic and keep only
their own frame source + capture loop.
Approach (safe / verifiable)
Per the agreed scope, this is the shared-core approach, not a full
strategy-pattern rewrite: the camera capture loops (OpenCV / Picamera2) and the
benchmark loops are preserved verbatim — only the duplicated helpers were
removed. This keeps the untestable hardware paths byte-for-byte identical.
http_client.py: unchanged public API; addsset_model_config()so thebenchmark variants can override the TFLite folder / input resolution (with
submodel-prefix and layer auto-detection) before interpreters preload.
http_clientCAMlaptop/http_clientCAMpi: webcam / Picamera2 wrappers.http_clientCAMlaptopBench/http_clientCAMpiBench: same + CLI overrides(
--id/--model/--res) and profiler export on shutdown.Config overrides are applied before importing the shared constants, so each
wrapper's
main()body is used unchanged. Hardware-only imports (cv2,picamera2) are guarded so the modules load for tooling/analysis off-device andfail with a clear error only at camera open.
Impact
client-*extra already includes everythinghttp_clientneeds; the added coupling is a co-located source import only.Verification
py_compileon all five client files.pyflakes: no undefined names (every shared reference is imported); the onlyremaining note is a pre-existing verbatim debug f-string.
http_clientverified to exist;set_device_id/set_model_configsanity-checked.--extra test --extra server): 174 passed, 2 skipped. The onefailure (
test_dependency_profiles::test_tensorflow_uses_platform_specific_supported_versions)is pre-existing and unrelated — it expects platform-markered
tensorflowpins in
pyproject.toml, which this PR does not touch.Not covered
The camera hardware paths (OpenCV webcam, Picamera2) cannot be exercised in CI. A
follow-up to fully unify the
main()loops behind aFrameSourcestrategy can bedone later with hardware available.