Skip to content

Commit e3d2afa

Browse files
committed
move to subsection
1 parent 456a521 commit e3d2afa

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

crates/ruff_workspace/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub struct Options {
312312
/// ```
313313
///
314314
/// If both are specified, `target-version` takes precedence over
315-
/// `requires-python`. See [_Config file discovery_](https://docs.astral.sh/ruff/configuration/#config-file-discovery)
315+
/// `requires-python`. See [_Inferring the Python version_](https://docs.astral.sh/ruff/configuration/#inferring-the-python-version)
316316
/// for a complete description of how the `target-version` is determined
317317
/// when left unspecified.
318318
///

docs/configuration.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,6 @@ There are a few exceptions to these rules:
275275
1. Any config-file-supported settings that are provided on the command-line (e.g., via
276276
`--select`) will override the settings in _every_ resolved configuration file.
277277

278-
When no discovered configuration specifies a [`target-version`](settings.md#target-version), Ruff will attempt to fallback to the minimum version compatible with the `requires-python` field in a nearby `pyproject.toml`.
279-
The rules for this behavior are as follows:
280-
281-
1. If a configuration file is passed directly, Ruff does not attempt to infer a missing `target-version`.
282-
1. If a configuration file is found in the filesystem hierarchy, Ruff will infer a missing `target-version` from the `requires-python` field in a `pyproject.toml` file in the same directory as the found configuration.
283-
1. If we are using a user-level configuration from `${config_dir}/ruff/pyproject.toml`, the `requires-python` field in the first `pyproject.toml` file found in an ancestor of the current working directory takes precedence over the `target-version` in the user-level configuration.
284-
1. If no configuration files are found, Ruff will infer the `target-version` from the `requires-python` field in the first `pyproject.toml` file found in an ancestor of the current working directory.
285-
286-
Note that in these last two cases, the behavior of Ruff may differ depending on the working directory from which it is invoked.
287-
288278
Unlike [ESLint](https://eslint.org/docs/latest/use/configure/configuration-files#cascading-configuration-objects),
289279
Ruff does not merge settings across configuration files; instead, the "closest" configuration file
290280
is used, and any parent configuration files are ignored. In lieu of this implicit cascade, Ruff
@@ -317,6 +307,17 @@ If Ruff detects multiple configuration files in the same directory, the `.ruff.t
317307
precedence over the `ruff.toml` file, and the `ruff.toml` file will take precedence over
318308
the `pyproject.toml` file.
319309

310+
### Inferring the Python version
311+
When no discovered configuration specifies a [`target-version`](settings.md#target-version), Ruff will attempt to fallback to the minimum version compatible with the `requires-python` field in a nearby `pyproject.toml`.
312+
The rules for this behavior are as follows:
313+
314+
1. If a configuration file is passed directly, Ruff does not attempt to infer a missing `target-version`.
315+
1. If a configuration file is found in the filesystem hierarchy, Ruff will infer a missing `target-version` from the `requires-python` field in a `pyproject.toml` file in the same directory as the found configuration.
316+
1. If we are using a user-level configuration from `${config_dir}/ruff/pyproject.toml`, the `requires-python` field in the first `pyproject.toml` file found in an ancestor of the current working directory takes precedence over the `target-version` in the user-level configuration.
317+
1. If no configuration files are found, Ruff will infer the `target-version` from the `requires-python` field in the first `pyproject.toml` file found in an ancestor of the current working directory.
318+
319+
Note that in these last two cases, the behavior of Ruff may differ depending on the working directory from which it is invoked.
320+
320321
## Python file discovery
321322

322323
When passed a path on the command-line, Ruff will automatically discover all Python files in that

ruff.schema.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)