Skip to content

Commit

Permalink
ci!: Add ruff, replacing isort, black, flake8 and its plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed May 27, 2023
1 parent 25e9482 commit cf9f3ef
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 292 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
cache: 'poetry'

- name: Install dependencies
run: poetry install -E "docs test coverage lint format"
run: poetry install -E "docs test coverage lint"

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

- name: Lint with mypy
run: poetry run mypy .
Expand Down
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ entr_warn:
@echo "See https://eradman.com/entrproject/ "
@echo "----------------------------------------------------------"

isort:
poetry run isort `${PY_FILES}`

black:
poetry run black `${PY_FILES}`

test:
poetry run py.test $(test)

Expand All @@ -39,11 +33,11 @@ start_docs:
design_docs:
$(MAKE) -C docs design

flake8:
poetry run flake8
ruff:
poetry run ruff .

watch_flake8:
if command -v entr > /dev/null; then ${PY_FILES} | entr -c $(MAKE) flake8; else $(MAKE) flake8 entr_warn; fi
watch_ruff:
if command -v entr > /dev/null; then ${PY_FILES} | entr -c $(MAKE) ruff; else $(MAKE) ruff entr_warn; fi

mypy:
poetry run mypy `${PY_FILES}`
Expand Down
83 changes: 56 additions & 27 deletions docs/contributing/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ cd libvcs
```

```console
$ poetry install -E "docs test coverage lint format"
$ poetry install -E "docs test coverage lint"
```

Makefile commands prefixed with `watch_` will watch files and rerun.
Expand Down Expand Up @@ -49,69 +49,100 @@ Rebuild docs on file change: `make watch_docs` (requires [entr(1)])
Rebuild docs and run server via one terminal: `make dev_docs` (requires above, and a `make(1)` with
`-J` support, e.g. GNU Make)

## Formatting
## Formatting / linting

The project uses [black] and [isort] (one after the other). Configurations are in `pyproject.toml`
and `setup.cfg`:
### ruff

- `make black isort`: Run `black` first, then `isort` to handle import nuances

## Linting

[flake8] and [mypy] run via CI in our GitHub Actions. See the configuration in `pyproject.toml` and
`setup.cfg`.

### flake8

[flake8] provides fast, reliable, barebones styling and linting.
The project uses [ruff] to handles formatting, sorting imports and linting.

````{tab} Command
poetry:
```console
$ poetry run flake8
$ poetry run ruff
```
If you setup manually:
```console
$ flake8
$ ruff .
```
````

````{tab} make
```console
$ make flake8
$ make ruff
```
````

````{tab} Watch
```console
$ make watch_flake8
$ make watch_ruff
```
requires [`entr(1)`].
````

````{tab} Configuration
````{tab} Fix files
poetry:
```console
$ poetry run ruff . --fix
```
If you setup manually:
```console
$ ruff . --fix
```
````

### mypy

[mypy] is used for static type checking.

````{tab} Command
poetry:
```console
$ poetry run mypy .
```
If you setup manually:
```console
$ mypy .
```
````

````{tab} make
```console
$ make mypy
```
See `[flake8]` in setup.cfg.
````

```{literalinclude} ../../setup.cfg
:language: ini
:start-at: "[flake8]"
:end-before: "[isort]"
````{tab} Watch
```console
$ make watch_mypy
```
requires [`entr(1)`].
````


### mypy

[mypy] is used for static type checking.
Expand Down Expand Up @@ -202,7 +233,5 @@ 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
[isort]: https://pypi.org/project/isort/
[flake8]: https://flake8.pycqa.org/
[ruff]: https://ruff.rs
[mypy]: http://mypy-lang.org/
Loading

0 comments on commit cf9f3ef

Please sign in to comment.