Skip to content

Commit 64e36b1

Browse files
authored
Formatting: black -> ruff format (#890)
Retain the formatting style of black while eliminating a dev dependency by using our existing rust-based ruff linter. See also: https://docs.astral.sh/ruff/formatter/
2 parents 4e96234 + 84a8c32 commit 64e36b1

File tree

11 files changed

+88
-129
lines changed

11 files changed

+88
-129
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ jobs:
5656
run: |
5757
poetry install -E "test coverage lint"
5858
59-
- name: Lint with black . --check
60-
run: poetry run black . --check
61-
6259
- name: Lint with ruff .
6360
run: poetry run ruff .
6461

62+
- name: Format with ruff
63+
run: poetry run ruff format . --check
64+
6565
- name: Lint with mypy
6666
run: poetry run mypy .
6767

.vim/.vim/coc-settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"[markdown][python]": {
3+
"coc.preferences.formatOnSave": true
4+
},
5+
"python.analysis.autoSearchPaths": true,
6+
"python.analysis.typeCheckingMode": "basic",
7+
"python.analysis.useLibraryCodeForTypes": true,
8+
"python.formatting.provider": "ruff",
9+
"python.linting.ruffEnabled": true,
10+
"python.linting.mypyEnabled": true,
11+
"python.linting.flake8Enabled": false,
12+
"python.linting.pyflakesEnabled": false,
13+
"python.linting.pycodestyleEnabled": false,
14+
"python.linting.banditEnabled": false,
15+
"python.linting.pylamaEnabled": false,
16+
"python.linting.pylintEnabled": false,
17+
"pyright.organizeimports.provider": "ruff",
18+
"pyright.testing.provider": "pytest",
19+
}

.vim/coc-settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"[markdown][python]": {
3+
"coc.preferences.formatOnSave": true
4+
},
5+
"python.analysis.autoSearchPaths": true,
6+
"python.analysis.typeCheckingMode": "basic",
7+
"python.analysis.useLibraryCodeForTypes": true,
8+
"python.formatting.provider": "ruff",
9+
"python.linting.ruffEnabled": true,
10+
"python.linting.mypyEnabled": true,
11+
"python.linting.flake8Enabled": false,
12+
"python.linting.pyflakesEnabled": false,
13+
"python.linting.pycodestyleEnabled": false,
14+
"python.linting.banditEnabled": false,
15+
"python.linting.pylamaEnabled": false,
16+
"python.linting.pylintEnabled": false,
17+
"pyright.organizeimports.provider": "ruff",
18+
"pyright.testing.provider": "pytest",
19+
}

CHANGES

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force
2626

2727
See also: https://github.com/python-poetry/poetry/blob/1.7.0/CHANGELOG.md
2828

