mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Fix isort FAQ to surface correct src setting (#11829)
## Summary Closes https://github.com/astral-sh/ruff/issues/11722. Based on feedback in that issue.
This commit is contained in:
parent
521a358a4d
commit
0d06900cec
1 changed files with 51 additions and 48 deletions
99
docs/faq.md
99
docs/faq.md
|
@ -271,53 +271,6 @@ by isort, like `_string` and `idlelib`.
|
|||
|
||||
Like isort, Ruff's import sorting is compatible with Black.
|
||||
|
||||
Ruff does not yet support all of isort's configuration options, though it does support many of
|
||||
them. You can find the supported settings in the [API reference](settings.md#lintisort).
|
||||
For example, you can set [`known-first-party`](settings.md#lint_isort_known-first-party)
|
||||
like so:
|
||||
|
||||
=== "pyproject.toml"
|
||||
|
||||
```toml
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
# Pyflakes
|
||||
"F",
|
||||
# Pycodestyle
|
||||
"E",
|
||||
"W",
|
||||
# isort
|
||||
"I001"
|
||||
]
|
||||
|
||||
# Note: Ruff supports a top-level `src` option in lieu of isort's `src_paths` setting.
|
||||
src = ["src", "tests"]
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
known-first-party = ["my_module1", "my_module2"]
|
||||
```
|
||||
|
||||
=== "ruff.toml"
|
||||
|
||||
```toml
|
||||
[lint]
|
||||
select = [
|
||||
# Pyflakes
|
||||
"F",
|
||||
# Pycodestyle
|
||||
"E",
|
||||
"W",
|
||||
# isort
|
||||
"I001"
|
||||
]
|
||||
|
||||
# Note: Ruff supports a top-level `src` option in lieu of isort's `src_paths` setting.
|
||||
src = ["src", "tests"]
|
||||
|
||||
[lint.isort]
|
||||
known-first-party = ["my_module1", "my_module2"]
|
||||
```
|
||||
|
||||
## How does Ruff determine which of my imports are first-party, third-party, etc.?
|
||||
|
||||
Ruff accepts a `src` option that in your `pyproject.toml`, `ruff.toml`, or `.ruff.toml` file, which
|
||||
|
@ -353,6 +306,7 @@ consider `src` as a first-party source like so:
|
|||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
# Ruff supports a top-level `src` option in lieu of isort's `src_paths` setting.
|
||||
# All paths are relative to the project root, which is the directory containing the pyproject.toml.
|
||||
src = ["src"]
|
||||
```
|
||||
|
@ -360,6 +314,7 @@ consider `src` as a first-party source like so:
|
|||
=== "ruff.toml"
|
||||
|
||||
```toml
|
||||
# Ruff supports a top-level `src` option in lieu of isort's `src_paths` setting.
|
||||
# All paths are relative to the project root, which is the directory containing the pyproject.toml.
|
||||
src = ["src"]
|
||||
```
|
||||
|
@ -392,7 +347,55 @@ above, `baz.py` would be identified as part of the Python package beginning at
|
|||
`./my_project/src/foo`, and so any imports in `baz.py` that begin with `foo` (like `import foo.bar`)
|
||||
would be considered first-party based on this same-package heuristic.
|
||||
|
||||
For a detailed explanation, see the [contributing guide](contributing.md).
|
||||
For a detailed explanation of `src` resolution, see the [contributing guide](contributing.md).
|
||||
|
||||
Ruff can also be configured to treat certain modules as (e.g.) always first-party, regardless of
|
||||
their location on the filesystem. For example, you can set [`known-first-party`](settings.md#lint_isort_known-first-party)
|
||||
like so:
|
||||
|
||||
=== "pyproject.toml"
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
src = ["src", "tests"]
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
# Pyflakes
|
||||
"F",
|
||||
# Pycodestyle
|
||||
"E",
|
||||
"W",
|
||||
# isort
|
||||
"I001"
|
||||
]
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
known-first-party = ["my_module1", "my_module2"]
|
||||
```
|
||||
|
||||
=== "ruff.toml"
|
||||
|
||||
```toml
|
||||
src = ["src", "tests"]
|
||||
|
||||
[lint]
|
||||
select = [
|
||||
# Pyflakes
|
||||
"F",
|
||||
# Pycodestyle
|
||||
"E",
|
||||
"W",
|
||||
# isort
|
||||
"I001"
|
||||
]
|
||||
|
||||
[lint.isort]
|
||||
known-first-party = ["my_module1", "my_module2"]
|
||||
```
|
||||
|
||||
Ruff does not yet support all of isort's configuration options, though it does support many of
|
||||
them. You can find the supported settings in the [API reference](settings.md#lintisort).
|
||||
|
||||
## Does Ruff support Jupyter Notebooks?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue