mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-28 10:50:26 +00:00
[ty] Limit shown import paths to at most 5 unless ty runs with -v (#20912)
This commit is contained in:
parent
c8133104e8
commit
9393279f65
11 changed files with 155 additions and 12 deletions
|
|
@ -421,6 +421,94 @@ fn lib64_site_packages_directory_on_unix() -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_search_paths() -> anyhow::Result<()> {
|
||||
let case = CliTest::with_files([
|
||||
("extra1/foo1.py", ""),
|
||||
("extra2/foo2.py", ""),
|
||||
("extra3/foo3.py", ""),
|
||||
("extra4/foo4.py", ""),
|
||||
("extra5/foo5.py", ""),
|
||||
("extra6/foo6.py", ""),
|
||||
("test.py", "import foo1, baz"),
|
||||
])?;
|
||||
|
||||
assert_cmd_snapshot!(
|
||||
case.command()
|
||||
.arg("--python-platform").arg("linux")
|
||||
.arg("--extra-search-path").arg("extra1")
|
||||
.arg("--extra-search-path").arg("extra2")
|
||||
.arg("--extra-search-path").arg("extra3")
|
||||
.arg("--extra-search-path").arg("extra4")
|
||||
.arg("--extra-search-path").arg("extra5")
|
||||
.arg("--extra-search-path").arg("extra6"),
|
||||
@r"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
error[unresolved-import]: Cannot resolve imported module `baz`
|
||||
--> test.py:1:14
|
||||
|
|
||||
1 | import foo1, baz
|
||||
| ^^^
|
||||
|
|
||||
info: Searched in the following paths during module resolution:
|
||||
info: 1. <temp_dir>/extra1 (extra search path specified on the CLI or in your config file)
|
||||
info: 2. <temp_dir>/extra2 (extra search path specified on the CLI or in your config file)
|
||||
info: 3. <temp_dir>/extra3 (extra search path specified on the CLI or in your config file)
|
||||
info: 4. <temp_dir>/extra4 (extra search path specified on the CLI or in your config file)
|
||||
info: 5. <temp_dir>/extra5 (extra search path specified on the CLI or in your config file)
|
||||
info: ... and 3 more paths. Run with `-v` to see all paths.
|
||||
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment
|
||||
info: rule `unresolved-import` is enabled by default
|
||||
|
||||
Found 1 diagnostic
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Shows all with `-v`
|
||||
assert_cmd_snapshot!(
|
||||
case.command()
|
||||
.arg("--python-platform").arg("linux")
|
||||
.arg("--extra-search-path").arg("extra1")
|
||||
.arg("--extra-search-path").arg("extra2")
|
||||
.arg("--extra-search-path").arg("extra3")
|
||||
.arg("--extra-search-path").arg("extra4")
|
||||
.arg("--extra-search-path").arg("extra5")
|
||||
.arg("--extra-search-path").arg("extra6")
|
||||
.arg("-v"),
|
||||
@r"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
error[unresolved-import]: Cannot resolve imported module `baz`
|
||||
--> test.py:1:14
|
||||
|
|
||||
1 | import foo1, baz
|
||||
| ^^^
|
||||
|
|
||||
info: Searched in the following paths during module resolution:
|
||||
info: 1. <temp_dir>/extra1 (extra search path specified on the CLI or in your config file)
|
||||
info: 2. <temp_dir>/extra2 (extra search path specified on the CLI or in your config file)
|
||||
info: 3. <temp_dir>/extra3 (extra search path specified on the CLI or in your config file)
|
||||
info: 4. <temp_dir>/extra4 (extra search path specified on the CLI or in your config file)
|
||||
info: 5. <temp_dir>/extra5 (extra search path specified on the CLI or in your config file)
|
||||
info: 6. <temp_dir>/extra6 (extra search path specified on the CLI or in your config file)
|
||||
info: 7. <temp_dir>/ (first-party code)
|
||||
info: 8. vendored://stdlib (stdlib typeshed stubs vendored by ty)
|
||||
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment
|
||||
info: rule `unresolved-import` is enabled by default
|
||||
|
||||
Found 1 diagnostic
|
||||
|
||||
----- stderr -----
|
||||
INFO Python version: Python 3.14, platform: linux
|
||||
INFO Indexed 7 file(s) in 0.000s
|
||||
");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pyvenv_cfg_file_annotation_showing_where_python_version_set() -> anyhow::Result<()> {
|
||||
let case = CliTest::with_files([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue