Skip to content

Drive the AVIS Academy web Sandbox - #19

Open
AmirmohammadZarif wants to merge 1 commit into
mainfrom
feat/web-sandbox
Open

AmirmohammadZarif wants to merge 1 commit into
mainfrom
feat/web-sandbox

Conversation

@AmirmohammadZarif

Copy link
Copy Markdown
Member

What this adds

The API can now drive the AVIS Academy web Sandbox (the simulator in the browser) from Python on the learner's own computer, in two styles:

  • Same code as the Sandbox editor: python -m avisengine my_driver.py runs a script with setup() and loop(). The car API is generated from the Sandbox's own module, so code moves between the browser and a laptop unchanged.
  • Existing classic scripts: car.connectSandbox() instead of car.connect(ip, port). Each getData() is one simulation step; getSpeed() stays in km/h.

The command prints a port and a six-digit pairing code. In the Sandbox, open Laptop Python, enter them and press Connect, then Run. The simulator waits for the script at every control step, so results do not depend on the computer's speed.

Desktop simulator use is unchanged (from avisengine import Car, car.connect(...)).

Security

The script listens on 127.0.0.1 only, accepts only AVIS Academy page origins, needs the pairing code, and serves one tab at a time. Graded practices always run in the browser.

Packaging

  • Package layout matching the published avisengine 0.1.3 wheel, now versioned 0.2.0 with a pyproject.toml (the 0.1.x build files were never committed).
  • Dependencies reduced to numpy, opencv-python, Pillow and websockets, with modern floors. PySocks, PyYAML, regex and requests were not imported anywhere; the old pins (numpy 1.18, OpenCV 4.2) do not install on current Python.

Tests and CI

  • 10 tests: both Sandbox styles, error tracebacks pointing at the user's line, reloading on each Run, wrong pairing codes, other websites refused, loop() running on the serving thread (needed for cv2.imshow on macOS), and the desktop protocol against a fake simulator.
  • CI pointed at a tests/ folder that did not exist; it now installs the package and runs the tests on Python 3.9 to 3.13.

Checked

  • Tests pass locally on Python 3.9 and 3.12; the wheel and sdist build.
  • A classic-style script drove the real Sandbox (local dev server): real camera frames, speed rising, clean stop.
  • cv2.imshow inside loop() works on macOS (it failed before loop() moved to the main thread).

After merging

Publish 0.2.0 to PyPI, then the Sandbox's Laptop Python panel can switch to pip install avisengine.

🤖 Generated with Claude Code

- Package layout matching the published avisengine wheel; version 0.2.0
  with pyproject.toml (the 0.1.x build files were never committed).
- Web Sandbox support: `python -m avisengine my_driver.py` runs the same
  setup()/loop() code as the Sandbox editor; `car.connectSandbox()` lets
  classic while-loop scripts drive it, one getData() per control step.
- The Sandbox API (_api.py) is generated from the Sandbox's own module.
- Local only: 127.0.0.1, Academy origins, six-digit pairing code.
- Modern dependency floors; unused ones dropped.
- Tests for the Sandbox link and the desktop protocol; CI fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant