Skip to content

Formatting: black -> ruff format #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ jobs:
poetry install -E "test coverage lint"

- name: Lint with ruff
run: |
poetry run ruff .
run: poetry run ruff .

- name: Format with ruff
run: poetry run ruff format . --check

- name: Lint with mypy
run: poetry run mypy .
Expand Down
19 changes: 19 additions & 0 deletions .vim/.vim/coc-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"[markdown][python]": {
"coc.preferences.formatOnSave": true
},
"python.analysis.autoSearchPaths": true,
"python.analysis.typeCheckingMode": "basic",
"python.analysis.useLibraryCodeForTypes": true,
"python.formatting.provider": "ruff",
"python.linting.ruffEnabled": true,
"python.linting.mypyEnabled": true,
"python.linting.flake8Enabled": false,
"python.linting.pyflakesEnabled": false,
"python.linting.pycodestyleEnabled": false,
"python.linting.banditEnabled": false,
"python.linting.pylamaEnabled": false,
"python.linting.pylintEnabled": false,
"pyright.organizeimports.provider": "ruff",
"pyright.testing.provider": "pytest",
}
19 changes: 19 additions & 0 deletions .vim/coc-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"[markdown][python]": {
"coc.preferences.formatOnSave": true
},
"python.analysis.autoSearchPaths": true,
"python.analysis.typeCheckingMode": "basic",
"python.analysis.useLibraryCodeForTypes": true,
"python.formatting.provider": "ruff",
"python.linting.ruffEnabled": true,
"python.linting.mypyEnabled": true,
"python.linting.flake8Enabled": false,
"python.linting.pyflakesEnabled": false,
"python.linting.pycodestyleEnabled": false,
"python.linting.banditEnabled": false,
"python.linting.pylamaEnabled": false,
"python.linting.pylintEnabled": false,
"pyright.organizeimports.provider": "ruff",
"pyright.testing.provider": "pytest",
}
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ $ pip install --user --upgrade --pre libtmux
### Development

- Poetry 1.5.1 -> 1.6.1 (#497)
- Move formatting from `black` to [`ruff format`] (#506)

This retains the same formatting style of `black` while eliminating a
dev dependency by using our existing rust-based `ruff` linter.

[`ruff format`]: https://docs.astral.sh/ruff/formatter/

## libtmux 0.23.2 (2023-09-09)

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ serve_docs:
dev_docs:
$(MAKE) -j watch_docs serve_docs

black:
poetry run black `${PY_FILES}`
ruff_format:
poetry run ruff format .

ruff:
poetry run ruff .
Expand Down
56 changes: 27 additions & 29 deletions docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,86 +54,84 @@ Rebuild docs and run server via one terminal: `make dev_docs` (requires above, a

## Linting

### black
### ruff

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

````{tab} Command

poetry:

```console
$ poetry run black .
$ poetry run ruff
```

If you setup manually:

```console
$ black .
$ ruff .
```

````

````{tab} make

```console
$ make black
$ make ruff
```

````

In the future, `ruff` (below) may replace black as formatter.
````{tab} Watch

### ruff
```console
$ make watch_ruff
```

The project uses [ruff] to handles formatting, sorting imports and linting.
requires [`entr(1)`].

````{tab} Command
````

````{tab} Fix files

poetry:

```console
$ poetry run ruff
$ poetry run ruff . --fix
```

If you setup manually:

```console
$ ruff .
$ ruff . --fix
```

````

````{tab} make
#### ruff format

```console
$ make ruff
```
[ruff format] is used for formatting.

````
````{tab} Command

````{tab} Watch
poetry:

```console
$ make watch_ruff
$ poetry run ruff format .
```

requires [`entr(1)`].

````

````{tab} Fix files

poetry:
If you setup manually:

```console
$ poetry run ruff . --fix
$ ruff format .
```

If you setup manually:
````

````{tab} make

```console
$ ruff . --fix
$ make ruff_format
```

````
Expand Down Expand Up @@ -236,6 +234,6 @@ Update `__version__` in `__about__.py` and `pyproject.toml`::
[poetry]: https://python-poetry.org/
[entr(1)]: http://eradman.com/entrproject/
[`entr(1)`]: http://eradman.com/entrproject/
[black]: https://github.com/psf/black
[ruff format]: https://docs.astral.sh/ruff/formatter/
[ruff]: https://ruff.rs
[mypy]: http://mypy-lang.org/
84 changes: 1 addition & 83 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ coverage = "*"
pytest-cov = "*"

### Format ###
black = "*"
ruff = "*"
mypy = "*"

Expand All @@ -93,7 +92,7 @@ docs = [
]
test = ["pytest", "pytest-rerunfailures", "pytest-mock", "pytest-watcher"]
coverage = ["codecov", "coverage", "pytest-cov"]
lint = ["black", "ruff", "mypy"]
lint = ["ruff", "mypy"]

[tool.poetry.plugins.pytest11]
libtmux = "libtmux.pytest_plugin"
Expand Down