Commit 54edd6e
authored
Remove black, use ruff for generated config_models (DataDog#23588)
* Drop black as a direct dependency, use ruff format for generated config models
- Remove explicit `black==23.12.1` from `datadog_checks_dev`
- Replace `apply_black` calls in the model consumer with `ruff format -`,
using the repo's centralized `[tool.ruff]` configuration
- Drop the now-unused `code_formatter` plumbing through `ModelConsumer` /
`build_model_file` / `validate models`
- Drop the [tool.black] block from `ddev/pyproject.toml` and the matching
python-version-bump logic in `update_py_config.py` (with test fixture)
- Update README badge from black to ruff
The root `[tool.black]` section is kept (with an explanatory comment)
because `datamodel-code-generator` reads it transitively through its own
internal formatter, and removing it changes line-length to 88 which
breaks our list[...] -> tuple[..., ...] line-by-line transform.
* Add changelog entries
* Make ruff a hard dep of datadog_checks_dev[cli], invoke via python -m ruff
CI installs ddev with `pip install -e ./datadog_checks_dev[cli]` and never
adds ruff to PATH. The previous helper called `shutil.which('ruff')` and
silently returned the input unchanged when ruff was missing — leaving long
lines and missing wraps in 401 generated config-model files, surfacing as
"not in sync" in the validate workflow.
- Declare `ruff>=0.11` in `datadog_checks_dev[cli]` so the package is
always installed alongside the model generator.
- Switch the helper to `sys.executable -m ruff` so the in-venv package is
used regardless of PATH.
- Raise loudly on missing ruff or non-zero ruff exit instead of silently
degrading, so any future regression fails the workflow with a clear error.
* Pin ruff to 0.11.10 to match ddev's hatch lint env
* Remove [tool.black] from root pyproject.toml and update _fix_types
Make `_fix_types` operate on the joined document (as UTF-8 bytes) instead
of line by line, so the bracket-tracking pass works regardless of how
datamodel-code-generator's internal formatter wrapped `list[...]`. Place
the `, ...` sentinel right after the last non-whitespace byte before the
closing `]`, so output stays on the previous content line even when the
parser pre-wrapped the closing bracket onto its own line.
With those changes the generator no longer relies on `[tool.black]`
existing in the repo, so the section and its accompanying comment are
removed from `pyproject.toml`. The black-related comment near the
config_models lint exclusion and the black badge in `README.md` go too.
Four config_models files (kafka_actions, win32_event_log, yarn x2)
regenerate with different — but semantically identical — wrapping. They
were the only ones whose pre-wrapped form was sensitive to the change in
upstream line-length default; future regens are stable.
* Add changelogs for regenerated config_models in kafka_actions, win32_event_log, yarn
* Address PR review: docs, error-path hint, focused _fix_types tests
- Replace remaining "code style - black" references in developer docs
(`docs/developer/index.md` badge, `docs/developer/guidelines/style.md`
style section, link reference) with ruff equivalents.
- Update the stale `ddev test postgres -l` example output in
`docs/developer/testing.md` to drop `black==22.12.0` and reflect the
current lint env contents (`ruff==0.11.10`, `pydantic==2.11.5`).
- Move the "ruff is not installed" install hint in `format_with_ruff`
from the `FileNotFoundError` branch to the `CalledProcessError` branch
and gate it on `"No module named 'ruff'"` in stderr — the previous
layout was effectively dead code because `sys.executable` always
resolves, so missing-ruff surfaces as a non-zero exit, not a missing
binary.
- Add `tests/tooling/configuration/consumers/model/test_fix_types.py`
with focused coverage for the `_fix_types` post-processing pass: the
multiline-wrapped `list[Literal[...]]` regression case the PR was
written to fix, dict and nested-list translations, unicode in
descriptions, and verbatim pass-through when no `list[`/`dict[`
is present.
* Address PR review (round 2): code_formatter robustness + direct tests
code_formatter.py:
- Guard `_resolve_ruff_config` with `if root_str:` so an unset
`get_root()` (returns '') doesn't fall into the `Path('').is_dir()`
branch (which is True — it resolves to CWD), and unit tests actually
walk back to the repo pyproject.toml as the docstring claims.
- Replace the loose `'[tool.ruff' in text` substring with a line-anchored
scan that only matches actual TOML table headers (`[tool.ruff]` or
`[tool.ruff.…]`), so a comment or string value can't false-positive.
- Surface argv (via `shlex.join`), stderr, and stdout in the error
message for non-missing-package failures, so a future ruff config
change emitting actionable output is debuggable from the message alone.
Tests:
- New `test_code_formatter.py` (17 tests): direct coverage for
`format_with_ruff` (line wrapping, quote-style preservation, short
passthrough, missing-ruff hint, full-context error on other failures)
and `_resolve_ruff_config` (root path success, fallback walk on empty
root, fallback walk when root has no `[tool.ruff]`, returns None when
nothing is found, parametrized header recognition for `_has_ruff_section`).
- `test_update_py_config.py`: add explicit content assertions on the
rewritten `ddev/pyproject.toml` — no `[tool.black]` block survives,
`[tool.ruff].target-version` is updated to the new pinned version, the
old token is gone. Captures the actual contract instead of relying on
the success-counter being 9.
* Relax ddev's datadog-checks-dev pin to span the dcd 39 release gap
This PR bumps `datadog-checks-dev` to 39 (`black` is dropped from `[cli]`
extras, so per semver it's a major). The current `~=38.0` constraint in
ddev's `pyproject.toml` would block any GitHub Action that installs both
packages from the local repo — `pip install -e ./ddev` would fail to
resolve the local dcd 39 against ddev's pin.
Relax the pin to `>=38.0,<40` for the duration of the gap between this
PR landing and the next ddev release. The release PR for ddev MUST
tighten this back to `~=39.0`.
* Apply ruff format to new helper and tests
* Restore relaxed datadog-checks-dev pin for transition period1 parent 2f66fc4 commit 54edd6e
27 files changed
Lines changed: 522 additions & 134 deletions
File tree
- datadog_checks_dev
- changelog.d
- datadog_checks/dev/tooling
- commands/validate
- configuration/consumers/model
- tests/tooling/configuration/consumers/model
- ddev
- changelog.d
- src/ddev/cli/meta/scripts
- tests/cli/meta/scripts
- docs/developer
- .snippets
- guidelines
- kafka_actions
- changelog.d
- datadog_checks/kafka_actions/config_models
- win32_event_log
- changelog.d
- datadog_checks/win32_event_log/config_models
- yarn
- changelog.d
- datadog_checks/yarn/config_models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 46 | + | |
| 47 | + | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | 98 | | |
101 | 99 | | |
102 | 100 | | |
| |||
135 | 133 | | |
136 | 134 | | |
137 | 135 | | |
138 | | - | |
| 136 | + | |
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
| |||
Lines changed: 89 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
Lines changed: 5 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | | - | |
| 9 | + | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
| 34 | + | |
36 | 35 | | |
37 | | - | |
38 | 36 | | |
39 | 37 | | |
40 | 38 | | |
| |||
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
140 | | - | |
141 | 138 | | |
142 | 139 | | |
143 | 140 | | |
| |||
207 | 204 | | |
208 | 205 | | |
209 | 206 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | 207 | | |
216 | 208 | | |
217 | 209 | | |
| |||
226 | 218 | | |
227 | 219 | | |
228 | 220 | | |
229 | | - | |
| 221 | + | |
230 | 222 | | |
231 | 223 | | |
232 | 224 | | |
| |||
255 | 247 | | |
256 | 248 | | |
257 | 249 | | |
258 | | - | |
| 250 | + | |
259 | 251 | | |
Lines changed: 40 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | | - | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | | - | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
| |||
54 | 51 | | |
55 | 52 | | |
56 | 53 | | |
57 | | - | |
| 54 | + | |
58 | 55 | | |
59 | 56 | | |
60 | 57 | | |
| |||
109 | 106 | | |
110 | 107 | | |
111 | 108 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
133 | 147 | | |
134 | 148 | | |
135 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
| |||
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
| |||
0 commit comments