Add a trampoline variant that just executes python (#8637)

Currently, our trampoline is used to convert `<command> [args]` to
`python <command> [args]` for script entrypoints installed into virtual
environments. For #8458, it'd be nice to convert a shim `python3.12
[args]` to `python [args]`. Here, we modify the trampolines to support
this use-case.

The only change we really need here is to avoid injecting `<command>`
into the child process. We change the "magic number" at the end of the
trampoline executables from `UVUV` to `UVSC` and `UVPY` which define
"script" and "python" variants to the trampoline. We then omit the
`<command>` injection in the latter case. We also omit writing the zip
script payload.

To support construction of the new variant, a new
`uv-trampoline-builder` crate is introduced — this avoids requirements
on `uv-install-wheel` in future work. I also use `uv-trampoline-builder`
to consolidate some of the test setup for `uv-trampoline`.

There should be no backwards compatibility concerns, since trampolines
are fully self-referential.

I rebased to fix the commits at the end, as this took many iterations to
get working via CI. This should roughly be reviewable by commit if you
prefer.
This commit is contained in:
Zanie Blue
2024-10-29 09:21:15 -05:00
committed by GitHub
parent 94ae79d90d
commit c335dc5e5d
19 changed files with 564 additions and 474 deletions
+10 -3
View File
@@ -396,6 +396,11 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
workspaces: ${{ github.workspace }}/crates/uv-trampoline
- name: "Test committed binaries"
working-directory: ${{ github.workspace }}
run: |
rustup target add ${{ matrix.target-arch }}-pc-windows-msvc
cargo test -p uv-trampoline-builder --target ${{ matrix.target-arch }}-pc-windows-msvc
# Build and copy the new binaries
- name: "Build"
working-directory: ${{ github.workspace }}/crates/uv-trampoline
@@ -403,9 +408,11 @@ jobs:
cargo build --target ${{ matrix.target-arch }}-pc-windows-msvc
cp target/${{ matrix.target-arch }}-pc-windows-msvc/debug/uv-trampoline-console.exe trampolines/uv-trampoline-${{ matrix.target-arch }}-console.exe
cp target/${{ matrix.target-arch }}-pc-windows-msvc/debug/uv-trampoline-gui.exe trampolines/uv-trampoline-${{ matrix.target-arch }}-gui.exe
- name: "Test"
working-directory: ${{ github.workspace }}/crates/uv-trampoline
run: cargo test --target ${{ matrix.target-arch }}-pc-windows-msvc --test *
- name: "Test new binaries"
working-directory: ${{ github.workspace }}
run: |
# We turn off the default "production" test feature since these are debug binaries
cargo test -p uv-trampoline-builder --target ${{ matrix.target-arch }}-pc-windows-msvc --no-default-features
typos:
runs-on: ubuntu-latest