Skip to content

Commit c10f56b

Browse files
authored
Switch formatter to Ruff (#106)
1 parent 7b4275a commit c10f56b

File tree

8 files changed

+40
-105
lines changed

8 files changed

+40
-105
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Store coverage
3434
uses: actions/upload-artifact@v4
3535
with:
36-
name: coverage-${{ matrix.python-version }}-${{ matrix.os }}
36+
name: coverage-${{ matrix.python-version }}
3737
path: .coverage.*
3838
coverage:
3939
needs: test

Diff for: docs/contributing.md

+6-11
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,24 @@ poetry install
2828
Parsita uses pytest to run the tests in the `tests/` directory. The test command is encapsulated with Nox:
2929

3030
```shell
31-
poetry run nox -e test
31+
poetry run nox -s test
3232
```
3333

3434
This will try to test with all compatible Python versions that `nox` can find. To run the tests with only a particular version, run something like this:
3535

3636
```shell
37-
poetry run nox -e test-3.9
37+
poetry run nox -s test-3.9
3838
```
3939

40-
It is good to run the tests locally before making a PR, but it is not necessary to have all Python versions run. It is rare for a failure to appear in a single version, and the CI will catch it anyway.
40+
It is good to run the tests locally before making a PR, but it is not necessary to have all Python versions run. It is rare for a failure to appear in a single version, and the CI will catch it anyway.
4141

4242
## Code quality
4343

44-
Parsita uses Black and Ruff to ensure a minimum standard of code quality. The commands to check the code quality are encapsulated with Nox:
44+
Parsita uses Ruff to ensure a minimum standard of code quality. The code quality commands are encapsulated with Nox:
4545

4646
```shell
47-
poetry run nox -e lint
48-
```
49-
50-
The commands to apply Black and the isort subset of Ruff are also encapsulated with Nox:
51-
52-
```shell
53-
poetry run nox - fmt
47+
poetry run nox -s format
48+
poetry run nox -s lint
5449
```
5550

5651
## Generating the docs

Diff for: noxfile.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import nox
1+
from __future__ import annotations
2+
3+
from nox import options, parametrize
24
from nox_poetry import Session, session
35

4-
nox.options.sessions = ["test", "coverage", "lint"]
6+
options.sessions = ["test", "coverage", "lint"]
57

68

79
@session(python=["3.8", "3.9", "3.10", "3.11", "3.12"])
@@ -19,12 +21,12 @@ def coverage(s: Session):
1921

2022

2123
@session(venv_backend="none")
22-
def fmt(s: Session) -> None:
23-
s.run("ruff", "check", ".", "--select", "I", "--fix")
24-
s.run("black", ".")
24+
@parametrize("command", [["ruff", "check", "."], ["ruff", "format", "--check", "."]])
25+
def lint(s: Session, command: list[str]):
26+
s.run(*command)
2527

2628

2729
@session(venv_backend="none")
28-
def lint(s: Session) -> None:
29-
s.run("black", "--check", ".")
30-
s.run("ruff", "check", ".")
30+
def format(s: Session) -> None:
31+
s.run("ruff", "check", ".", "--select", "I", "--fix")
32+
s.run("ruff", "format", ".")

Diff for: poetry.lock

+19-76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+1-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pytest-cov = "*"
2929
pytest-timeout = "*"
3030

3131
# Lint
32-
black = ">=22.10"
33-
ruff = ">=0.0.265"
32+
ruff = "^0.1"
3433

3534
# Docs
3635
mkdocs-material = "^9"
@@ -60,10 +59,6 @@ source = [
6059
]
6160

6261

63-
[tool.black]
64-
line-length = 99
65-
66-
6762
[tool.ruff]
6863
src = ["src"]
6964
line-length = 99

Diff for: src/parsita/metaclasses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __prepare__(
8787
name,
8888
bases,
8989
*,
90-
whitespace: Union[Parser[Input, Any], Pattern, str, None] = missing
90+
whitespace: Union[Parser[Input, Any], Pattern, str, None] = missing,
9191
):
9292
if whitespace is missing:
9393
whitespace = mcs.default_whitespace

Diff for: src/parsita/parsers/_literal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def lit(literal: Sequence[Input], *literals: Sequence[Input]) -> Parser[Input, I
6767

6868
return LongestAlternativeParser(
6969
LiteralParser(literal, options.whitespace),
70-
*(LiteralParser(literal_i, options.whitespace) for literal_i in literals)
70+
*(LiteralParser(literal_i, options.whitespace) for literal_i in literals),
7171
)
7272
else:
7373
return LiteralParser(literal, options.whitespace)

Diff for: src/parsita/parsers/_repeated.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __repr__(self):
3535

3636

3737
def rep1(
38-
parser: Union[Parser[Input, Output], Sequence[Input]]
38+
parser: Union[Parser[Input, Output], Sequence[Input]],
3939
) -> RepeatedOnceParser[Input, Output]:
4040
"""Match a parser one or more times repeatedly.
4141

0 commit comments

Comments
 (0)