Skip to content

Commit 6cd6ac9

Browse files
Add Ruff for linting and formatting (#118).
Replace flake8 with ruff in CI, Makefile, and requirements, and document the 88-character line length convention. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4a07b84 commit 6cd6ac9

8 files changed

Lines changed: 33 additions & 18 deletions

File tree

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ trim_trailing_whitespace = true
1010
[*.py]
1111
indent_style = space
1212
indent_size = 4
13+
max_line_length = 88
1314

1415
[Makefile]
1516
indent_style = tab

.github/workflows/main.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
uses: codecov/codecov-action@v2
4141

4242
python-code-quality:
43-
# Run flake8 for linting
43+
# Run ruff for linting and formatting
4444
runs-on: ubuntu-latest
4545

4646
steps:
@@ -50,5 +50,7 @@ jobs:
5050
- name: Install python packages
5151
run: pip install -r requirements.txt
5252

53-
- name: Run flake8
54-
run: flake8 .
53+
- name: Run ruff
54+
run: |
55+
ruff check .
56+
ruff format --check .

CONTRIBUTING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ Ready to contribute? Here's how to set up `pywikitools` for local development.
4848

4949
Now you can make your changes locally.
5050

51-
5. When you're done making changes, check that all tests are passing and that
52-
`flake8` has nothing to complain:
51+
5. When you're done making changes, run `make format` and check that all tests
52+
are passing and that `make lint` has nothing to complain:
5353

5454
```shell
55+
$ make format
5556
$ make test
5657
$ make lint
5758
```
@@ -70,7 +71,7 @@ Ready to contribute? Here's how to set up `pywikitools` for local development.
7071

7172
* Please write good and readable code with meaningful documentation.
7273
* We do our best to follow the PEP 8 style guide ([PEP 8](https://pep8.org/))
73-
with the exception that lines can have up to `120 characters`.
74+
with a maximum line length of `88 characters` (enforced by Ruff).
7475
* Every script should print documentation on arguments when run without or with
7576
incorrect arguments.
7677

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
.PHONY: help test lint coverage clean clean-pyc clean-test
1+
.PHONY: help test lint format coverage clean clean-pyc clean-test
22

33
.DEFAULT_GOAL := help
44

55
PYTHON ?= ./env/bin/python
6-
FLAKE8 ?= ./env/bin/flake8
6+
RUFF ?= ./env/bin/ruff
77
COVERAGE ?= ./env/bin/coverage
88

99
define BROWSER_PYSCRIPT
@@ -34,8 +34,12 @@ help: ## show this help
3434
test: ## run the test suite
3535
$(PYTHON) -m unittest discover -s pywikitools/test
3636

37-
lint: ## check style with flake8
38-
$(FLAKE8) .
37+
lint: ## check style with ruff
38+
$(RUFF) check .
39+
$(RUFF) format --check .
40+
41+
format: ## auto-format code with ruff
42+
$(RUFF) format .
3943

4044
coverage: ## run tests with coverage report and open HTML in browser
4145
$(COVERAGE) run --source=pywikitools/,pywikitools/correctbot/ --omit=pywikitools/user-config.py -m unittest discover -s pywikitools/test

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,17 @@ From your base pywikitools path (with the virtual environment set up):
9797
9898
```shell
9999
$ make test # run the test suite
100-
$ make lint # check style with flake8
100+
$ make lint # check style with ruff
101+
$ make format # auto-format code with ruff
101102
$ make coverage # coverage report; opens htmlcov/ in your browser
102103
```
103104
104105
The same commands without `make`:
105106
106107
```shell
107108
$ python -m unittest discover -s pywikitools/test
108-
$ flake8 .
109+
$ ruff check .
110+
$ ruff format --check .
109111
```
110112
111113
With `GitHub Actions` tests and linting run automatically on every push or pull

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tool.ruff]
2+
line-length = 88
3+
exclude = [
4+
"env",
5+
"pywikitools/user-config.py",
6+
"pywikitools/correctbot/user-config.py",
7+
]
8+
9+
[tool.ruff.format]
10+
# defaults (Black-compatible) are sufficient

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
flake8>=7.3.0
1+
ruff>=0.8.0
22
coverage>=7.3.2
33
wikitextparser>=0.54.0
44
pywikibot>=8.4.0

setup.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)