mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-23 03:45:14 +00:00
Port Pyright's import resolver to Rust (#5381)
## Summary This PR contains the first step towards enabling robust first-party, third-party, and standard library import resolution in Ruff (including support for `typeshed`, stub files, native modules, etc.) by porting Pyright's import resolver to Rust. The strategy taken here was to start with a more-or-less direct port of the Pyright's TypeScript resolver. The code is intentionally similar, and the test suite is effectively a superset of Pyright's test suite for its own resolver. Due to the nature of the port, the code is very, very non-idiomatic for Rust. The code is also entirely unused outside of the test suite, and no effort has been made to integrate it with the rest of the codebase. Future work will include: - Refactoring the code (now that it works) to match Rust and Ruff idioms. - Further testing, in practice, to ensure that the resolver can resolve imports in a complex project, when provided with a virtual environment path. - Caching, to minimize filesystem lookups and redundant resolutions. - Integration into Ruff itself (use Ruff's existing settings, find rules that can make use of robust resolution, etc.)
This commit is contained in:
parent
502e15585d
commit
1ed227a1e0
17 changed files with 2343 additions and 1 deletions
26
crates/ruff_python_resolver/src/config.rs
Normal file
26
crates/ruff_python_resolver/src/config.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::python_version::PythonVersion;
|
||||
|
||||
pub(crate) struct Config {
|
||||
/// Path to python interpreter.
|
||||
pub(crate) python_path: Option<PathBuf>,
|
||||
|
||||
/// Path to use for typeshed definitions.
|
||||
pub(crate) typeshed_path: Option<PathBuf>,
|
||||
|
||||
/// Path to custom typings (stub) modules.
|
||||
pub(crate) stub_path: Option<PathBuf>,
|
||||
|
||||
/// Path to a directory containing one or more virtual environment
|
||||
/// directories. This is used in conjunction with the "venv" name in
|
||||
/// the config file to identify the python environment used for resolving
|
||||
/// third-party modules.
|
||||
pub(crate) venv_path: Option<PathBuf>,
|
||||
|
||||
/// Default venv environment.
|
||||
pub(crate) venv: Option<PathBuf>,
|
||||
|
||||
/// Default Python version. Can be overridden by ExecutionEnvironment.
|
||||
pub(crate) default_python_version: Option<PythonVersion>,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue