-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[ty] Allow discovering dependencies in system Python environments #22994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
carljm
wants to merge
1
commit into
main
Choose a base branch
from
claude/fix-issue-2068-x2E5Q
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+128
−26
Conversation
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
Typing conformance resultsNo changes detected ✅ |
|
…led into Fixes an issue where ty couldn't resolve imports from packages installed in a system Python environment when ty itself was installed directly in that system Python (rather than in a virtual environment). Previously, `SysPrefixPathOrigin::SelfEnvironment` was treated as requiring a virtual environment (with `pyvenv.cfg`), which caused discovery to fail for system Python installations. This change allows ty to fall back to treating its own environment as a `SystemEnvironment` when no `pyvenv.cfg` is found. Additionally, this change implements correct priority ordering: - When ty is installed in a virtual environment (e.g., `uvx --with ...`), ty's venv takes priority over other discovered environments - When ty is installed in a system Python, discovered environments (like `.venv`) take priority over the system Python's site-packages Fixes astral-sh/ty#2068 https://claude.ai/code/session_01885t5j7zeT78vRZCtu8X9C
4c9471a to
dce6885
Compare
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 astral-sh/ty#2068.
This change allows ty to discover and use dependencies installed in system Python environments where ty itself is installed.
The subtlety here is in the case where we discover a local
.venvAND ty is installed in a different Python env. In this case, we add both the local.venvand the ty-env site-packages to the resolver paths, because we want ty to work in a local project even if installed globally, but we also don't want use of global packages to break just because you run it in a project dir. Currently on main, we prioritize the ty-env over the.venv, so that packages installed usinguvx --with ...take precedence. But if the ty-env is a global env, we want the precedence to go the other way, so packages in local.venvtake precedence.Test Plan
Added test; existing tests continue to pass.