Commit 15c0535
# Summary
This PR introduces the following modifications in configuration
resolution:
1. In the event where we are reading in a configuration file `myconfig`
with no `target-version` specified, we will search for a
`pyproject.toml` in the _same directory_ as `myconfig` and see if it has
a `requires-python` field. If so, we will use that as the
`target-version`.
2. In the event where...
- we have not used the flag `--isolated`, and
- we have not found any configuration file, and
- we have not passed `--config` specifying a target version
then we will search for a `pyproject.toml` file with `required-python`
in an ancestor directory and use that if we find it.
We've also added some debug logs to indicate which of these paths is
taken.
## Implementation
Two small things:
1. I have chosen a method that will sometimes re-parse a
`pyproject.toml` file that has already been parsed at some earlier stage
in the resolution process. It seemed like avoiding that would require
more drastic changes - but maybe there is a clever way that I'm not
seeing!
2. When searching for these fallbacks, I suppress any errors that may
occur when parsing `pyproject.toml`s rather than propagate them. The
reasoning here is that we have already found or decided upon a perfectly
good configuration, and this is just a "bonus" to find a better guess
for the target version.
Closes #14813, #16662
## Testing
The linked issue contains a repo for reproducing the behavior, which we
used for a manual test:
```console
ruff-F821-repro on main
❯ uvx ruff check --no-cache
hello.py:9:11: F821 Undefined name `anext`. Consider specifying `requires-python = ">= 3.10"` or `tool.ruff.target-version = "py310"` in your `pyproject.toml` file.
|
8 | async def main():
9 | print(anext(g()))
| ^^^^^ F821
|
Found 1 error.
ruff-F821-repro on main
❯ ../ruff/target/debug/ruff check --no-cache
All checks passed!
```
In addition, we've added snapshot tests with the CLI output in some
examples. Please let me know if there are some additional scenarios
you'd like me to add tests for!
---------
Co-authored-by: Micha Reiser <micha@reiser.io>
1 parent d622137 commit 15c0535
File tree
10 files changed
+2914
-65
lines changed- crates
- ruff_server
- src
- session/index
- ruff_workspace/src
- ruff
- src
- tests
10 files changed
+2914
-65
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
| |||
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
64 | | - | |
| 70 | + | |
| 71 | + | |
65 | 72 | | |
66 | 73 | | |
67 | 74 | | |
| |||
74 | 81 | | |
75 | 82 | | |
76 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
77 | 102 | | |
78 | 103 | | |
79 | 104 | | |
80 | 105 | | |
81 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
82 | 113 | | |
83 | 114 | | |
84 | 115 | | |
| |||
91 | 122 | | |
92 | 123 | | |
93 | 124 | | |
94 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
95 | 143 | | |
96 | 144 | | |
97 | 145 | | |
| |||
0 commit comments