mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 13:05:06 +00:00
Add support for configuring knot in pyproject.toml
files (#15493)
## Summary This PR adds support for configuring Red Knot in the `tool.knot` section of the project's `pyproject.toml` section. Options specified on the CLI precede the options in the configuration file. This PR only supports the `environment` and the `src.root` options for now. Other options will be added as separate PRs. There are also a few concerns that I intentionally ignored as part of this PR: * Handling of relative paths: We need to anchor paths relative to the current working directory (CLI), or the project (`pyproject.toml` or `knot.toml`) * Tracking the source of a value. Diagnostics would benefit from knowing from which configuration a value comes so that we can point the user to the right configuration file (or CLI) if the configuration is invalid. * Schema generation and there's a lot more; see https://github.com/astral-sh/ruff/issues/15491 This PR changes the default for first party codes: Our existing default was to only add the project root. Now, Red Knot adds the project root and `src` (if such a directory exists). Theoretically, we'd have to add a file watcher event that changes the first-party search paths if a user later creates a `src` directory. I think this is pretty uncommon, which is why I ignored the complexity for now but I can be persuaded to handle it if it's considered important. Part of https://github.com/astral-sh/ruff/issues/15491 ## Test Plan Existing tests, new file watching test demonstrating that changing the python version and platform is correctly reflected.
This commit is contained in:
parent
9ed67ba33e
commit
eb47a6634d
36 changed files with 820 additions and 413 deletions
|
@ -30,22 +30,10 @@ pub struct ModuleDb {
|
|||
impl ModuleDb {
|
||||
/// Initialize a [`ModuleDb`] from the given source root.
|
||||
pub fn from_src_roots(
|
||||
mut src_roots: impl Iterator<Item = SystemPathBuf>,
|
||||
src_roots: Vec<SystemPathBuf>,
|
||||
python_version: PythonVersion,
|
||||
) -> Result<Self> {
|
||||
let search_paths = {
|
||||
// Use the first source root.
|
||||
let src_root = src_roots
|
||||
.next()
|
||||
.ok_or_else(|| anyhow::anyhow!("No source roots provided"))?;
|
||||
|
||||
let mut search_paths = SearchPathSettings::new(src_root);
|
||||
|
||||
// Add the remaining source roots as extra paths.
|
||||
search_paths.extra_paths.extend(src_roots);
|
||||
|
||||
search_paths
|
||||
};
|
||||
let search_paths = SearchPathSettings::new(src_roots);
|
||||
|
||||
let db = Self::default();
|
||||
Program::from_settings(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue