Skip to content

Commit ceefa69

Browse files
authored
ci: Replace black and flake8 with ruff. (#4866)
### Description Replace `black` and `flake8` with `ruff`. With this change also reformat the code base (only minor changes, because the configuration is basically the same.) The commits for the reformatting are not included in `git blame` calls (see `.git-blame-ignore-revs`). Also updates the `pre-commit` config so we have exactly the same linting/formatting in CI and local dev. We now have: - Less dependencies - Less configuration - Faster #### Issues * resolves: #2527
1 parent 3a43dc9 commit ceefa69

File tree

81 files changed

+358
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+358
-361
lines changed

.coveragerc36

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
[run]
55
branch = true
6-
omit =
6+
omit =
77
/tmp/*
88
*/tests/*
99
*/.venv/*
1010

1111

1212
[report]
13-
exclude_lines =
13+
exclude_lines =
1414
if TYPE_CHECKING:

.cursor/rules/core-architecture.mdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description:
3-
globs:
2+
description:
3+
globs:
44
alwaysApply: false
55
---
66
# Core Architecture

.cursor/rules/integrations-guide.mdc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description:
3-
globs:
2+
description:
3+
globs:
44
alwaysApply: false
55
---
66
# Integrations Guide
@@ -133,10 +133,10 @@ from sentry_sdk.integrations import Integration
133133

134134
class MyIntegration(Integration):
135135
identifier = "my_integration"
136-
136+
137137
def __init__(self, param=None):
138138
self.param = param
139-
139+
140140
@staticmethod
141141
def setup_once():
142142
# Install hooks, monkey patches, etc.

.cursor/rules/project-overview.mdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description:
3-
globs:
2+
description:
3+
globs:
44
alwaysApply: false
55
---
66
# Sentry Python SDK - Project Overview

.cursor/rules/quick-reference.mdc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description:
3-
globs:
2+
description:
3+
globs:
44
alwaysApply: false
55
---
66
# Quick Reference
@@ -44,7 +44,7 @@ tox -e py3.12-django-v5.2.3
4444

4545
### Code Quality
4646

47-
Our `linters` tox environment runs `black` for formatting, `flake8` for linting and `mypy` for type checking.
47+
Our `linters` tox environment runs `ruff-format` for formatting, `ruff-check` for linting and `mypy` for type checking.
4848

4949
```bash
5050
tox -e linters

.cursor/rules/testing-guide.mdc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description:
3-
globs:
2+
description:
3+
globs:
44
alwaysApply: false
55
---
66
# Testing Guide
@@ -65,10 +65,10 @@ def test_flask_integration(sentry_init, capture_events):
6565
# Test setup
6666
sentry_init(integrations=[FlaskIntegration()])
6767
events = capture_events()
68-
68+
6969
# Test execution
7070
# ... test code ...
71-
71+
7272
# Assertions
7373
assert len(events) == 1
7474
assert events[0]["exception"]["values"][0]["type"] == "ValueError"

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Formatting commits to ignore in git blame
2+
afea4a017bf13f78e82f725ea9d6a56a8e02cb34
3+
23a340a9dca60eea36de456def70c00952a33556

.pre-commit-config.yaml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.3.0
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
rev: v0.13.2
66
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
10-
- repo: https://github.com/psf/black
11-
rev: 24.1.0
12-
hooks:
13-
- id: black
14-
exclude: ^(.*_pb2.py|.*_pb2_grpc.py)
15-
16-
- repo: https://github.com/pycqa/flake8
17-
rev: 5.0.4
18-
hooks:
19-
- id: flake8
20-
additional_dependencies:
21-
[
22-
flake8-pyproject,
23-
flake8-bugbear,
24-
pep8-naming,
25-
]
26-
27-
# Disabled for now, because it lists a lot of problems.
28-
#- repo: https://github.com/pre-commit/mirrors-mypy
29-
# rev: 'v0.931'
30-
# hooks:
31-
# - id: mypy
7+
- id: ruff-check
8+
args: [--fix]
9+
- id: ruff-format

codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ comment:
1919
# Comments will only post when coverage changes. Furthermore, if a comment
2020
# already exists, and a newer commit results in no coverage change for the
2121
# entire pull, the comment will be deleted.
22-
require_changes: true
22+
require_changes: true
2323
require_base: true # must have a base report to post
2424
require_head: true # must have a head report to post
2525

2626
github_checks:
27-
annotations: false
27+
annotations: false

pyproject.toml

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
#
2-
# Tool: Black
3-
#
4-
5-
[tool.black]
6-
# 'extend-exclude' excludes files or directories in addition to the defaults
7-
extend-exclude = '''
8-
# A regex preceded with ^/ will apply only to files and directories
9-
# in the root of the project.
10-
(
11-
.*_pb2.py # exclude autogenerated Protocol Buffer files anywhere in the project
12-
| .*_pb2_grpc.py # exclude autogenerated Protocol Buffer files anywhere in the project
13-
)
14-
'''
15-
16-
171
#
182
# Tool: Coverage
193
#
@@ -196,29 +180,48 @@ module = "agents.*"
196180
ignore_missing_imports = true
197181

198182
#
199-
# Tool: Flake8
183+
# Tool: Ruff (linting and formatting)
200184
#
201185

202-
[tool.flake8]
203-
extend-ignore = [
204-
# Handled by black (Whitespace before ':' -- handled by black)
205-
"E203",
206-
# Handled by black (Line too long)
207-
"E501",
208-
# Sometimes not possible due to execution order (Module level import is not at top of file)
209-
"E402",
210-
# I don't care (Do not assign a lambda expression, use a def)
211-
"E731",
212-
# does not apply to Python 2 (redundant exception types by flake8-bugbear)
213-
"B014",
214-
# I don't care (Lowercase imported as non-lowercase by pep8-naming)
215-
"N812",
216-
# is a worse version of and conflicts with B902 (first argument of a classmethod should be named cls)
217-
"N804",
186+
[tool.ruff]
187+
# Target Python 3.7+ (minimum version supported by ruff)
188+
target-version = "py37"
189+
190+
# Exclude files and directories
191+
extend-exclude = [
192+
"*_pb2.py", # Protocol Buffer files (covers all pb2 files including grpc_test_service_pb2.py)
193+
"*_pb2_grpc.py", # Protocol Buffer files (covers all pb2_grpc files including grpc_test_service_pb2_grpc.py)
194+
"checkouts", # From flake8
195+
"lol*", # From flake8
218196
]
219-
extend-exclude = ["checkouts", "lol*"]
220-
exclude = [
221-
# gRCP generated files
222-
"grpc_test_service_pb2.py",
223-
"grpc_test_service_pb2_grpc.py",
197+
198+
[tool.ruff.lint]
199+
# Match flake8's default rule selection exactly
200+
# Flake8 by default only enables E and W (pycodestyle) + F (pyflakes)
201+
select = [
202+
"E", # pycodestyle errors (same as flake8 default)
203+
"W", # pycodestyle warnings (same as flake8 default)
204+
"F", # Pyflakes (same as flake8 default)
205+
# Note: B and N rules are NOT enabled by default in flake8
206+
# They were only active through the plugins, which may not have been fully enabled
224207
]
208+
209+
# Use ONLY the same ignores as the original flake8 config + compatibility for this codebase
210+
ignore = [
211+
"E203", # Whitespace before ':'
212+
"E501", # Line too long
213+
"E402", # Module level import not at top of file
214+
"E731", # Do not assign a lambda expression, use a def
215+
"B014", # Redundant exception types
216+
"N812", # Lowercase imported as non-lowercase
217+
"N804", # First argument of classmethod should be named cls
218+
219+
# Additional ignores for codebase compatibility
220+
"F401", # Unused imports - many in TYPE_CHECKING blocks used for type comments
221+
"E721", # Use isinstance instead of type() == - existing pattern in this codebase
222+
]
223+
224+
[tool.ruff.format]
225+
# ruff format already excludes the same files as specified in extend-exclude
226+
# Ensure Python 3.7 compatibility - avoid using Python 3.9+ syntax features
227+
skip-magic-trailing-comma = false

0 commit comments

Comments
 (0)