[ty] Add basic support for non-virtual Python environments#17991
Merged
[ty] Add basic support for non-virtual Python environments#17991
Conversation
Contributor
|
zanieb
commented
May 9, 2025
Comment on lines
+42
to
+44
| Err(SitePackagesDiscoveryError::NoPyvenvCfgFile(_, _)) => { | ||
| Ok(Self::System(SystemEnvironment::new(path))) | ||
| } |
Member
Author
There was a problem hiding this comment.
We should probably not use this fallback if the origin is specific to virtual environments, I can do that in a follow-up since it's not critical and I'll need to build on #17996 to add test coverage.
This test is no longer correct
zanieb
added a commit
that referenced
this pull request
May 10, 2025
Adds test coverage for #17991, which includes some minor refactoring of the virtual environment test infrastructure. I tried to minimize stylistic changes, but there are still a few because I was a little confused by the setup. I could see this evolving more in the future, as I don't think the existing model can capture all the test coverage I'm looking for.
Glyphack
pushed a commit
to Glyphack/ruff
that referenced
this pull request
May 21, 2025
…#17991) This adds basic support for non-virtual Python environments by accepting a directory without a `pyvenv.cfg` which allows existing, subsequent site-packages discovery logic to succeed. We can do better here in the long-term, by adding more eager validation (for error messages) and parsing the Python version from the discovered site-packages directory (which isn't relevant yet, because we don't use the discovered Python version from virtual environments as the default `--python-version` yet either). Related - astral-sh/ty#265 - astral-sh/ty#193 You can review this commit by commit if it makes you happy. I tested this manually; I think refactoring the test setup is going to be a bit more invasive so I'll stack it on top (see astral-sh#17996). ``` ❯ uv run ty check --python /Users/zb/.local/share/uv/python/cpython-3.10.17-macos-aarch64-none/ -vv example 2025-05-09 12:06:33.685911 DEBUG Version: 0.0.0-alpha.7 (f9c4c8999 2025-05-08) 2025-05-09 12:06:33.685987 DEBUG Architecture: aarch64, OS: macos, case-sensitive: case-insensitive 2025-05-09 12:06:33.686002 DEBUG Searching for a project in '/Users/zb/workspace/ty' 2025-05-09 12:06:33.686123 DEBUG Resolving requires-python constraint: `>=3.8` 2025-05-09 12:06:33.686129 DEBUG Resolved requires-python constraint to: 3.8 2025-05-09 12:06:33.686142 DEBUG Project without `tool.ty` section: '/Users/zb/workspace/ty' 2025-05-09 12:06:33.686147 DEBUG Searching for a user-level configuration at `/Users/zb/.config/ty/ty.toml` 2025-05-09 12:06:33.686156 INFO Defaulting to python-platform `darwin` 2025-05-09 12:06:33.68636 INFO Python version: Python 3.8, platform: darwin 2025-05-09 12:06:33.686375 DEBUG Adding first-party search path '/Users/zb/workspace/ty' 2025-05-09 12:06:33.68638 DEBUG Using vendored stdlib 2025-05-09 12:06:33.686634 DEBUG Discovering site-packages paths from sys-prefix `/Users/zb/.local/share/uv/python/cpython-3.10.17-macos-aarch64-none` (`--python` argument') 2025-05-09 12:06:33.686667 DEBUG Attempting to parse virtual environment metadata at '/Users/zb/.local/share/uv/python/cpython-3.10.17-macos-aarch64-none/pyvenv.cfg' 2025-05-09 12:06:33.686671 DEBUG Searching for site-packages directory in `sys.prefix` path `/Users/zb/.local/share/uv/python/cpython-3.10.17-macos-aarch64-none` 2025-05-09 12:06:33.686702 DEBUG Resolved site-packages directories for this environment are: ["/Users/zb/.local/share/uv/python/cpython-3.10.17-macos-aarch64-none/lib/python3.10/site-packages"] 2025-05-09 12:06:33.686706 DEBUG Adding site-packages search path '/Users/zb/.local/share/uv/python/cpython-3.10.17-macos-aarch64-none/lib/python3.10/site-packages' ... ❯ uv run ty check --python /tmp -vv example 2025-05-09 15:36:10.819416 DEBUG Version: 0.0.0-alpha.7 (f9c4c8999 2025-05-08) 2025-05-09 15:36:10.819708 DEBUG Architecture: aarch64, OS: macos, case-sensitive: case-insensitive 2025-05-09 15:36:10.820118 DEBUG Searching for a project in '/Users/zb/workspace/ty' 2025-05-09 15:36:10.821652 DEBUG Resolving requires-python constraint: `>=3.8` 2025-05-09 15:36:10.821667 DEBUG Resolved requires-python constraint to: 3.8 2025-05-09 15:36:10.8217 DEBUG Project without `tool.ty` section: '/Users/zb/workspace/ty' 2025-05-09 15:36:10.821888 DEBUG Searching for a user-level configuration at `/Users/zb/.config/ty/ty.toml` 2025-05-09 15:36:10.822072 INFO Defaulting to python-platform `darwin` 2025-05-09 15:36:10.822439 INFO Python version: Python 3.8, platform: darwin 2025-05-09 15:36:10.822773 DEBUG Adding first-party search path '/Users/zb/workspace/ty' 2025-05-09 15:36:10.822929 DEBUG Using vendored stdlib 2025-05-09 15:36:10.829872 DEBUG Discovering site-packages paths from sys-prefix `/tmp` (`--python` argument') 2025-05-09 15:36:10.829911 DEBUG Attempting to parse virtual environment metadata at '/private/tmp/pyvenv.cfg' 2025-05-09 15:36:10.829917 DEBUG Searching for site-packages directory in `sys.prefix` path `/private/tmp` ty failed Cause: Invalid search path settings Cause: Failed to discover the site-packages directory: Failed to search the `lib` directory of the Python installation at `sys.prefix` path `/private/tmp` for `site-packages` ```
Glyphack
pushed a commit
to Glyphack/ruff
that referenced
this pull request
May 21, 2025
…al-sh#17996) Adds test coverage for astral-sh#17991, which includes some minor refactoring of the virtual environment test infrastructure. I tried to minimize stylistic changes, but there are still a few because I was a little confused by the setup. I could see this evolving more in the future, as I don't think the existing model can capture all the test coverage I'm looking for.
Glyphack
pushed a commit
to Glyphack/ruff
that referenced
this pull request
May 21, 2025
…` or `VIRTUAL_ENV` (astral-sh#18003) Follow-up to astral-sh#17991 ensuring we do not allow detection of system environments when the origin is `VIRTUAL_ENV` or a discovered `.venv` directory — i.e., those always require a `pyvenv.cfg` file.
Glyphack
pushed a commit
to Glyphack/ruff
that referenced
this pull request
May 21, 2025
Following astral-sh#17991, removes some of astral-sh#17222 which is no longer strictly necessary. I don't actually think it's that ugly to have around? no strong feelings on retaining it or not.
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.
This adds basic support for non-virtual Python environments by accepting a directory without a
pyvenv.cfgwhich allows existing, subsequent site-packages discovery logic to succeed. We can do better here in the long-term, by adding more eager validation (for error messages) and parsing the Python version from the discovered site-packages directory (which isn't relevant yet, because we don't use the discovered Python version from virtual environments as the default--python-versionyet either).Related
You can review this commit by commit if it makes you happy.
I tested this manually; I think refactoring the test setup is going to be a bit more invasive so I'll stack it on top (see #17996).