Skip to content

Formatting: black -> ruff format #890

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 8 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: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ jobs:
run: |
poetry install -E "test coverage lint"

- name: Lint with black . --check
run: poetry run black . --check

- name: Lint with 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",
}
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force

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

### Development

- Move formatting from `black` to [`ruff format`] (#890)

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/

## tmuxp 1.31.0 (2023-09-23)

### Breaking changes
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 @@ start_docs:
design_docs:
$(MAKE) -C docs design

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 @@ -329,86 +329,84 @@ this will load the `.tmuxp.yaml` in the root of the project.

## Formatting

### 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 @@ -467,7 +465,7 @@ the [gh build site].
[entr]: http://entrproject.org/
[`entr(1)`]: http://entrproject.org/
[ruff]: https://ruff.rs
[black]: https://github.com/psf/black
[ruff format]: https://docs.astral.sh/ruff/formatter/
[mypy]: http://mypy-lang.org/
[github actions]: https://github.com/features/actions
[gh build site]: https://github.com/tmux-python/tmuxp/actions?query=workflow%3Atests
Expand Down
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.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ codecov = "*"
coverage = "*"

### Lint ###
black = "*"
ruff = "*"
mypy = "*"
types-colorama = "*"
Expand All @@ -106,7 +105,6 @@ docs = [
test = ["pytest", "pytest-rerunfailures", "pytest-mock", "pytest-watcher"]
coverage = ["codecov", "coverage", "pytest-cov"]
lint = [
"black",
"ruff",
"mypy",
"types-colorama",
Expand Down
2 changes: 1 addition & 1 deletion src/tmuxp/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def launch(
shell: t.Optional["CLIShellLiteral"] = "best",
use_pythonrc: bool = False,
use_vi_mode: bool = False,
**kwargs: "Unpack[LaunchOptionalImports]"
**kwargs: "Unpack[LaunchOptionalImports]",
) -> None:
# Also allowing passing shell='code' to force using code.interact
imported_objects = get_launch_args(**kwargs)
Expand Down
12 changes: 6 additions & 6 deletions tests/workspace/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@ def f() -> bool:
return retry_until(f, raises=False)

for i, pane in enumerate(session.attached_window.panes):
assert assert_last_line(
pane, str(i)
), "Initial command did not execute properly/" + str(i)
assert assert_last_line(pane, str(i)), (
"Initial command did not execute properly/" + str(i)
)
pane.cmd("send-keys", "Up") # Will repeat echo
pane.enter() # in each iteration
assert assert_last_line(
pane, str(i)
), "Repeated command did not execute properly/" + str(i)
assert assert_last_line(pane, str(i)), (
"Repeated command did not execute properly/" + str(i)
)

session.cmd("send-keys", " echo moo")
session.cmd("send-keys", "Enter")
Expand Down
4 changes: 1 addition & 3 deletions tests/workspace/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ def test_replaces_env_variables(monkeypatch: pytest.MonkeyPatch) -> None:
panes:
- shell_command:
- htop
""".format(
TEST_VAR="${%s}" % env_key
)
""".format(TEST_VAR="${%s}" % env_key)

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

Expand Down