fix Upward Find for venv #759#2791
Open
asukaminato0721 wants to merge 3 commits intofacebook:mainfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Updates Pyrefly’s virtual environment discovery to search upward through ancestor directories so a project can use a .venv located in a parent directory (addresses #759).
Changes:
- Refactors venv discovery into a per-root helper (
find_in_root) and applies it acrossproject_pathancestors. - Adds unit tests ensuring ancestor search works and prefers the nearest matching ancestor venv.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+51
to
+53
| pub fn find(project_path: &Path) -> Option<PathBuf> { | ||
| project_path.ancestors().find_map(find_in_root) | ||
| } |
connernilsen
requested changes
Mar 17, 2026
Contributor
connernilsen
left a comment
There was a problem hiding this comment.
Hey @asukaminato0721, thanks for doing this. This has been on the todo list for a while, so it's awesome that you picked it up.
There are a few requests below, but I don't think they should be too difficult to fix. Let me know if you have further questions or want to discuss anything.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #759
keeping the existing per-root scan and applying it across project_path plus its ancestors, so Pyrefly now finds the nearest ancestor .venv instead of only searching downward from the current root.
Test Plan
add test