Skip to content

Commit a94cee8

Browse files
authored
Formatting: black -> ruff format (#506)
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 6509995 + 7bce50f commit a94cee8

File tree

8 files changed

+79
-118
lines changed

8 files changed

+79
-118
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ jobs:
5151
poetry install -E "test coverage lint"
5252
5353
- name: Lint with ruff
54-
run: |
55-
poetry run ruff .
54+
run: poetry run ruff .
55+
56+
- name: Format with ruff
57+
run: poetry run ruff format . --check
5658

5759
- name: Lint with mypy
5860
run: poetry run mypy .

.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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ $ pip install --user --upgrade --pre libtmux
2828
### Development
2929

3030
- Poetry 1.5.1 -> 1.6.1 (#497)
31+
- Move formatting from `black` to [`ruff format`] (#506)
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/
3137

3238
## libtmux 0.23.2 (2023-09-09)
3339

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ serve_docs:
3838
dev_docs:
3939
$(MAKE) -j watch_docs serve_docs
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
@@ -54,86 +54,84 @@ Rebuild docs and run server via one terminal: `make dev_docs` (requires above, a
5454

5555
## Linting
5656

57-
### black
57+
### ruff
5858

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

6161
````{tab} Command
6262
6363
poetry:
6464
6565
```console
66-
$ poetry run black .
66+
$ poetry run ruff
6767
```
6868
6969
If you setup manually:
7070
7171
```console
72-
$ black .
72+
$ ruff .
7373
```
7474
7575
````
7676

7777
````{tab} make
7878
7979
```console
80-
$ make black
80+
$ make ruff
8181
```
8282
8383
````
8484

85-
In the future, `ruff` (below) may replace black as formatter.
85+
````{tab} Watch
8686
87-
### ruff
87+
```console
88+
$ make watch_ruff
89+
```
8890
89-
The project uses [ruff] to handles formatting, sorting imports and linting.
91+
requires [`entr(1)`].
9092
91-
````{tab} Command
93+
````
94+
95+
````{tab} Fix files
9296
9397
poetry:
9498
9599
```console
96-
$ poetry run ruff
100+
$ poetry run ruff . --fix
97101
```
98102
99103
If you setup manually:
100104
101105
```console
102-
$ ruff .
106+
$ ruff . --fix
103107
```
104108
105109
````
106110

107-
````{tab} make
111+
#### ruff format
108112

109-
```console
110-
$ make ruff
111-
```
113+
[ruff format] is used for formatting.
112114

113-
````
115+
````{tab} Command
114116
115-
````{tab} Watch
117+
poetry:
116118
117119
```console
118-
$ make watch_ruff
120+
$ poetry run ruff format .
119121
```
120122
121-
requires [`entr(1)`].
122-
123-
````
124-
125-
````{tab} Fix files
126-
127-
poetry:
123+
If you setup manually:
128124
129125
```console
130-
$ poetry run ruff . --fix
126+
$ ruff format .
131127
```
132128
133-
If you setup manually:
129+
````
130+
131+
````{tab} make
134132
135133
```console
136-
$ ruff . --fix
134+
$ make ruff_format
137135
```
138136
139137
````
@@ -236,6 +234,6 @@ Update `__version__` in `__about__.py` and `pyproject.toml`::
236234
[poetry]: https://python-poetry.org/
237235
[entr(1)]: http://eradman.com/entrproject/
238236
[`entr(1)`]: http://eradman.com/entrproject/
239-
[black]: https://github.com/psf/black
237+
[ruff format]: https://docs.astral.sh/ruff/formatter/
240238
[ruff]: https://ruff.rs
241239
[mypy]: http://mypy-lang.org/

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ coverage = "*"
7373
pytest-cov = "*"
7474

7575
### Format ###
76-
black = "*"
7776
ruff = "*"
7877
mypy = "*"
7978

@@ -93,7 +92,7 @@ docs = [
9392
]
9493
test = ["pytest", "pytest-rerunfailures", "pytest-mock", "pytest-watcher"]
9594
coverage = ["codecov", "coverage", "pytest-cov"]
96-
lint = ["black", "ruff", "mypy"]
95+
lint = ["ruff", "mypy"]
9796

9897
[tool.poetry.plugins.pytest11]
9998
libtmux = "libtmux.pytest_plugin"

0 commit comments

Comments
 (0)