Skip to content

refactor(client): unify HTTP clients on a shared http_client core (#46)#54

Merged
lbedogni merged 2 commits into
mainfrom
feature/sciot-046-unify-http-clients
Jul 10, 2026
Merged

refactor(client): unify HTTP clients on a shared http_client core (#46)#54
lbedogni merged 2 commits into
mainfrom
feature/sciot-046-unify-http-clients

Conversation

@ff225

@ff225 ff225 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #46 — the five HTTP clients duplicated ~15 helper functions each, so a fix
in http_client.py had to be replicated across four files.

This PR makes http_client.py the single source of truth and reduces the four
camera 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; adds set_model_config() so the
    benchmark 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 and
fail with a clear error only at camera open.

Impact

  • ~2,300 fewer duplicated lines across the four camera variants.
  • A fix in a shared helper now applies to every client at once.
  • No dependency changes: each client-* extra already includes everything
    http_client needs; the added coupling is a co-located source import only.

Verification

  • py_compile on all five client files.
  • All four wrappers import cleanly in a dev env without the hardware extras.
  • pyflakes: no undefined names (every shared reference is imported); the only
    remaining note is a pre-existing verbatim debug f-string.
  • Every name imported from http_client verified to exist; set_device_id /
    set_model_config sanity-checked.
  • Test suite (--extra test --extra server): 174 passed, 2 skipped. The one
    failure (test_dependency_profiles::test_tensorflow_uses_platform_specific_supported_versions)
    is pre-existing and unrelated — it expects platform-markered tensorflow
    pins 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 a FrameSource strategy can be
done later with hardware available.

ff225 added 2 commits July 10, 2026 10:15
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.
@lbedogni lbedogni merged commit f01f485 into main Jul 10, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify the 5 duplicated HTTP clients

2 participants