You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ty] Fix --python argument for Windows, and improve error messages for bad --python arguments (#18457)
## Summary
Fixesastral-sh/ty#556.
On Windows, system installations have different layouts to virtual
environments. In Windows virtual environments, the Python executable is
found at `<sys.prefix>/Scripts/python.exe`. But in Windows system
installations, the Python executable is found at
`<sys.prefix>/python.exe`. That means that Windows users were able to
point to Python executables inside virtual environments with the
`--python` flag, but they weren't able to point to Python executables
inside system installations.
This PR fixes that issue. It also makes a couple of other changes:
- Nearly all `sys.prefix` resolution is moved inside `site_packages.rs`.
That was the original design of the `site-packages` resolution logic,
but features implemented since the initial implementation have added
some resolution and validation to `resolver.rs` inside the module
resolver. That means that we've ended up with a somewhat confusing code
structure and a situation where several checks are unnecessarily
duplicated between the two modules.
- I noticed that we had quite bad error messages if you e.g. pointed to
a path that didn't exist on disk with `--python` (we just gave a
somewhat impenetrable message saying that we "failed to canonicalize"
the path). I improved the error messages here and added CLI tests for
`--python` and the `environment.python` configuration setting.
## Test Plan
- Existing tests pass
- Added new CLI tests
- I manually checked that virtual-environment discovery still works if
no configuration is given
- Micha did some manual testing to check that pointing `--python` to a
system-installation executable now works on Windows
Copy file name to clipboardExpand all lines: crates/ruff/tests/analyze_graph.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -566,7 +566,7 @@ fn venv() -> Result<()> {
566
566
----- stderr -----
567
567
ruff failed
568
568
Cause: Invalid search path settings
569
-
Cause: Failed to discover the site-packages directory: Invalid `--python` argument: `none` could not be canonicalized
569
+
Cause: Failed to discover the site-packages directory: Invalid `--python` argument: `none` does not point to a Python executable or a directory on disk
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
975
+
ty failed
976
+
Cause: Invalid search path settings
977
+
Cause: Failed to discover the site-packages directory: Invalid `--python` argument: `<temp_dir>/my-venv/foo/some_other_file.txt` does not point to a Python executable or a directory on disk
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
988
+
ty failed
989
+
Cause: Invalid search path settings
990
+
Cause: Failed to discover the site-packages directory: Invalid `--python` argument: `<temp_dir>/not-a-directory-or-executable` does not point to a Python executable or a directory on disk
// TODO: this error message should say "invalid `python` configuration setting" rather than "invalid `--python` argument"
1056
+
assert_cmd_snapshot!(case.command(), @r"
1057
+
success: false
1058
+
exit_code: 2
1059
+
----- stdout -----
1060
+
1061
+
----- stderr -----
1062
+
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
1063
+
ty failed
1064
+
Cause: Invalid search path settings
1065
+
Cause: Failed to discover the site-packages directory: Invalid `--python` argument: `<temp_dir>/not-a-directory-or-executable` does not point to a Python executable or a directory on disk
0 commit comments