Skip to content

Desktop: find and stage PYTHONHOME beside a native-image executable (#246) - #247

Merged
b-re-w merged 3 commits into
developfrom
feat/native-image-python-home
Oct 17, 2026
Merged

b-re-w merged 3 commits into
developfrom
feat/native-image-python-home

Conversation

@b-re-w

@b-re-w b-re-w commented Oct 17, 2026

Copy link
Copy Markdown
Member

Closes #246

Feature added (SPEC L-9).

  • Run time. PackagedPythonHome.resolve has a fourth source. Inside a GraalVM native image only (org.graalvm.nativeimage.imagecode == runtime, read as a property, with no GraalVM SDK dependency), it uses <directory of the executable>/python-multiplatform-home when that directory exists. It then goes through L-3's check, Py_SetPythonHome and the libpython lookup like the other packaged sources. The executable is a lambda, evaluated only inside a native image: ProcessHandle is never asked on a JVM, and never on Android, which lacks it on older versions; a test pins that.
  • Build. The plugin task stageNativeImagePythonHome (a Sync) copies the same pruned prefix Compose packaging gets into <pythonBindings.nativeImageDirectory>/python-multiplatform-home. It copies nothing and stages nothing unless that directory is set.

Test added (red first: the plugin test failed to compile, Unresolved reference: nativeImageDirectory):

  • PM/desktopTest/.../PackagedPythonHomeTest: 4 new tests, 17 in total.
  • GP/PackagedPythonHomeTest: 2 new tests, 10 in total.

Verification (local):

  • :python-multiplatform:desktopTest: 625, 0 failed, 1 skipped.
  • :python-multiplatform-gradle-plugin:test: 323, with the 1 environment-only AcquiredHeaderVersionTest failure.
  • compileDebugKotlinAndroid: compiles.

The end-to-end use, a native image started from an empty directory, is the next PR: the notebook E2E as a native image (#191 milestone 1).

Inside a GraalVM native image, the prefix beside the executable is the
fourth packaged source, and stageNativeImagePythonHome copies it there
when pythonBindings.nativeImageDirectory is set.
Library: a native image finds python-multiplatform-home beside its
executable; a JVM ignores a directory beside java and never asks for
the executable; no directory resolves to nothing; the environment
still wins. Plugin: stageNativeImagePythonHome copies the pruned prefix
into the native-image directory after stagePythonHome, and copies
nothing when the directory is unset.
PackagedPythonHome.resolve takes the executable lazily and, inside a
native image only (org.graalvm.nativeimage.imagecode = runtime), uses
<its directory>/python-multiplatform-home when it exists. The plugin's
stageNativeImagePythonHome Sync copies the same pruned prefix there.

Closes #246
@b-re-w
b-re-w merged commit 3ad1e08 into develop Oct 17, 2026
@b-re-w
b-re-w deleted the feat/native-image-python-home branch October 17, 2026 12:37
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