Skip to content

Install versioned Python executables into the bin directory during uv python install#8458

Merged
zanieb merged 5 commits intomainfrom
zb/python-exec-dir
Oct 30, 2024
Merged

Install versioned Python executables into the bin directory during uv python install#8458
zanieb merged 5 commits intomainfrom
zb/python-exec-dir

Conversation

@zanieb
Copy link
Copy Markdown
Member

@zanieb zanieb commented Oct 22, 2024

Updates uv python install to link python3.x in the executable directory (i.e., ~/.local/bin) to the the managed interpreter path.

Includes

Remaining work

@zanieb zanieb added enhancement New feature or improvement to existing functionality breaking A breaking change labels Oct 22, 2024
@zanieb zanieb changed the base branch from main to zb/uv-dirs October 22, 2024 14:23
@zanieb zanieb changed the title zb/python exec dir Install versioned Python executables into the bin directory during uv python install Oct 22, 2024
@zanieb zanieb added this to the v0.5.0 milestone Oct 22, 2024
Base automatically changed from zb/uv-dirs to main October 22, 2024 16:33
@zanieb zanieb changed the base branch from main to tracking/050 October 22, 2024 16:55
@zanieb zanieb force-pushed the zb/python-exec-dir branch 4 times, most recently from b3f1ede to dc70ac5 Compare October 22, 2024 17:52
@zanieb zanieb temporarily deployed to uv-test-publish October 22, 2024 17:54 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/python-exec-dir branch from dc70ac5 to a5bae91 Compare October 22, 2024 18:19
@zanieb zanieb temporarily deployed to uv-test-publish October 22, 2024 18:22 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/python-exec-dir branch from a5bae91 to b188781 Compare October 22, 2024 18:57
@zanieb zanieb temporarily deployed to uv-test-publish October 22, 2024 19:00 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/python-exec-dir branch 2 times, most recently from 1396487 to 6bd04ee Compare October 22, 2024 22:25
@zanieb zanieb temporarily deployed to uv-test-publish October 22, 2024 22:28 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/python-exec-dir branch from 6bd04ee to 3157909 Compare October 22, 2024 22:43
@zanieb zanieb temporarily deployed to uv-test-publish October 22, 2024 22:46 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/python-exec-dir branch from 3157909 to cb814eb Compare October 22, 2024 22:57
Comment on lines -339 to -342
// Workaround for python-build-standalone v20241016 which is missing the standard
// `python.exe` executable in free-threaded distributions on Windows.
//
// See https://github.com/astral-sh/uv/issues/8298
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moved up, so executable always returns the existing executable for an installation and we ensure all the canonical names exist here.

Comment on lines +412 to +419
let canonical_names = &["python"];

for name in canonical_names {
let executable =
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactored for future changes.

@zanieb zanieb temporarily deployed to uv-test-publish October 22, 2024 22:59 — with GitHub Actions Inactive
@zanieb zanieb requested a review from charliermarsh October 22, 2024 23:06
@zanieb zanieb marked this pull request as ready for review October 22, 2024 23:06
zanieb added a commit that referenced this pull request Oct 29, 2024
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.
zanieb added a commit that referenced this pull request Oct 29, 2024
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.
zanieb added a commit that referenced this pull request Oct 29, 2024
Following #8458, we need to remove the installed Python executables on
`uv python uninstall`.

Needs Windows support still, but that approach will be different since
there won't be links.
zanieb added a commit that referenced this pull request Oct 29, 2024
Following #8458 we want to support showing the target directory in the
CLI
@zanieb zanieb temporarily deployed to uv-test-publish October 29, 2024 16:21 — with GitHub Actions Inactive
zanieb added a commit that referenced this pull request Oct 29, 2024
Following #8458, we need to remove the installed Python executables on
`uv python uninstall`.

Needs Windows support still, but that approach will be different since
there won't be links.
zanieb added a commit that referenced this pull request Oct 29, 2024
Following #8458 we want to support showing the target directory in the
CLI
@zanieb zanieb force-pushed the zb/python-exec-dir branch from c76ec88 to 783e70d Compare October 29, 2024 16:24
zanieb added a commit that referenced this pull request Oct 29, 2024
Following #8458, we need to remove the installed Python executables on
`uv python uninstall`.

Needs Windows support still, but that approach will be different since
there won't be links.
zanieb added a commit that referenced this pull request Oct 29, 2024
Following #8458 we want to support showing the target directory in the
CLI
@zanieb zanieb force-pushed the zb/python-exec-dir branch from 783e70d to 00873e2 Compare October 29, 2024 16:28
@zanieb zanieb temporarily deployed to uv-test-publish October 29, 2024 16:32 — with GitHub Actions Inactive
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per our conversation on Discord, I think it could make sense to gate this on preview.

Following #8458, we need to remove the installed Python executables on
`uv python uninstall`.

Needs Windows support still, but that approach will be different since
there won't be links.
@zanieb zanieb added preview Experimental behavior and removed breaking A breaking change labels Oct 30, 2024
@zanieb
Copy link
Copy Markdown
Member Author

zanieb commented Oct 30, 2024

Going to gate with preview and rebase onto main.

Following #8458 we want to support showing the target directory in the
CLI
@zanieb zanieb force-pushed the zb/python-exec-dir branch from 00873e2 to 7d2cf99 Compare October 30, 2024 13:41
@zanieb
Copy link
Copy Markdown
Member Author

zanieb commented Oct 30, 2024

Note this also gated to Unix pending #8663

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to existing functionality preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants