Skip to content

fix(python): respect UV_PROJECT_ENVIRONMENT for uv venvs - #11475

Merged
jdx merged 1 commit into
jdx:mainfrom
Marukome0743:pr11475
Jul 29, 2026
Merged

jdx merged 1 commit into
jdx:mainfrom
Marukome0743:pr11475

Conversation

@Marukome0743

@Marukome0743 Marukome0743 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • respect UV_PROJECT_ENVIRONMENT when python.uv_venv_auto selects, creates, and activates a uv virtual environment
  • resolve relative paths from the uv workspace root and preserve absolute paths, while retaining .venv as the empty or unset fallback
  • initialize resolved config environment values before cache lookup and include the selected virtual environment path in cache keys
  • document the supported behavior

Root cause

The uv auto-venv path was hardcoded to <uv-root>/.venv in both activation and env cache invalidation. As a result, mise ignored the environment path selected by uv and could activate or cache the wrong virtual environment. Cache lookup also did not guarantee that config environment values were initialized before deriving the key, so alternate config construction paths could derive different lookup and save keys.

Testing

  • mise exec -- cargo test uv::tests::test_resolve_uv_venv_path
  • mise run test:e2e e2e/core/test_python_uv_venv e2e/env/test_env_cache_venv
  • mise exec -- cargo check --all-features
  • mise exec -- cargo fmt --all -- --check
  • mise exec -- shellcheck -x e2e/core/test_python_uv_venv e2e/env/test_env_cache_venv
  • mise exec -- shfmt -d -s e2e/core/test_python_uv_venv e2e/env/test_env_cache_venv
  • mise exec -- markdownlint docs/lang/python.md
  • mise x prettier -- prettier --check docs/lang/python.md

mise run lint could not start because hk does not recognize the Sapling working copy as a Git repository; all checks applicable to the changed files were run individually above.

Addresses #7142

AI-assisted — Tool: Codex; model: OpenAI/GPT-5; version: unavailable.

Summary by CodeRabbit

  • New Features

    • Python projects can now use a custom virtual environment path via UV_PROJECT_ENVIRONMENT, including relative and absolute locations.
    • Virtual environment create/activate behavior now consistently honors the configured path (not just the default directory).
  • Bug Fixes

    • Improved env-cache behavior so cache keys and reuse reflect custom virtual environment locations.
    • Prevented virtual environment settings from leaking between projects when using custom paths.
  • Documentation

    • Updated Python documentation with clearer UV_PROJECT_ENVIRONMENT guidance and examples.
  • Tests

    • Expanded end-to-end coverage for UV_PROJECT_ENVIRONMENT interactions and caching.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: d108c01e-186a-4434-b843-d3b13df7ce11

📥 Commits

Reviewing files that changed from the base of the PR and between 4940a9f and 4d22e7a.

📒 Files selected for processing (6)
  • docs/lang/python.md
  • e2e/core/test_python_uv_venv
  • e2e/env/test_env_cache_venv
  • src/cli/hook_env.rs
  • src/toolset/toolset_env.rs
  • src/uv.rs
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/cli/hook_env.rs
  • e2e/env/test_env_cache_venv
  • src/toolset/toolset_env.rs
  • docs/lang/python.md
  • e2e/core/test_python_uv_venv
  • src/uv.rs

📝 Walkthrough

Walkthrough

uv virtual environment selection now honors UV_PROJECT_ENVIRONMENT, including relative and absolute paths. Creation, sourcing, environment-cache invalidation, end-to-end coverage, and Python documentation were updated accordingly.

Changes

Configurable uv environment selection

Layer / File(s) Summary
Resolve and use the configured uv environment path
src/uv.rs
uv resolves configured environment values and uses the resulting path for virtual environment loading and creation, with unit tests for supported path forms.
Track the selected path in environment caching
src/toolset/toolset_env.rs, src/cli/hook_env.rs, e2e/env/test_env_cache_venv
Environment-cache loading now awaits environment results, cache inputs use custom uv environment directories, and regression tests cover cache reuse and sibling isolation.
Validate and document selection behavior
e2e/core/test_python_uv_venv, docs/lang/python.md
Tests and documentation cover configuration sources, precedence, relative and absolute paths, and source versus create|source modes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProjectConfig
  participant uv
  participant VirtualEnvironment
  participant EnvCache
  ProjectConfig->>uv: provide UV_PROJECT_ENVIRONMENT
  uv->>uv: resolve selected venv path
  uv->>VirtualEnvironment: load or create selected environment
  uv->>EnvCache: use selected path for cache inputs
  EnvCache-->>ProjectConfig: return cached environment state
Loading

Poem

A rabbit hopped through .venv bright,
Then chose a custom path just right.
It sourced, it cached, it tested too,
With docs to guide what uv should do.
“Hop hop!” cried Bun, “the paths now bloom!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: uv venv handling now respects UV_PROJECT_ENVIRONMENT.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Updates uv virtual-environment handling to:

  • Resolve UV_PROJECT_ENVIRONMENT from configuration or the process environment, using the uv workspace root for relative paths.
  • Use the resolved environment path for creation, activation, and environment-cache keys.
  • Initialize resolved configuration environment values before cache lookup.
  • Add unit, end-to-end, cache-isolation, and documentation coverage for custom uv environment paths.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/uv.rs Adds configuration-aware uv environment path resolution and uses it consistently when creating or loading the virtual environment.
src/toolset/toolset_env.rs Initializes resolved config environment values before cache-key computation and keys cached environments by the resolved uv environment path.
src/cli/hook_env.rs Awaits the now-asynchronous full environment-cache lookup during shell activation.
e2e/core/test_python_uv_venv Covers config-defined, process-defined, removed, relative, and absolute UV_PROJECT_ENVIRONMENT behavior.
e2e/env/test_env_cache_venv Covers cache isolation across custom uv environment paths and consistent lookup/save keys.
docs/lang/python.md Documents custom uv environment selection and relative-path resolution.

Reviews (3): Last reviewed commit: "fix(python): respect UV_PROJECT_ENVIRONM..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/toolset/toolset_env.rs`:
- Around line 286-294: Ensure the environment configuration is initialized
before deriving the cache key used by both cache lookup and save, so
UV_PROJECT_ENVIRONMENT from the [env] configuration resolves identically in
env_results_cached() and final_env(). Update the relevant initialization flow
around uv_venv_inputs and add a regression test covering a config-defined custom
uv environment and a cache hit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 64a94119-b4eb-42a4-95e5-2ff5b445871b

📥 Commits

Reviewing files that changed from the base of the PR and between f0b1d44 and 88b9611.

📒 Files selected for processing (5)
  • docs/lang/python.md
  • e2e/core/test_python_uv_venv
  • e2e/env/test_env_cache_venv
  • src/toolset/toolset_env.rs
  • src/uv.rs

Comment thread src/toolset/toolset_env.rs
@jdx
jdx merged commit 97f3cf3 into jdx:main Jul 29, 2026
36 checks passed
@Marukome0743
Marukome0743 deleted the pr11475 branch July 29, 2026 21:05
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.

2 participants