bazel-contrib / bazel-contrib/rules_python

allow py_zipapp to not include the python runtime

Offen
#3,805 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
core-rules type: feature request
Vorherrschende Sprache
Starlark
Sterne
688
Forks
721
Ø Merge
15 Std. 7 Min.
Gemergte PRs (30 T.)
76

Beschreibung

The gist of the feature request is to allow using py_zipapp to create a zipapp that doesn't include the python runtime. The reason is because the runtime is large, and if you're using e.g. docker to provide the runtime separately, then the bundled runtime is unwanted overhead.

Not including the runtime files is trivial: just don't include those depsets of files when creating the zip.

However, the resulting zip isn't functional. This is because, under the hood, a venv layout is used, which expects `bin/python` to point to the runtime. But if the runtime is being provided externally, it doesn't have a play to point to.

There's 3 options I can think of:

(1) Use runtime_env_toolchain. It has some hacks/tricks to use a shell script as bin/python, but still act as a venv interpreter. Its fragile though, relying on undocumented python behavior.

(2) Lookup python at runtime and recreate venv at runtime. The logic for this already exists in one of the bootstraps (not sure if its in the zip one, though).

(3a) Write a relative symlink that "escapes" the zip file tree. Then its up to the user to ensure that path exists and points to a usable python.

(3b) Write an absolute symlink, i.e. make use of the "platform interpreter" feature. Then it's up to the user to ensure that path exists and points to a usable python.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne bei der Implementierung von py_zipapp und untersuche deren venv-Layout und depsets für Laufzeitdateien. Vergleiche die vorhandene Bootstrap-Logik mit dem Verhalten von runtime_env_toolchain, ermittle dann, welche Option für eine externe Laufzeit unterstützt wird, und überprüfe, dass die resultierende Zipapp ohne gebündelte Laufzeitdateien ausgeführt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
build-system
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Aktiv
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.