Skip to content

Conversation

@TonyHernandezAtMS
Copy link

@TonyHernandezAtMS TonyHernandezAtMS commented Nov 16, 2025

Description

Fixes broken Python venv symlinks after container restarts by mounting ~/.local/share/ to persist uv-managed Python installations.

Fixes #87

Problem

When uv creates a venv with --python-preference managed, it downloads Python to ~/.local/share/uv/python/. The venv contains symlinks pointing to this location, but since ~/.local/share/ was not mounted, the Python installation was lost on container exit, leaving broken symlinks.

Solution

Added mount for PROJECT_SLOT_DIR/.local/share in lib/docker.sh to persist uv-downloaded Python installations across container restarts.

+    # Mount .local/share for uv-managed Python installations
+    # uv downloads Python to ~/.local/share/uv/python/ which must persist across containers
+    mkdir -p "$PROJECT_SLOT_DIR/.local/share"
+    docker_args+=(-v "$PROJECT_SLOT_DIR/.local/share":/home/$DOCKER_USER/.local/share)

Testing

Tested on macOS with ml-tutorial project:

  1. ✅ Clean project, add python ml profiles
  2. ✅ First run: Python 3.14 downloads successfully (111 packages including torch, transformers, scikit-learn, pandas, numpy)
  3. ✅ Verified Python installation persists on host: ~/.claudebox/projects/.../6111fd25/.local/share/uv/python/cpython-3.14.0-linux-aarch64-gnu/
  4. ✅ Venv symlinks are valid and point to persisted Python
  5. ✅ Subsequent container starts: Python works correctly

Impact

  • Affects: python, ml, and datascience profiles
  • Compatibility: macOS and Linux
  • Breaking changes: None
  • Performance: Negligible (adds one directory mount)

Related Issues

This bug was introduced in commit 57fa079 when Python installation was moved from build-time to runtime.

Subsequent commits attempted to fix Python issues but missed the root cause:

  • 4fd05a8 - "Fix multiple issues: shell auth, Python/uv PATH..."
  • b2aedd9 - "Fix multiple issues with Python/uv, tmux activation..."
  • bcf4ee7 - "Add UV_PYTHON_MANAGED=1 environment variable"

Fixes broken Python venv symlinks after container restarts.

Problem:
When uv creates a venv with --python-preference managed, it downloads
Python to ~/.local/share/uv/python/. The venv contains symlinks pointing
to this location. However, this directory was not mounted, causing the
Python installation to be lost when containers exit, leaving broken
symlinks.

This bug was introduced in commit 57fa079 (July 17, 2025) when Python
installation was moved from Docker build-time to runtime with the
entrypoint flag system.

Solution:
Mount PROJECT_SLOT_DIR/.local/share to persist uv-downloaded Python
installations across container restarts.

Affects: python, ml, and datascience profiles

Testing:
- Clean project and add python profile
- Verify Python 3.14 downloads and installs successfully
- Restart container and verify Python still works
- Confirm ~/.local/share/uv/python/ persists on host
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 16, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a host directory creation and Docker volume mount for ~/.local/share in the run_claudebox_container function to persist uv-managed Python installations and prevent broken venv symlinks across container restarts.

Flow diagram for persisting uv-managed Python installations

flowchart TD
    A["Container start"] --> B["Create $PROJECT_SLOT_DIR/.local/share on host"]
    B --> C["Mount $PROJECT_SLOT_DIR/.local/share to /home/$DOCKER_USER/.local/share in container"]
    C --> D["uv downloads Python to /home/$DOCKER_USER/.local/share/uv/python/"]
    D --> E["Python installation persists across container restarts"]
Loading

File-Level Changes

Change Details Files
Persist uv-managed Python installations by mounting ~/.local/share.
  • Create host directory $PROJECT_SLOT_DIR/.local/share if it doesn't exist
  • Add docker_args entry to mount host .local/share into /home/$DOCKER_USER/.local/share
lib/docker.sh

Possibly linked issues

  • #Python not available in containers issue: The PR fixes Python not persisting in containers by mounting ~/.local/share, as suggested in the issue, resolving broken venv symlinks.
  • #123: The PR fixes the root cause of uv pip install failures by ensuring uv-managed Python installations persist through mounting .local/share.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python not available in containers - broken venv symlinks to uv-managed installations

1 participant