Skip to content

Commit a91fee8

Browse files
committed
describe requires-python fallback in docs
1 parent d622137 commit a91fee8

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

crates/ruff_workspace/src/options.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ pub struct Options {
312312
/// ```
313313
///
314314
/// If both are specified, `target-version` takes precedence over
315-
/// `requires-python`.
315+
/// `requires-python`. See [_Config file discovery_](https://docs.astral.sh/ruff/configuration/#config-file-discovery)
316+
/// for a complete description of how the `target-version` is determined
317+
/// when left unspecified.
316318
///
317319
/// Note that a stub file can [sometimes make use of a typing feature](https://typing.readthedocs.io/en/latest/spec/distributing.html#syntax)
318320
/// before it is available at runtime, as long as the stub does not make

docs/configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ 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+
If this attempt fails, Ruff will use the default `target-version`.
280+
The rules for this behavior are as follows:
281+
282+
1. If a configuration file is passed directly, Ruff does not attempt to infer a missing `target-version`.
283+
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.
284+
1. If we are using a user-level configuration from `${config_dir}/ruff/pyproject.toml`, Ruff will infer a missing `target-version` from the `requires-python` field in the first `pyproject.toml` file found in an ancestor of the current working directory.
285+
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.
286+
287+
Note that in these last two cases, the behavior of Ruff may differ depending on the working directory from which it is invoked.
288+
278289
Unlike [ESLint](https://eslint.org/docs/latest/use/configure/configuration-files#cascading-configuration-objects),
279290
Ruff does not merge settings across configuration files; instead, the "closest" configuration file
280291
is used, and any parent configuration files are ignored. In lieu of this implicit cascade, Ruff

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)