Fix Pipenv venv discovery settings view (#645, #546) - #654
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
Conversation
Assisted-by: Claude Code:claude-opus-5-5
Agent mode and hosted stale-install checks now find the venv Pipenv really uses in two cases where they used to miss it, patch the system interpreter instead, and let VEX attest not_affected: - WORKON_HOME, PIPENV_CUSTOM_VENV_NAME or PIPENV_VENV_IN_PROJECT set in the project's .env (or PIPENV_DOTENV_LOCATION), which every Pipenv command loads before it picks the venv (#546). - An explicit "not in project" setting next to a ./.venv directory. Only Pipenv 2023.11.14+ skips ./.venv then; 2018.11 to 2023.10.24 still use it, so both venvs are now patched (#645). Assisted-by: Claude Code:claude-opus-5-5
Scan-level regressions for both fixes: a .env-named venv is scanned (and PIPENV_DONT_LOAD_ENV turns that off), and an explicit "not in project" setting now scans ./.venv as well as the WORKON_HOME venv. The Pipenv compatibility doc describes the new discovery rules. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
The new .env test removed the whole WORKON_HOME on Windows, where site-packages sits one level shallower, so the .env-named venv went with it. .env values now decode exactly python-dotenv's escapes, so a backslash in a quoted Windows path is kept as written. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
|
Bugbot Autofix prepared a fix for the issue found in the latest run.
Or push these changes by commenting: Preview (dec35ec829)diff --git a/crates/socket-patch-cli/tests/in_process_python_envs.rs b/crates/socket-patch-cli/tests/in_process_python_envs.rs
--- a/crates/socket-patch-cli/tests/in_process_python_envs.rs
+++ b/crates/socket-patch-cli/tests/in_process_python_envs.rs
@@ -689,7 +689,7 @@
project.join(".env"),
format!(
"export WORKON_HOME=\"{}\"\nPIPENV_CUSTOM_VENV_NAME=proj-env # named\n",
- workon.display()
+ workon.display().to_string().replace('\\', "\\\\")
),
)
.unwrap();
diff --git a/crates/socket-patch-core/src/crawlers/python_crawler.rs b/crates/socket-patch-core/src/crawlers/python_crawler.rs
--- a/crates/socket-patch-core/src/crawlers/python_crawler.rs
+++ b/crates/socket-patch-core/src/crawlers/python_crawler.rs
@@ -3545,9 +3545,10 @@
"HOME",
tmp.path().join("home").to_string_lossy().into_owned(),
)]);
+ let base_escaped = base.replace('\\', "\\\\");
for dotenv in [
format!("WORKON_HOME={base}/elsewhere\n"),
- format!("# venvs\nexport WORKON_HOME=\"{base}/elsewhere\" # here\n"),
+ format!("# venvs\nexport WORKON_HOME=\"{base_escaped}/elsewhere\" # here\n"),
format!("WORKON_HOME='{base}/elsewhere'\n"),
format!("BASE={base}\nWORKON_HOME=${{BASE}}/elsewhere # comment\n"),
] {You can send follow-ups to the cloud agent here. |
|
Ready for review — head
Reviewers: the change is in Pipenv venv discovery. It now reads Generated by Claude Code |
|
Codex follow-up review of The first fixes preserve native modern dotenv bindings and interpolation, including single-quoted and multiline values, and apply the active-environment decision within each settings view. Relative and empty active paths retain the verified behavior. The remaining compatibility gap is now corrected with explicit Pipenv 2018.11.26 and 2020.11.15 shell profiles. The 2018 parser resolves the complete file mapping with process values first and its shell sets Verified on the exact committed source:
335 successful checks, 7 skipped, and 8 successful workflows (1 additional workflow skipped). Bugbot is clear on this commit; no unresolved review threads or new actionable findings. Ready for review has been restored. GitHub still requires the normal human approval before merge. |
|
BugBot review Please review the dotenv parsing and per-view active-environment correction on |
|
BugBot review Please review the native Pipenv 2018/2020 cached-shell discovery correction on |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit d8356ae. Configure here.

LLM Description written by Claude Code:claude-opus-5-5
Fixes #645
Fixes #546
Summary
Agent mode, and the hosted stale-install check, now find the venv a Pipenv project actually uses in two cases they used to miss. In both, socket-patch fell through to the system interpreter, patched that instead, and let
vexattestnot_affectedwhile the venv Pipenv runs stayed vulnerable.Root cause
pipenv_project_site_packages(crates/socket-patch-core/src/crawlers/python_crawler.rs) chose the venv from settings that don't match what the installed Pipenv sees:.envsettings (orPIPENV_DOTENV_LOCATION) before selecting an environment, unless loading is disabled. Parser behavior and the timing of cached settings differ between current commands and the supported 2018/2020 shells, so a process-only or single dotenv view can miss the installed environment../.venv". Only Pipenv 2023.11.14+ does that. Releases 2018.11 through 2023.10.24 use an existing./.venvdirectory whatever the setting says, and only 2026.2+ reads the Pipfile[pipenv] venv_in_projectkey.Fix
./.venvdirectory exists, any setting other than an explicit "in project" now returns both the WORKON_HOME venv and./.venv, so the venv any Pipenv release uses gets patched.docs/testing/pipenv-compatibility.mddescribes the new rules.Known over-approximation: if
.envsays "in project" and the project also has a WORKON_HOME venv, that venv is patched too, because the environment-only view still returns it. It belongs to the same project, so this is harmless.Verification against real Pipenv
pipenv --venv, with both a./.venvdirectory and$WORKON_HOME/custompresent:PIPENV_VENV_IN_PROJECT=0p/.venvwh/custom.envPIPENV_CUSTOM_VENV_NAME=custom(no.venv)wh/customwh/customwh/customTests (red → green)
Per issue:
pipenv_venv_in_project_settings_decide_about_dot_venv(core unit) coversPIPENV_VENV_IN_PROJECT=0/false/Off/no,PIPENV_NO_VENV_IN_PROJECT=1, the Pipfile key, and the case where only.venvexists.pipenv_explicit_not_in_project_still_scans_dot_venv(scan level,in_process_python_envs.rs).pipenv_dotenv_settings_move_the_venvcovers a custom venv name in.env,WORKON_HOMEin.envin each python-dotenv syntax,PIPENV_DONT_LOAD_ENV, andPIPENV_DOTENV_LOCATION.pipenv_dotenv_venv_in_project_is_honoured.dotenv_parsing_follows_python_dotenv, including Windows paths.pipenv_dotenv_settings_pick_the_scanned_venv(scan level).I ran the new tests on top of
mainfirst, with the parser stubbed to return nothing.dotenv_parsing_follows_python_dotenv,pipenv_dotenv_settings_move_the_venvandpipenv_venv_in_project_settings_decide_about_dot_venvFAILED. With the fix, all 63python_crawlertests pass. I changed the existing #334 tests that asserted "explicit false skips./.venv" to expect the corrected behaviour. The guard against a strayvenv/directory is kept.Local runs:
cargo clippy --workspace --all-features -- -D warnings: clean.cargo test --workspace --all-features --no-fail-fast: all passed except 12 fault-injection tests (*_write_failure_*,*unremovable*,relax_loop_must_not_traverse_symlinked_root). They depend onchmodand fail only because the sandbox runs as root. None of them touches Python discovery, and CI runs them as non-root.cargo fmt --all -- --checkalready fails onmain(~500 diffs; CI has no fmt step). The lines this PR adds are rustfmt-clean, and I didn't reformat unrelated code.bf91b10: all 335 checks green (6 skipped by design). That includestest (windows-latest), which first failed on a Windows-only bug in the new test's fixture, fixed inbf91b10. Bugbot's one finding (backslash escapes in quoted Windows paths) is fixed and resolved, and its re-review found no new issues.npm/,pypi/,gem/) are needed, since discovery lives in core.🤖 Generated with Claude Code
Note
Medium Risk
Changes which Python site-packages get scanned/patched for Pipenv projects; incorrect discovery could miss or over-patch venvs, though results are limited to project-owned environments and heavily tested.
Overview
Pipenv venv discovery now mirrors how real Pipenv picks environments: project
.env(orPIPENV_DOTENV_LOCATION, unlessPIPENV_DONT_LOAD_ENV) is parsed with python-dotenv semantics plus a legacy 2018 parser, and discovery merges several timing profiles (current dotenv, process env, 2018/2020 cached shell views) so agent mode and hosted stale-install checks target the venv Pipenv actually uses instead of falling through to a global interpreter.#645: An explicit “not in project” no longer drops
./.venvfor all releases—only Pipenv 2023.11.14+ ignores it, so when both WORKON_HOME and./.venvexist, both are returned (WORKON_HOME first). #546: Dotenv-drivenWORKON_HOME, custom venv names, and active-env overrides are honored per view.Docs in
pipenv-compatibility.mdand broad unit, scan, and hosted redirect/VEX regression tests cover dotenv syntax, legacy WORKON_HOME, and the revised in-project behavior.Reviewed by Cursor Bugbot for commit d8356ae. Configure here.
Generated by Claude Code
Review follow-up on
d8356ae2: all three reported discovery findings are corrected. Modern dotenv binding/interpolation and per-view active-environment selection are preserved. Native-proven 2018 and 2020 shell profiles now retain their own parser, cached settings and active-prefix timing; discovery includes their project environments without scanning unrelated venvs. Verified with 162 repository tests, seven hosted stale-install regression cases, 18 real native environment cases, 34 legacy and 58 modern parser cases, targeted Clippy and independent review. Ready to merge as-is from this review. 335 successful checks, 7 skipped, and 8 successful workflows (1 additional workflow skipped). Bugbot is clear on this commit; no unresolved review threads or new actionable findings.