Skip to content

Commit ab8bc7c

Browse files
committed
debt: Migrate Python formatter from black to ruff
- Faster tooling - Better handling with linting rule conflicts - Enables extending to hundreds of linting rules - Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
1 parent da5c0d6 commit ab8bc7c

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

.pre-commit-config.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
5-
- repo: https://github.com/psf/black-pre-commit-mirror
6-
rev: c53240a7f974b3707e13eac6710542cc96a2d61a # frozen: 24.10.0
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6
76
hooks:
8-
- id: black
7+
- id: ruff-format
98
files: "^python/"
109
- repo: https://github.com/asottile/pyupgrade
1110
rev: 19364aa1b2ac289ce75e6bbe93994f7b4b9425f6 # frozen: v3.19.0

python/gherkin/ast_node.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
class AstNode:
12-
1312
def __init__(self, rule_type: str) -> None:
1413
self.rule_type = rule_type
1514
self._sub_items: defaultdict[str, list[object]] = defaultdict(list)

python/gherkin/dialect.py

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434

3535
class Dialect:
36-
3736
@classmethod
3837
def for_name(cls, name: str) -> Self | None:
3938
return cls(DIALECTS[name]) if name in DIALECTS else None

python/gherkin/token_matcher_markdown.py

-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
class GherkinInMarkdownTokenMatcher(TokenMatcher):
15-
1615
def __init__(self, dialect_name: str = "en") -> None:
1716
super().__init__(dialect_name)
1817

@@ -21,7 +20,6 @@ def reset(self) -> None:
2120
self.matched_feature_line = False
2221

2322
def match_FeatureLine(self, token: Token) -> bool:
24-
2523
if self.matched_feature_line:
2624
self._set_token_matched(token, None)
2725

@@ -122,7 +120,6 @@ def match_Comment(self, token: Token) -> bool:
122120
return self._set_token_matched(token, None, False)
123121

124122
def match_Empty(self, token: Token) -> bool:
125-
126123
result = False
127124
if token.line.is_empty():
128125
result = True

python/pyproject.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ gherkin = ["*.json"]
4444
disallow_untyped_defs = true
4545
packages = ["gherkin"]
4646

47-
[tool.black]
48-
target-version = ["py39", "py310", "py311", "py312", "py313"]
47+
[tool.ruff]
48+
target-version = "py39"
4949

5050
[tool.flake8]
51-
# E1: indentation: already covered by `black`
52-
# E2: whitespace: already covered by `black`
53-
# E3: blank line: already covered by `black`
54-
# E501: line length: already covered by `black`
51+
# E1: indentation: already covered by `ruff`
52+
# E2: whitespace: already covered by `ruff`
53+
# E3: blank line: already covered by `ruff`
54+
# E501: line length: already covered by `ruff`
5555
extend-ignore = "E1,E2,E3,E501"

0 commit comments

Comments
 (0)