Skip to content

Comments

Add fallback parent process detection to uv tool update-shell#15356

Merged
zanieb merged 4 commits intoastral-sh:mainfrom
edrogers:ed/shell
Aug 18, 2025
Merged

Add fallback parent process detection to uv tool update-shell#15356
zanieb merged 4 commits intoastral-sh:mainfrom
edrogers:ed/shell

Conversation

@edrogers
Copy link
Contributor

Summary

Closes #15355

This PR adds a fallback mechanism to Shell::from_env() that inspects the parent process when shell environment variables are not available on Unix-like systems.

Currently, uv tool update-shell fails with "the current shell could not be determined" when environment variables like ZSH_VERSION, BASH_VERSION, or SHELL are not exported. This commonly occurs in automated environments such as GitHub Actions runners.

The fallback approach:

  1. Uses nix::unistd::getppid() to get the parent process ID
  2. Reads /proc/<ppid>/exe to determine the parent executable path
  3. Falls back to /proc/<ppid>/comm if the exe symlink fails
  4. Uses existing parse_shell_from_path() to identify the shell type

This maintains full backward compatibility - the fallback only activates when environment variables are unavailable and an error would otherwise occur.

Test Plan

Tested locally with:

env -u ZSH_VERSION -u SHELL PATH="/usr/bin:/bin" $(which cargo) run -- tool update-shell --verbose
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.30s
     Running `target/debug/uv tool update-shell --verbose`
DEBUG uv 0.8.11
DEBUG Ensuring that the executable directory is in PATH: /home/user/.local/bin
DEBUG Detected parent process ID: 4147396
DEBUG Parent process executable: /usr/bin/zsh
Updated configuration file: /home/user/.zshenv
Restart your shell to apply changes

@zanieb zanieb self-assigned this Aug 18, 2025
Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me. cc @geofft

@zanieb zanieb added the enhancement New feature or improvement to existing functionality label Aug 18, 2025
@edrogers
Copy link
Contributor Author

I've gotten a couple CI failures that appear to be infrastructure-related rather than code issues:

  • macOS smoketest: Network timeout downloading ruff (Failed to download distribution due to network timeout. Try increasing UV_HTTP_TIMEOUT (current value: 30s))
  • Docker build: Build infrastructure timeout (rpc error: code = Unavailable desc = error reading from server: read tcp ... connection timed out)

The core functionality tests pass and all code quality checks (clippy, formatting) are successful. Let me know if there's anything further I should do to prepare this PR for review.

@zanieb
Copy link
Member

zanieb commented Aug 18, 2025

Don't worry about those. GitHub is flaky today.

@zanieb zanieb merged commit 4b88b13 into astral-sh:main Aug 18, 2025
233 of 243 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 21, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.8.11` -> `0.8.12` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.8.12`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0812)

[Compare Source](astral-sh/uv@0.8.11...0.8.12)

##### Python

- Add 3.13.7
- Improve performance of zstd in Python 3.14

See the [python-build-standalone release notes](https://github.com/astral-sh/python-build-standalone/releases/tag/20250818) for details.

##### Enhancements

- Add an `aarch64-pc-windows-msvc` target for `python-platform` ([#&#8203;15347](astral-sh/uv#15347))
- Add fallback parent process detection to `uv tool update-shell` ([#&#8203;15356](astral-sh/uv#15356))
- Install non-build-isolation packages in a second phase ([#&#8203;15306](astral-sh/uv#15306))
- Add hint when virtual environments are included in source distributions ([#&#8203;15202](astral-sh/uv#15202))
- Add Docker images derived from `buildpack-deps:trixie`, `debian:trixie-slim`, `alpine:3.22` ([#&#8203;15351](astral-sh/uv#15351))

##### Bug fixes

- Reject already-installed wheels built with outdated settings ([#&#8203;15289](astral-sh/uv#15289))
- Skip interpreters that are not found on query ([#&#8203;15315](astral-sh/uv#15315))
- Handle dotted package names in script path resolution ([#&#8203;15300](astral-sh/uv#15300))
- Reject `match-runtime = true` for dynamic packages ([#&#8203;15292](astral-sh/uv#15292))

##### Documentation

- Document improvements to build-isolation setups ([#&#8203;15326](astral-sh/uv#15326))
- Fix reference documentation recommendation to use `uv cache clean` instead of `clear` ([#&#8203;15313](astral-sh/uv#15313))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS43Ni4wIiwidXBkYXRlZEluVmVyIjoiNDEuNzYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Have uv tool update-shell check parent process when environment variables aren't enough

3 participants