Skip to content

Add xpython command - #90

Merged
freakboy3742 merged 30 commits into
mainfrom
xpython
Sep 25, 2026
Merged

freakboy3742 merged 30 commits into
mainfrom
xpython

Conversation

@freakboy3742

Copy link
Copy Markdown
Member

Adds an xpython entry point.

Simplest usage is xpython --platform ios --src tests -d otherpkg --group dev -- -m pytest tests

This will:

  • create a clone of a testbed project
  • copy the tests folder into the testbed project
  • Install otherpkg as a dependency
  • Install the packages in the dev dependency group
  • Build the testbed project
  • Run the equivalent of python -m pytest tests, but in the emulator environment.

PR Checklist:

  • I will abide by the BeeWare Code of Conduct
  • I have read and have followed the CONTRIBUTING.md file
  • This PR was generated or assisted using an AI tool
    Assisted-by: Claude Sonnet 5

Two bugs surfaced by live end-to-end testing against a real network and
downloaded Python builds (mocked unit tests couldn't catch either since
they mock subprocess.run entirely):

1. xpython/platforms/ios.py hardcoded the literal string "python" when
   invoking the testbed clone/run driver scripts. This fails on any host
   (like this one) where only python3 is on PATH. Use sys.executable
   instead, since xpython already requires running under the same
   major.minor interpreter as the target build.

2. xpython/deps.py's install_requirements() ran pip inside a cross-platform
   venv without disabling the venv's sys.platform-patching shim first.
   With the shim active, CPython's ctypes special-cases
   sys.platform in ("android", "cygwin") to load pythonapi via dlopen(),
   which pip's vendored rich library triggers during import, crashing pip
   on a host that isn't actually running on-device Android. Mirror the
   existing XBUILD_ENV=off pattern already used by xbuild/env.py's
   install_environment() and tests/live/test_xvenv.py to disable the shim
   while pip itself runs.

Verified live:
- iOS: xpython now gets past the testbed clone step and reaches
  xcodebuild build-for-testing (which then fails for an unrelated
  deployment-target/Xcode-version mismatch in this environment).
- Android: pip install now succeeds inside the cross-venv; failure moves
  to android.py's own SyntaxError (caused by /usr/bin/python3 3.9.6 being
  first on PATH, unrelated to this fix) -- well past the previous
  ctypes/dlopen crash during pip install.
…etup in main()

install_requirements() and ios.stage_and_run()'s testbed clone step can
raise subprocess.CalledProcessError. Previously this propagated out of
main() as an unhandled traceback instead of a clean _error() + exit(1),
inconsistent with how xvenv/xbuild handle expected failures and with
the design spec's error-handling section.

Also fix stale 'both commands' wording in the common-options doc now
that xpython makes three commands, not two.
Item 4 of the numbered behavior list claimed xpython always runs
'-m <module> <args...>' inside the testbed, which was only true for
the old iOS-only invocation shape. This contradicts the dedicated
'-- [args ...]' section below, which correctly documents that
Android also accepts -c <code> or no args (defaulting to -m test).
Point to that section instead of overclaiming.
@freakboy3742
freakboy3742 merged commit e1dfba9 into main Sep 25, 2026
22 checks passed
@freakboy3742
freakboy3742 deleted the xpython branch September 25, 2026 01:24
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