Skip to content

Commit 1157b58

Browse files
authored
Merge pull request #2359 from cclauss/ruff
Lint Python code with ruff
2 parents 55756f8 + 1502a96 commit 1157b58

10 files changed

+88
-17
lines changed

docs/contributing/2.-coding-standard.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ All code submitted to hug should run through the following tools:
5252
- Flake8
5353
- flake8-bugbear
5454
- Bandit
55+
- ruff
5556
- pep8-naming
5657
- vulture
5758
- safety

isort/output.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def _with_straight_imports(
569569
) -> List[str]:
570570
output: List[str] = []
571571

572-
as_imports = any((module in parsed.as_map["straight"] for module in straight_modules))
572+
as_imports = any(module in parsed.as_map["straight"] for module in straight_modules)
573573

574574
# combine_straight_imports only works for bare imports, 'as' imports not included
575575
if config.combine_straight_imports and not as_imports:

isort/settings.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,11 @@ def _get_config_data(file_path: str, sections: Tuple[str, ...]) -> Dict[str, Any
892892

893893
for key, value in settings.items():
894894
existing_value_type = _get_str_to_type_converter(key)
895-
if existing_value_type == tuple:
895+
if existing_value_type is tuple:
896896
settings[key] = tuple(_as_list(value))
897-
elif existing_value_type == frozenset:
897+
elif existing_value_type is frozenset:
898898
settings[key] = frozenset(_as_list(settings.get(key))) # type: ignore
899-
elif existing_value_type == bool:
899+
elif existing_value_type is bool:
900900
# Only some configuration formats support native boolean values.
901901
if not isinstance(value, bool):
902902
value = _as_bool(value)

pyproject.toml

+44
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ dev = [
133133
"pytest-benchmark>=3.4.1",
134134
"pytest-mock>=1.10",
135135
"requirementslib>=1.5",
136+
"ruff>=0.9.6",
136137
"safety>=2.2.0",
137138
"stdlibs>=2024.10.21.16",
138139
"toml>=0.10.2",
@@ -169,6 +170,49 @@ allow_untyped_defs = true
169170
allow_incomplete_defs = true
170171
allow_untyped_calls = true
171172

173+
[tool.ruff]
174+
line-length = 100
175+
lint.select = [
176+
"ASYNC",
177+
"B",
178+
"C4",
179+
"C90",
180+
"E",
181+
"F",
182+
"FLY",
183+
"PERF",
184+
"PIE",
185+
"PLC",
186+
"PLE",
187+
"RUF",
188+
"S",
189+
"UP",
190+
"W",
191+
]
192+
lint.ignore = [
193+
"B017",
194+
"B028",
195+
"B904",
196+
"E203",
197+
"E501",
198+
"PERF203",
199+
"RUF100",
200+
"UP006",
201+
"UP035",
202+
]
203+
lint.exclude = [ "isort/_vendored/*" ]
204+
lint.mccabe.max-complexity = 91 # Default is 10
205+
206+
[tool.ruff.lint.per-file-ignores]
207+
"isort/deprecated/finders.py" = [ "UP034" ]
208+
"isort/hooks.py" = [ "S603" ]
209+
"isort/output.py" = [ "PLC0206" ]
210+
"isort/settings.py" = [ "PLC0414", "S603", "S607" ]
211+
"isort/setuptools_commands.py" = [ "RUF012" ]
212+
"tests/*" = [ "RUF001", "S" ]
213+
"tests/unit/example_crlf_file.py" = [ "F401" ]
214+
"tests/unit/test_wrap_modes.py" = [ "PIE804" ]
215+
172216
[tool.isort]
173217
profile = "hug"
174218
src_paths = ["isort", "tests"]

scripts/build_profile_docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/env python
22
import os
3-
from typing import Any, Dict, Generator, Iterable, Type
3+
from typing import Any, Dict
44

55
from isort.profiles import profiles
66

scripts/check_acknowledgments.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ async def main():
4646
)
4747
results = response.json()
4848
contributors.extend(
49-
(
50-
contributor
51-
for contributor in results
52-
if contributor["type"] == GITHUB_USER_TYPE
53-
and contributor["login"] not in IGNORED_AUTHOR_LOGINS
54-
and f"@{contributor['login'].lower()}" not in ACKNOWLEDGEMENTS
55-
)
49+
contributor
50+
for contributor in results
51+
if contributor["type"] == GITHUB_USER_TYPE
52+
and contributor["login"] not in IGNORED_AUTHOR_LOGINS
53+
and f"@{contributor['login'].lower()}" not in ACKNOWLEDGEMENTS
5654
)
5755

5856
unacknowledged_users = await asyncio.gather(

scripts/lint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ uv run black --target-version py39 --check .
77
uv run isort --profile hug --check --diff isort/ tests/
88
uv run isort --profile hug --check --diff example_*/
99
uv run --with=Flake8-pyproject flake8 isort/ tests/
10+
uv run ruff check
1011
# 51457: https://github.com/tiangolo/typer/discussions/674
1112
# 72715: https://github.com/timothycrosley/portray/issues/95
1213
uv run safety check -i 72715 -i 51457 -i 59587

tests/unit/test_exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def setup_class(self):
8686

8787
def test_variables(self):
8888
assert self.instance.code == "x = ["
89-
assert self.instance.original_error == SyntaxError
89+
assert self.instance.original_error is SyntaxError
9090

9191

9292
class TestLiteralSortTypeMismatch(TestISortError):
@@ -96,8 +96,8 @@ def setup_class(self):
9696
)
9797

9898
def test_variables(self):
99-
assert self.instance.kind == tuple
100-
assert self.instance.expected_kind == list
99+
assert self.instance.kind is tuple
100+
assert self.instance.expected_kind is list
101101

102102

103103
class TestAssignmentsFormatMismatch(TestISortError):

tests/unit/test_isort.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ def test_import_by_paren_issue_460() -> None:
30193019
import io
30203020
import os
30213021
"""
3022-
assert isort.code((test_input)) == test_input
3022+
assert isort.code(test_input) == test_input
30233023

30243024

30253025
def test_function_with_docstring() -> None:
@@ -3783,7 +3783,7 @@ def test_command_line(tmpdir, capfd, multiprocess: bool) -> None:
37833783

37843784
tmpdir.join("file1.py").write("import re\nimport os\n\nimport contextlib\n\n\nimport isort")
37853785
tmpdir.join("file2.py").write(
3786-
("import collections\nimport time\n\nimport abc" "\n\n\nimport isort")
3786+
"import collections\nimport time\n\nimport abc" "\n\n\nimport isort"
37873787
)
37883788
arguments = [str(tmpdir), "--settings-path", os.getcwd()]
37893789
if multiprocess:

uv.lock

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

0 commit comments

Comments
 (0)