ruff/crates/red_knot_project
Micha Reiser 03f08283ad
[red-knot] Fallback to `requires-python` if no `python-version` is specified (#16028)
## Summary

Add support for the `project.requires-python` field in `pyproject.toml`
files.

Fall back to the resolved lower bound of `project.requires-python` if
the `environment.python-version` field is `None` (or more accurately,
initialize `environment.python-version with `requires-python`'s lower
bound if left unspecified).

## UX design

There are two options on how we can handle the fallback to
`requires-python`'s lower bound:

1. Store the resolved lower bound in `environment.python-version` if
that field is `None` (Implemented in this PR)
2. Store the `requires-python` constraint separately. 

There's no observed difference unless a user-level configuration (or any
other inherited configuration is used). Let's discuss it on the given
example


**User configuration**

```toml
[environment]
python-version = "3.10"
```

**Project configuration (`pyproject.toml`)**

```toml
[project]
name = "test"
requires-python = ">= 3.12"

[tool.knot]
# No environment table
```

The resolved version for 1. is 3.12 because the `requires-python`
constraint precedence takes precedence over the `python-version` in the
user configuration. 2. resolves to 3.10 because all `python-version`
constraints take precedence before falling back to `requires-python`.

Ruff implements 1. It's also the easier to implement and it does seem
intuitive to me that the more local `requires-python` constraint takes
precedence.


## Test plan

Added CLI and unit tests.
2025-02-12 11:47:59 +00:00
..
resources/test/corpus Rename `red_knot_workspace` to `red_knot_project` (#15615) 2025-01-20 14:02:36 +01:00
src [red-knot] Fallback to `requires-python` if no `python-version` is specified (#16028) 2025-02-12 11:47:59 +00:00
tests [red-knot] Combine terminal statement support with statically known branches (#15817) 2025-02-05 17:47:49 -05:00
Cargo.toml [red-knot] Fallback to `requires-python` if no `python-version` is specified (#16028) 2025-02-12 11:47:59 +00:00