29+
### Development
30+
31+
- Move formatting from `black` to [`ruff format`] (#890)
32+
33+
This retains the same formatting style of `black` while eliminating a
34+
dev dependency by using our existing rust-based `ruff` linter.
35+
36+
[`ruff format`]: https://docs.astral.sh/ruff/formatter/
37+
2938
## tmuxp 1.31.0 (2023-09-23)
3039

3140
### Breaking changes

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ start_docs:
3838
design_docs:
3939
$(MAKE) -C docs design
4040

41-
black:
42-
poetry run black `${PY_FILES}`
41+
ruff_format:
42+
poetry run ruff format .
4343

4444
ruff:
4545
poetry run ruff .

docs/developing.md

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -329,86 +329,84 @@ this will load the `.tmuxp.yaml` in the root of the project.
329329

330330
## Formatting
331331

332-
### black
332+
### ruff
333333

334-
[black] is used for formatting.
334+
The project uses [ruff] to handles formatting, sorting imports and linting.
335335

336336
````{tab} Command
337337
338338
poetry:
339339
340340
```console
341-
$ poetry run black .
341+
$ poetry run ruff
342342
```
343343
344344
If you setup manually:
345345
346346
```console
347-
$ black .
347+
$ ruff .
348348
```
349349
350350
````
351351

352352
````{tab} make
353353
354354
```console
355-
$ make black
355+
$ make ruff
356356
```
357357
358358
````
359359

360-
In the future, `ruff` (below) may replace black as formatter.
360+
````{tab} Watch
361361
362-
### ruff
362+
```console
363+
$ make watch_ruff
364+
```
363365
364-
The project uses [ruff] to handles formatting, sorting imports and linting.
366+
requires [`entr(1)`].
365367
366-
````{tab} Command
368+
````
369+
370+
````{tab} Fix files
367371
368372
poetry:
369373
370374
```console
371-
$ poetry run ruff
375+
$ poetry run ruff . --fix
372376
```
373377
374378
If you setup manually:
375379
376380
```console
377-
$ ruff .
381+
$ ruff . --fix
378382
```
379383
380384
````
381385

382-
````{tab} make
386+
#### ruff format
383387

384-
```console
385-
$ make ruff
386-
```
388+
[ruff format] is used for formatting.
387389

388-
````
390+
````{tab} Command
389391
390-
````{tab} Watch
392+
poetry:
391393
392394
```console
393-
$ make watch_ruff
395+
$ poetry run ruff format .
394396
```
395397
396-
requires [`entr(1)`].
397-
398-
````
399-
400-
````{tab} Fix files
401-
402-
poetry:
398+
If you setup manually:
403399
404400
```console
405-
$ poetry run ruff . --fix
401+
$ ruff format .
406402
```
407403
408-
If you setup manually:
404+
````
405+
406+
````{tab} make
409407
410408
```console
411-
$ ruff . --fix
409+
$ make ruff_format
412410
```
413411
414412
````
@@ -467,7 +465,7 @@ the [gh build site].
467465
[entr]: http://entrproject.org/
468466
[`entr(1)`]: http://entrproject.org/
469467
[ruff]: https://ruff.rs
470-
[black]: https://github.com/psf/black
468+
[ruff format]: https://docs.astral.sh/ruff/formatter/
471469
[mypy]: http://mypy-lang.org/
472470
[github actions]: https://github.com/features/actions
473471
[gh build site]: https://github.com/tmux-python/tmuxp/actions?query=workflow%3Atests

poetry.lock

Lines changed: 1 addition & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ codecov = "*"
7979
coverage = "*"
8080

8181
### Lint ###
82-
black = "*"
8382
ruff = "*"
8483
mypy = "*"
8584
types-colorama = "*"
@@ -106,7 +105,6 @@ docs = [
106105
test = ["pytest", "pytest-rerunfailures", "pytest-mock", "pytest-watcher"]
107106
coverage = ["codecov", "coverage", "pytest-cov"]
108107
lint = [
109-
"black",
110108
"ruff",
111109
"mypy",
112110
"types-colorama",

src/tmuxp/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def launch(
272272
shell: t.Optional["CLIShellLiteral"] = "best",
273273
use_pythonrc: bool = False,
274274
use_vi_mode: bool = False,
275-
**kwargs: "Unpack[LaunchOptionalImports]"
275+
**kwargs: "Unpack[LaunchOptionalImports]",
276276
) -> None:
277277
# Also allowing passing shell='code' to force using code.interact
278278
imported_objects = get_launch_args(**kwargs)

tests/workspace/test_builder.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,14 @@ def f() -> bool:
321321
return retry_until(f, raises=False)
322322

323323
for i, pane in enumerate(session.attached_window.panes):
324-
assert assert_last_line(
325-
pane, str(i)
326-
), "Initial command did not execute properly/" + str(i)
324+
assert assert_last_line(pane, str(i)), (
325+
"Initial command did not execute properly/" + str(i)
326+
)
327327
pane.cmd("send-keys", "Up") # Will repeat echo
328328
pane.enter() # in each iteration
329-
assert assert_last_line(
330-
pane, str(i)
331-
), "Repeated command did not execute properly/" + str(i)
329+
assert assert_last_line(pane, str(i)), (
330+
"Repeated command did not execute properly/" + str(i)
331+
)
332332

333333
session.cmd("send-keys", " echo moo")
334334
session.cmd("send-keys", "Enter")

tests/workspace/test_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ def test_replaces_env_variables(monkeypatch: pytest.MonkeyPatch) -> None:
317317
panes:
318318
- shell_command:
319319
- htop
320-
""".format(
321-
TEST_VAR="${%s}" % env_key
322-
)
320+
""".format(TEST_VAR="${%s}" % env_key)
323321

324322
sconfig = ConfigReader._load(format="yaml", content=yaml_workspace)
325323

0 commit comments

Comments
 (0)