[ty] Support ephemeral uv virtual environments#18335
Merged
AlexWaygood merged 4 commits intomainfrom May 28, 2025
Merged
Conversation
d4f926c to
860ae77
Compare
860ae77 to
a9d13be
Compare
Contributor
|
MichaReiser
reviewed
May 27, 2025
carljm
approved these changes
May 27, 2025
MichaReiser
approved these changes
May 28, 2025
Comment on lines
+290
to
+297
| Err(err) => { | ||
| tracing::warn!( | ||
| "Failed to resolve the site-packages directories of this ephemeral uv virtual environment's \ | ||
| parent environment. Imports will not be resolved correctly if they refer to packages installed \ | ||
| into the parent environment. Underlying error: {err}" | ||
| ); | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Unrelated to your PR but we should make this proper diagnostics and not just tracing warnings (that are easy to miss in the LSP)
Member
Author
There was a problem hiding this comment.
I'll open a followup issue for this!
cf0b387 to
536b241
Compare
dcreager
added a commit
that referenced
this pull request
May 28, 2025
* main: [ty] Support ephemeral uv virtual environments (#18335) Add a `ViolationMetadata::rule` method (#18234) Return `DiagnosticGuard` from `Checker::report_diagnostic` (#18232) [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (#18337) [ty] Support cancellation and retry in the server (#18273) [ty] Synthetic function-like callables (#18242) [ty] Support publishing diagnostics in the server (#18309) Add Autofix for ISC003 (#18256) [`pyupgrade`]: new rule UP050 (`useless-class-metaclass-type`) (#18334) [pycodestyle] Make `E712` suggestion not assume a context (#18328)
carljm
added a commit
to MatthewMckee4/ruff
that referenced
this pull request
May 28, 2025
* main: (246 commits) [ty] Simplify signature types, use them in `CallableType` (astral-sh#18344) [ty] Support ephemeral uv virtual environments (astral-sh#18335) Add a `ViolationMetadata::rule` method (astral-sh#18234) Return `DiagnosticGuard` from `Checker::report_diagnostic` (astral-sh#18232) [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (astral-sh#18337) [ty] Support cancellation and retry in the server (astral-sh#18273) [ty] Synthetic function-like callables (astral-sh#18242) [ty] Support publishing diagnostics in the server (astral-sh#18309) Add Autofix for ISC003 (astral-sh#18256) [`pyupgrade`]: new rule UP050 (`useless-class-metaclass-type`) (astral-sh#18334) [pycodestyle] Make `E712` suggestion not assume a context (astral-sh#18328) put similar dunder-call tests next to each other (astral-sh#18343) [ty] Derive `PartialOrd, Ord` for `KnownInstanceType` (astral-sh#18340) [ty] Simplify `Type::try_bool()` (astral-sh#18342) [ty] Simplify `Type::normalized` slightly (astral-sh#18339) [ty] Move arviz off the list of selected primer projects (astral-sh#18336) [ty] Add --config-file CLI arg (astral-sh#18083) [ty] Tell the user why we inferred a certain Python version when reporting version-specific syntax errors (astral-sh#18295) [ty] Implement implicit inheritance from `Generic[]` for PEP-695 generic classes (astral-sh#18283) [ty] Add hint if async context manager is used in non-async with statement (astral-sh#18299) ...
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
This PR implements support for the ephemeral environments uv creates when you use the
--withargument withuv run. It will only work with a version of uv that includes astral-sh/uv@7bba3d0 (currently you have to build uv with themainbranch; it hasn't been included in a release yet).Fixes astral-sh/ty#320
Test Plan
I added unit tests. I also manually tested the PR by doing the following:
I first built the main branch of uv using
cargo build --releasein my local uv clone.I next checked that ty on the main branch was not able to resolve imports if it was invoked with
uv run --with=ty. To do this, I:a. Applied this diff to the
mainbranch of my local Ruff clone:b.
cd'd into the local clone of a Python project with third-party dependencies (https://github.com/AlexWaygood/typeshed-stats)c. Ran
../uv/target/release/uv run --force-reinstall --with="ty@../ruff" ty checkd. Observed that ty ran on my project, but was not able to resolve any third-party dependencies, and reported 104 diagnostics
I next checked that this PR branch fixed the issue. I:
a. Checked out this PR branch
b. Applied the same
pyproject.tomldiff to this branch as I applied to themainbanch in step (2)c.
cd'd into mytypeshed-statsagaind. Again ran
../uv/target/release/uv run --force-reinstall --with="ty@../ruff" ty checke. Observed that ty was able to resolve all third-party dependencies, and reported only 11 diagnostics