Skip to content

Commit 3ceb956

Browse files
committed
Resolve a relative WORKON_HOME from the Pipenv project
The modern dotenv and process settings views passed WORKON_HOME through unjoined, so a relative value resolved against socket-patch's own cwd instead of the project Pipenv runs from (the legacy cached view already joined it). Under --cwd that missed the project's venv. Join it to the project directory in the shared helper, as the legacy path does. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 404b30e commit 3ceb956

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎crates/socket-patch-core/src/crawlers/python_crawler.rs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,9 @@ async fn find_pipenv_virtualenv_site_packages_with(
19431943
cwd: &Path,
19441944
var: &impl Fn(&str) -> Option<String>,
19451945
) -> Vec<PathBuf> {
1946-
let workon_home = pipenv_workon_home(var);
1946+
// Pipenv runs from the project, so a relative WORKON_HOME (from `.env`
1947+
// or the process) is the project's, not this process's cwd (`--cwd`).
1948+
let workon_home = pipenv_workon_home(var).map(|home| cwd.join(home));
19471949
find_pipenv_virtualenv_site_packages_at(cwd, workon_home.as_deref(), var).await
19481950
}
19491951

@@ -4831,6 +4833,26 @@ mod tests {
48314833
);
48324834
}
48334835

4836+
/// A relative WORKON_HOME names a directory under the project, not
4837+
/// under this process's cwd: `--cwd` scans must still find the venv.
4838+
#[tokio::test]
4839+
async fn pipenv_relative_workon_home_resolves_from_the_project() {
4840+
let (_tmp, project, site, base_var) = pipenv_project_with_workon_venv(&[]);
4841+
let var = |name: &str| {
4842+
if name == "WORKON_HOME" {
4843+
Some("../wh".to_string())
4844+
} else {
4845+
base_var(name)
4846+
}
4847+
};
4848+
let found = find_pipenv_virtualenv_site_packages_with(&project, &var).await;
4849+
let canon = |p: &PathBuf| std::fs::canonicalize(p).unwrap();
4850+
assert_eq!(
4851+
found.iter().map(canon).collect::<Vec<_>>(),
4852+
vec![canon(&site)]
4853+
);
4854+
}
4855+
48344856
#[tokio::test]
48354857
async fn pipenv_legacy_dotenv_shell_keeps_its_own_workon_home() {
48364858
let (tmp, project, default, base_var) = pipenv_project_with_workon_venv(&[]);

0 commit comments

Comments
 (0)