Skip to content

Commit

Permalink
Update docs to replace Black with ruff formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
eshwen committed Jan 30, 2024
1 parent b9f6354 commit 34cf125
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 73 deletions.
41 changes: 10 additions & 31 deletions docs/tooling/quality.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,27 @@ To automatically fix any issues, run
ruff --fix my_project/ tests/
```

### PyCharm integration

You can also install the [Ruff plugin for PyCharm] to run it automatically on file changes. In **Preferences** |
**Tools** | **Ruff**, configure it as you like.

To aid in documentation, in PyCharm go to **Preferences** | **Tools** | **Python Integrated Tools**. Under
**Docstrings**, select the docstring format as Google.

## Black

[Black] is a widely-used tool to ensure consistently-formatted code.
Ruff now contains a formatter to replace [Black]. It ensures consistently-formatted, highly readable code.

To automatically reformat your code, run
To automatically format your code, run

```shell
black my_project/ tests/
ruff format my_project/ tests/
```

To instead just show what `black` would change, run
To instead just show what `ruff` would change, run

```shell
black --diff my_project/ tests/
ruff format --diff my_project/ tests/
```

### PyCharm integration

`black` is integrated into PyCharm as of v2023.2. Go to **Settings** | **Tools** | **Black** to configure.

??? tip "For older versions"

PyCharm supports file watchers, which automatically run a command when a file is saved. This is useful for
transparently formatting code.

To include `black` as a file watcher, go to **Settings** | **Tools** | **File Watchers** and import the
[watchers.xml]. This will automatically apply formatting to Python files and Jupyter notebooks. You may need to
edit the **Program** path to point to your `black` executable.
You can also install the [Ruff plugin for PyCharm] to run it automatically on file changes. In **Preferences** |
**Tools** | **Ruff**, configure it as you like.

Otherwise, to set it up yourself, follow the instructions
at <https://black.readthedocs.io/en/stable/integrations/editors.html>.
To aid in documentation, in PyCharm go to **Preferences** | **Tools** | **Python Integrated Tools**. Under
**Docstrings**, select the docstring format as Google.

## Mypy

Expand Down Expand Up @@ -112,8 +94,7 @@ The [.pre-commit-config.yaml] file contains hooks to run

- built-in `pre-commit` checks
- Automatic use of the walrus operator
- `ruff` for linting (fixes fixable issues)
- `black` for formatting (fixes fixable issues)
- `ruff` for linting and formatting (fixes fixable issues)
- `mypy` type-hinting errors
- `poetry` dependency status (`poetry.lock` and requirements files are up-to-date)

Expand All @@ -132,8 +113,6 @@ pre-commit run -a

[pyproject.toml]: https://github.com/eshwen/ds-python-boilerplate/blob/main/pyproject.toml

[watchers.xml]: https://github.com/eshwen/ds-python-boilerplate/blob/main/pycharm/watchers.xml

[pre-commit]: https://pre-commit.com/

[Ruff]: https://beta.ruff.rs/docs/
Expand Down
42 changes: 0 additions & 42 deletions pycharm/watchers.xml

This file was deleted.

0 comments on commit 34cf125

Please sign in to comment.