Skip to content

Commit c77eba9

Browse files
authored
Replaces flake8 with ruff and associated fixes. (Netflix#2998)
* Fixing ruff suggestions
1 parent cb99c80 commit c77eba9

Some content is hidden

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

47 files changed

+168
-139
lines changed

.github/workflows/python.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ jobs:
3636
pip install -e ".[dev]"
3737
- name: "Lint with black"
3838
uses: psf/black@stable
39-
- name: "Lint with flake8"
39+
- name: "Lint with ruff"
4040
run: |
41-
# stop the build if there are Python syntax errors or undefined names
42-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
43-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
44-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
41+
ruff check src tests
4542
- name: Test with pytest
4643
run: |
4744
pip install pytest-cov

pyproject.toml

+61
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,64 @@
22
line-length = 100
33
target_version = ['py39']
44
include = '\.pyi?$'
5+
6+
[tool.ruff]
7+
select = [
8+
"E", # pycodestyle errors
9+
"W", # pycodestyle warnings
10+
"F", # pyflakes
11+
# "I", # isort
12+
"C", # flake8-comprehensions
13+
"B", # flake8-bugbear
14+
]
15+
ignore = [
16+
"E501", # line too long, handled by black
17+
"B008", # do not perform function calls in argument defaults
18+
"C901", # complexity
19+
]
20+
21+
# Allow autofix for all enabled rules (when `--fix`) is provided.
22+
fixable = ["A", "B", "C", "D", "E", "F"]
23+
unfixable = []
24+
25+
# Exclude a variety of commonly ignored directories.
26+
exclude = [
27+
".bzr",
28+
".direnv",
29+
".eggs",
30+
".git",
31+
".hg",
32+
".mypy_cache",
33+
".nox",
34+
".pants.d",
35+
".ruff_cache",
36+
".svn",
37+
".tox",
38+
".venv",
39+
"__pypackages__",
40+
"_build",
41+
"buck-out",
42+
"build",
43+
"dist",
44+
"node_modules",
45+
"venv",
46+
]
47+
48+
# Same as Black.
49+
line-length = 100
50+
51+
# Allow unused variables when underscore-prefixed.
52+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
53+
54+
# Assume Python 3.10.
55+
target-version = "py39"
56+
57+
[tool.ruff.mccabe]
58+
# Unlike Flake8, default to a complexity level of 10.
59+
max-complexity = 10
60+
61+
[tool.ruff.isort]
62+
known-third-party = ["fastapi", "pydantic", "starlette"]
63+
64+
[tool.ruff.per-file-ignores]
65+
"tests/conftest.py" = ["E402"]

requirements-dev.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ coverage
44
devtools
55
factory-boy
66
faker
7-
flake8
87
ipython
8+
ruff
99
pytest
1010
vulture
11+
typing-extensions==4.4.0

requirements-dev.txt

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#
2-
# This file is autogenerated by pip-compile with python 3.9
3-
# To update, run:
2+
# This file is autogenerated by pip-compile with Python 3.9
3+
# by the following command:
44
#
5-
# pip-compile --no-emit-index-url requirements-dev.in
5+
# pip-compile requirements-dev.in
66
#
7+
appnope==0.1.3
8+
# via ipython
79
asttokens==2.2.0
810
# via
911
# devtools
@@ -24,6 +26,8 @@ decorator==5.1.1
2426
# via ipython
2527
devtools==0.10.0
2628
# via -r requirements-dev.in
29+
exceptiongroup==1.1.0
30+
# via pytest
2731
executing==1.2.0
2832
# via
2933
# devtools
@@ -34,8 +38,6 @@ faker==17.0.0
3438
# via
3539
# -r requirements-dev.in
3640
# factory-boy
37-
flake8==6.0.0
38-
# via -r requirements-dev.in
3941
iniconfig==1.1.1
4042
# via pytest
4143
ipython==8.10.0
@@ -44,8 +46,6 @@ jedi==0.18.2
4446
# via ipython
4547
matplotlib-inline==0.1.6
4648
# via ipython
47-
mccabe==0.7.0
48-
# via flake8
4949
mypy-extensions==0.4.3
5050
# via black
5151
packaging==21.3
@@ -68,10 +68,6 @@ ptyprocess==0.7.0
6868
# via pexpect
6969
pure-eval==0.2.2
7070
# via stack-data
71-
pycodestyle==2.10.0
72-
# via flake8
73-
pyflakes==3.0.1
74-
# via flake8
7571
pygments==2.13.0
7672
# via ipython
7773
pyparsing==3.0.9
@@ -80,6 +76,8 @@ pytest==7.2.1
8076
# via -r requirements-dev.in
8177
python-dateutil==2.8.2
8278
# via faker
79+
ruff==0.0.246
80+
# via -r requirements-dev.in
8381
six==1.16.0
8482
# via
8583
# asttokens
@@ -88,10 +86,18 @@ stack-data==0.6.2
8886
# via ipython
8987
toml==0.10.2
9088
# via vulture
89+
tomli==2.0.1
90+
# via
91+
# black
92+
# pytest
9193
traitlets==5.6.0
9294
# via
9395
# ipython
9496
# matplotlib-inline
97+
typing-extensions==4.4.0
98+
# via
99+
# -r requirements-dev.in
100+
# black
95101
vulture==2.7
96102
# via -r requirements-dev.in
97103
wcwidth==0.2.5

setup.cfg

-25
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ looponfailroots = src tests
66
selenium_driver = chrome
77
self-contained-html = true
88

9-
[flake8]
10-
# E203 false positive, see https://github.com/PyCQA/pycodestyle/issues/373
11-
ignore = F999,E203,E266,W403,E501,E128,E124,E402,W503,W504,E731,C901,B007,B306,B009,B010
12-
exclude = .venv/.git,*/migrations/*,node_modules/*,docs/*
13-
max-line-length=100
14-
max-complexity = 18
15-
select = B,C,E,F,W,T4,B9
16-
17-
# XXX: E501 is ignored, which disables line length checking.
18-
# Currently, the black formatter doesn't wrap long strings: https://github.com/psf/black/issues/182#issuecomment-385325274
19-
# We already have a lot of E501's - these are lines black didn't wrap.
20-
# But rather than append # noqa: E501 to all of them, we just ignore E501 for now.
21-
229
[bdist_wheel]
2310
python-tag = py38
2411

@@ -29,17 +16,5 @@ source =
2916
src
3017
tests
3118

32-
[isort]
33-
line_length=100
34-
lines_between_sections=1
35-
multi_line_output=3
36-
include_trailing_comma=True
37-
force_grid_wrap=0
38-
use_parentheses=True
39-
known_first_party=dispatch
40-
default_section=THIRDPARTY
41-
indent=' '
42-
skip=setup.py,src/dispatch/models.py
43-
4419
[black]
4520
line_length=100

src/dispatch/__init__.py

-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from inspect import trace
21
import os
32
import os.path
43
import traceback
@@ -49,12 +48,6 @@
4948
from dispatch.term.models import Term # noqa lgtm[py/unused-import]
5049
from dispatch.ticket.models import Ticket # noqa lgtm[py/unused-import]
5150
from dispatch.workflow.models import Workflow # noqa lgtm[py/unused-import]
52-
from dispatch.data.source.environment.models import (
53-
SourceEnvironment,
54-
) # noqa lgtm[py/unused-import]
55-
from dispatch.data.source.data_format.models import (
56-
SourceDataFormat,
57-
) # noqa lgtm[py/unused-import]
5851
from dispatch.data.source.status.models import SourceStatus # noqa lgtm[py/unused-import]
5952
from dispatch.data.source.transport.models import SourceTransport # noqa lgtm[py/unused-import]
6053
from dispatch.data.source.type.models import SourceType # noqa lgtm[py/unused-import]

src/dispatch/case/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,4 @@ def delete_case(
257257
)
258258
}
259259
],
260-
)
260+
) from None

src/dispatch/database/revisions/tenant/versions/2021-07-22_2780d28e4f39.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
"""
88
from alembic import op
9-
import sqlalchemy as sa
109

1110

1211
# revision identifiers, used by Alembic.

src/dispatch/database/revisions/tenant/versions/2022-05-26_5e2bc6083503.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88
from alembic import op
99
import sqlalchemy as sa
10-
from sqlalchemy.dialects import postgresql
1110

1211
# revision identifiers, used by Alembic.
1312
revision = "5e2bc6083503"

src/dispatch/database/revisions/tenant/versions/2023-01-25_e23c468440c9.py

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
77
"""
88
from alembic import op
9-
import sqlalchemy as sa
10-
from sqlalchemy.dialects import postgresql
119

1210
# revision identifiers, used by Alembic.
1311
revision = "e23c468440c9"

src/dispatch/database/revisions/tenant/versions/2023-01-27_956eb8f8987e.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88
from alembic import op
99
import sqlalchemy as sa
10-
from sqlalchemy.dialects import postgresql
1110

1211
# revision identifiers, used by Alembic.
1312
revision = "956eb8f8987e"

src/dispatch/database/service.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ def __init__(self, filter_spec):
9494
try:
9595
filter_spec["field"]
9696
except KeyError:
97-
raise BadFilterFormat("`field` is a mandatory filter attribute.")
97+
raise BadFilterFormat("`field` is a mandatory filter attribute.") from None
9898
except TypeError:
99-
raise BadFilterFormat("Filter spec `{}` should be a dictionary.".format(filter_spec))
99+
raise BadFilterFormat(
100+
"Filter spec `{}` should be a dictionary.".format(filter_spec)
101+
) from None
100102

101103
self.operator = Operator(filter_spec.get("op"))
102104
self.value = filter_spec.get("value")
@@ -478,11 +480,11 @@ def search_filter_sort_paginate(
478480
ErrorWrapper(FieldNotFoundError(msg=str(e)), loc="filter"),
479481
],
480482
model=BaseModel,
481-
)
483+
) from None
482484
except BadFilterFormat as e:
483485
raise ValidationError(
484486
[ErrorWrapper(InvalidFilterError(msg=str(e)), loc="filter")], model=BaseModel
485-
)
487+
) from None
486488

487489
if items_per_page == -1:
488490
items_per_page = None

src/dispatch/entity_type/views.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def create_entity_type(*, db_session: Session = Depends(get_db), entity_type_in:
4646
raise ValidationError(
4747
[ErrorWrapper(ExistsError(msg="A entity with this name already exists."), loc="name")],
4848
model=EntityTypeCreate,
49-
)
49+
) from None
5050
return entity
5151

5252

@@ -77,7 +77,7 @@ def update_entity_type(
7777
)
7878
],
7979
model=EntityTypeUpdate,
80-
)
80+
) from None
8181
return entity_type
8282

8383

@@ -108,7 +108,7 @@ def process_entity_type(
108108
)
109109
],
110110
model=EntityTypeUpdate,
111-
)
111+
) from None
112112
return entity_type
113113

114114

src/dispatch/event/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from uuid import UUID
33

44
from typing import Optional
5-
from dispatch.models import PrimaryKey
65

76
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String
87
from sqlalchemy.dialects.postgresql import UUID as SQLAlchemyUUID

src/dispatch/evergreen/scheduled.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def create_evergreen_reminder(
7575
return
7676

7777
# we set the evergreen last reminder at time to now
78-
for resource_type, resources in resource_groups.items():
78+
for _, resources in resource_groups.items():
7979
for resource in resources:
8080
resource.evergreen_last_reminder_at = datetime.utcnow()
8181

src/dispatch/incident/scheduled.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def daily_report(db_session: SessionLocal, project: Project):
127127

128128
# we create and send an incidents daily report for each notification filter
129129
for notification_id, search_filter_dict in incidents_notification_filters_mapping.items():
130-
for search_filter_id, incidents in search_filter_dict.items():
130+
for _search_filter_id, incidents in search_filter_dict.items():
131131
items_grouped = []
132132
items_grouped_template = INCIDENT
133133

src/dispatch/logging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LogLevels(DispatchEnum):
1616

1717
def configure_logging():
1818
log_level = str(LOG_LEVEL).upper() # cast to string
19-
log_levels = [level for level in LogLevels]
19+
log_levels = list(LogLevels)
2020

2121
if log_level not in log_levels:
2222
# we use error as the default log level

src/dispatch/notification/service.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import List, Optional, Type
44

55
from dispatch.database.core import Base
6-
from dispatch.case.models import Case
76
from dispatch.models import PrimaryKey
87
from dispatch.plugin import service as plugin_service
98
from dispatch.project import service as project_service

src/dispatch/organization/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,5 @@ def update_organization(
122122
)
123123
],
124124
model=OrganizationUpdate,
125-
)
125+
) from None
126126
return organization

src/dispatch/plugins/dispatch_atlassian_confluence/docs/plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import List
66

77

8-
def replace_content(client: Confluence, document_id: str, replacements: List[str]) -> dict():
8+
def replace_content(client: Confluence, document_id: str, replacements: List[str]) -> {}:
99
# read content based on document_id
1010
current_content = client.get_page_by_id(
1111
document_id, expand="body.storage", status=None, version=None

src/dispatch/plugins/dispatch_atlassian_confluence/plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self):
5252
self.configuration_schema = ConfluenceConfiguration
5353

5454
def create_file(
55-
self, drive_id: str, name: str, participants: List[str] = [], file_type: str = "folder"
55+
self, drive_id: str, name: str, participants: List[str] = None, file_type: str = "folder"
5656
):
5757
"""Creates a new Home page for the incident documents.."""
5858
try:

0 commit comments

Comments
 (0)