mirror of https://github.com/astral-sh/ruff
## 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. |
||
|---|---|---|
| .. | ||
| red_knot | ||
| red_knot_project | ||
| red_knot_python_semantic | ||
| red_knot_server | ||
| red_knot_test | ||
| red_knot_vendored | ||
| red_knot_wasm | ||
| ruff | ||
| ruff_annotate_snippets | ||
| ruff_benchmark | ||
| ruff_cache | ||
| ruff_db | ||
| ruff_dev | ||
| ruff_diagnostics | ||
| ruff_formatter | ||
| ruff_graph | ||
| ruff_index | ||
| ruff_linter | ||
| ruff_macros | ||
| ruff_notebook | ||
| ruff_python_ast | ||
| ruff_python_ast_integration_tests | ||
| ruff_python_codegen | ||
| ruff_python_formatter | ||
| ruff_python_index | ||
| ruff_python_literal | ||
| ruff_python_parser | ||
| ruff_python_resolver | ||
| ruff_python_semantic | ||
| ruff_python_stdlib | ||
| ruff_python_trivia | ||
| ruff_python_trivia_integration_tests | ||
| ruff_server | ||
| ruff_source_file | ||
| ruff_text_size | ||
| ruff_wasm | ||
| ruff_workspace | ||