mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Detect imports in src
layouts by default (#12848)
## Summary Occasionally, we receive bug reports that imports in `src` directories aren't correctly detected. The root of the problem is that we default to `src = ["."]`, so users have to set `src = ["src"]` explicitly. This PR extends the default to cover _both_ of them: `src = [".", "src"]`. Closes https://github.com/astral-sh/ruff/issues/12454. ## Test Plan I replicated the structure described in https://github.com/astral-sh/ruff/issues/12453, and verified that the imports were considered sorted, but that adding `src = ["."]` showed an error.
This commit is contained in:
parent
33512a4249
commit
15aa5a6d57
8 changed files with 33 additions and 31 deletions
13
docs/faq.md
13
docs/faq.md
|
@ -292,13 +292,14 @@ When Ruff sees an import like `import foo`, it will then iterate over the `src`
|
|||
looking for a corresponding Python module (in reality, a directory named `foo` or a file named
|
||||
`foo.py`).
|
||||
|
||||
If the `src` field is omitted, Ruff will default to using the "project root" as the only
|
||||
first-party source. The "project root" is typically the directory containing your `pyproject.toml`,
|
||||
`ruff.toml`, or `.ruff.toml` file, unless a configuration file is provided on the command-line via
|
||||
the `--config` option, in which case, the current working directory is used as the project root.
|
||||
If the `src` field is omitted, Ruff will default to using the "project root", along with a `"src"`
|
||||
subdirectory, as the first-party sources, to support both flat and nested project layouts.
|
||||
The "project root" is typically the directory containing your `pyproject.toml`, `ruff.toml`, or
|
||||
`.ruff.toml` file, unless a configuration file is provided on the command-line via the `--config`
|
||||
option, in which case, the current working directory is used as the project root.
|
||||
|
||||
In this case, Ruff would only check the top-level directory. Instead, we can configure Ruff to
|
||||
consider `src` as a first-party source like so:
|
||||
In this case, Ruff would check the `"src"` directory by default, but we can configure it as an
|
||||
explicit, exclusive first-party source like so:
|
||||
|
||||
=== "pyproject.toml"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue