Conversation
Introduces get_int() to parse integer environment variables, warning and falling back to None on invalid values instead of raising. This lays the groundwork for configuring a custom uiautomator2 server port.
U2AndroidDriver now accepts an optional port and forwards it to u2.connect_usb, letting connect_usb validate and raise on an invalid port itself rather than duplicating that check here.
AndroidProvider gains a port option that it forwards to U2AndroidDriver instances it creates. If a non-U2 driver_class is configured alongside a port, warn and ignore the port rather than failing, since only U2AndroidDriver knows what to do with it.
Exposes the custom uiautomator2 port support added in AndroidProvider and U2AndroidDriver as a user-facing environment variable, threading it through every place uiautodev builds an AndroidProvider, and documents it in the README alongside the existing adb driver toggle.
Custom uiautomator2 ports require uiautomator2>=3.6.0. Bumping the pyproject.toml constraint lets uiautomator2's own dependency resolution enforce the minimum version, so uiautodev doesn't need to parse or compare version strings at runtime.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #76 +/- ##
==========================================
+ Coverage 49.08% 50.34% +1.26%
==========================================
Files 36 39 +3
Lines 2522 2582 +60
==========================================
+ Hits 1238 1300 +62
+ Misses 1284 1282 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds support for connecting to a uiautomator2 server running on a non-default port by threading an optional port through the Android driver/provider stack and exposing it via UIAUTODEV_U2_PORT.
Changes:
- Introduces
get_int()env parsing and addsEnvironment.UIAUTODEV_U2_PORT. - Threads optional
portthroughAndroidProvider→U2AndroidDriver→u2.connect_usb(...), and wires it into app/CLI/case entrypoints. - Updates dependency constraint (
uiautomator2>=3.6.0) and documents the new env var; adds unit tests for env parsing and port forwarding.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| uiautodev/utils/envutils.py | Adds get_int() helper and UIAUTODEV_U2_PORT environment binding. |
| uiautodev/provider.py | Adds optional port to AndroidProvider and forwards/warns based on driver class. |
| uiautodev/driver/android/u2_driver.py | Allows U2AndroidDriver to pass a custom port to u2.connect_usb. |
| uiautodev/cli.py | Wires Environment.UIAUTODEV_U2_PORT into the Android CLI provider. |
| uiautodev/case.py | Wires Environment.UIAUTODEV_U2_PORT into the case runner provider. |
| uiautodev/app.py | Wires Environment.UIAUTODEV_U2_PORT into the FastAPI app’s Android provider. |
| tests/test_envutils.py | Adds unit tests for get_int(). |
| tests/test_u2_driver.py | Adds unit tests verifying U2AndroidDriver forwards/omits port. |
| tests/test_provider.py | Adds unit test verifying warning when port is ignored for non-U2 driver class. |
| README.md | Documents UIAUTODEV_U2_PORT. |
| pyproject.toml | Bumps uiautomator2 minimum version to support custom-port connections. |
| uiautodev/remote/scrcpy3.py | Import reordering within stream_to_websocket. |
| uiautodev/remote/pipe.py | Formatting-only change (blank line). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def get_int(name: str) -> Optional[int]: | ||
| value = os.getenv(name) | ||
| if not value: | ||
| return None | ||
| try: | ||
| return int(value) | ||
| except ValueError: | ||
| logger.warning("Ignoring environment variable %s=%r: not a valid integer", name, value) | ||
| return None | ||
|
|
||
|
|
||
| class Environment: | ||
| UIAUTODEV_MOCK = is_enabled("UIAUTODEV_MOCK") | ||
| UIAUTODEV_U2_PORT = get_int("UIAUTODEV_U2_PORT") |
There was a problem hiding this comment.
I made the decision to not validate this here since it does get validated in uiautomator2. I can also validate it here.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@codeskyblue This is ready for your review. Thanks! |
Summary
U2AndroidDriverandAndroidProviderUIAUTODEV_U2_PORTenvironment variable, wired into the app, CLI, andcase.pyprovidersuiautomator2>=3.6.0, which is required for custom-port supportCloses #75
Test plan
tests/test_envutils.pycovers the newget_int()helpertests/test_u2_driver.pycoversU2AndroidDriverforwarding the port toconnect_usbtests/test_provider.pycoversAndroidProviderthreading the port through, and warning/ignoring it for non-U2 driver classes🤖 Generated with Claude Code