-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add man page support for uv tool #16549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add UV_TOOL_MAN_DIR as highest priority override for man page installation directory. Also adds UV_TOOL_BIN_DIR constant and NoManpageDirectory error variant for consistency. Resolves directory resolution fallback chain: 1. UV_TOOL_MAN_DIR (new, highest priority) 2. UV_TOOL_BIN_DIR/../share/man 3. XDG_BIN_HOME/../share/man 4. XDG_DATA_HOME/man 5. HOME/.local/share/man
Display man pages alongside executables in `uv tool list` and `uv tool list --show-paths` output. Man pages are shown with their section prefix (e.g., man6/pycowsay.6).
Clean up empty man page section directories (e.g., man6/) after removing the last man page from that section during tool uninstall. Operation is best-effort and non-blocking.
Add 12 new tests covering: - UV_TOOL_MAN_DIR environment variable - Environment variable fallback chain (UV_TOOL_BIN_DIR, XDG_DATA_HOME, HOME) - Man page display in tool list (with and without --show-paths) - Man page persistence across upgrades - Force flag behavior with man pages Total test coverage: 64 tests (38 install + 11 upgrade + 9 list + 6 uninstall) Note: Multi-section man page testing is documented as limited due to lack of suitable test packages. The code correctly handles multiple sections via iteration, validated by code review.
Add comprehensive documentation: - User guide (docs/guides/tools/man-pages.md) - Environment variable reference (UV_TOOL_MAN_DIR) - Package developer guide for including man pages - Changelog entry for v0.4.7 Documents the 5-level directory resolution fallback chain, troubleshooting steps, and platform-specific behavior (symlinks on Unix, file copy on Windows).
|
I don't think we can review this, the LLM doesn't follow our code style and it's clear that it doesn't reason through decisions, so we'd have to revalidate all the logic again anyway. Shipping at the scale of uv means hitting a lot of edge cases and design decisions becoming loadbearing once shipped. uv also has a lot of specific idioms and coding patterns due to its size and requirements, which LLMs ignore. Sorry but I think we can't use claude code (alone) to make progress on this problem. |
Add man page support for
uv toolSummary
This PR revives and completes the excellent work started by @eth3lbert in #7171, implementing automatic man page installation support for
uv toolcommands to achieve feature parity with pipx.When installing Python tools with
uv tool install, any man pages provided by the package are automatically discovered from the wheel's RECORD file, installed to an appropriate system directory, and managed alongside the tool's lifecycle (install, upgrade, uninstall).Implementation Details
Core Functionality
Man pages are discovered from package RECORD files at paths matching:
Installation behavior:
replace_symlink()(prevents TOCTOU attacks)uv-receipt.tomlwith backward compatibility (optional field)Directory Resolution
Five-level fallback chain for installation directory (highest to lowest priority):
$UV_TOOL_MAN_DIR(new) - Explicit override$UV_TOOL_BIN_DIR/../share/man- Adjacent to tool binaries$XDG_BIN_HOME/../share/man- XDG Base Directory spec$XDG_DATA_HOME/man- XDG data directory$HOME/.local/share/man- Default fallbackThis approach follows standard Unix conventions and provides maximum flexibility while maintaining sensible defaults.
Architecture
Uses a
Resource<T>enum abstraction to uniformly handle both executables and man pages throughout the discovery and installation pipeline:This design enables clean separation of concerns while remaining extensible for future resource types (shell completions, systemd units, etc.).
Additions Beyond Original PR
Building on @eth3lbert's foundation, this PR adds:
1. Environment Variable Support ✨
2. Tool List Integration ✨
uv tool listoutput alongside executables--show-pathsflag showing full man page paths3. Security Hardening 🔒
..components4. Comprehensive Testing 🧪
5. Complete Documentation 📚
For Users
docs/guides/tools/man-pages.md:For Package Developers
docs/guides/publish.md:Environment Variables Reference (
docs/configuration/environment.md):Changelog (
CHANGELOG.md):Design Decisions
Following pipx as a reference implementation (as suggested in the original issue):
Testing
Integration Tests
All tests follow uv's established patterns using real PyPI packages:
Test Coverage:
Note on Multi-Section Testing:
Testing packages with multiple man page sections (e.g., man1, man5, man7) is documented as limited due to lack of suitable test packages in PyPI. The code correctly handles multiple sections via iteration, validated by code review and manual testing.
Manual Verification
Tested complete workflows with real packages:
Backward Compatibility
manpagesfield handled gracefully (defaults to empty)Performance
Man page discovery and installation adds minimal overhead:
Negligible impact on typical tool operations.
Platform Support
~/.local/share/man/~/.local/share/man/Windows users can access man pages via Git Bash, MSYS2, or Windows Subsystem for Linux.
Code Quality
cargo fmt- All code properly formattedcargo clippy --all-targets --all-features -- -D warnings- Zero warningsExamples
Basic Usage
Custom Installation Directory
Tool Listing
Package Developer Guidance
Our documentation now includes comprehensive guidance for package authors on including man pages in their packages, with examples for all major build systems:
Directory Structure:
Build System Examples:
See
docs/guides/publish.mdanddocs/guides/tools/man-pages.mdfor complete details.Related Issues & PRs
uv toolshould support man pages #4731 - Original feature request (14 👍, "help wanted" label)uv tool#7171 - Original draft by @eth3lbertAcknowledgments
Huge thanks to @eth3lbert for the original implementation and architectural foundation. This PR completes that work with the requested enhancements, comprehensive testing, security hardening, and full documentation.
Checklist
Full disclosure; I've used Claude Code to assist me in this PR as I'm not very familiar with Rust, but really wanted this feature to assist me with publishing man pages with a couple of my python packages. I apologise in advance if this is undesirable here and for any issues in the implementation, but I welcome any and all feedback!