Skip to content

Commit 6caf279

Browse files
authored
Merge pull request #237 from scrapy/ruff
Migrate to ruff.
2 parents 6057cac + 8b85fc9 commit 6caf279

23 files changed

+282
-176
lines changed

.bandit.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

.bumpversion.cfg

Lines changed: 0 additions & 11 deletions
This file was deleted.

.coveragerc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.flake8

Lines changed: 0 additions & 2 deletions
This file was deleted.

.isort.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
repos:
2-
- repo: https://github.com/PyCQA/bandit
3-
rev: 1.8.2
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.3
44
hooks:
5-
- id: bandit
6-
args: [-r, -c, .bandit.yml]
7-
- repo: https://github.com/PyCQA/flake8
8-
rev: 7.1.1
9-
hooks:
10-
- id: flake8
11-
- repo: https://github.com/psf/black.git
12-
rev: 24.10.0
13-
hooks:
14-
- id: black
15-
- repo: https://github.com/pycqa/isort
16-
rev: 5.13.2
17-
hooks:
18-
- id: isort
19-
- repo: https://github.com/asottile/pyupgrade
20-
rev: v3.19.1
21-
hooks:
22-
- id: pyupgrade
23-
args: [--py39-plus]
5+
- id: ruff
6+
args: [ --fix ]
7+
- id: ruff-format

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
# All configuration values have a default; values that are commented out
1010
# serve to show the default.
1111

12-
import os
1312
import sys
13+
from pathlib import Path
1414

1515
# If extensions (or modules to document with autodoc) are in another directory,
1616
# add these directories to sys.path here. If the directory is relative to the
1717
# documentation root, use os.path.abspath to make it absolute, like shown here.
18-
sys.path.insert(0, os.path.abspath(".."))
18+
sys.path.insert(0, str(Path(__file__).parent.parent))
1919

2020
# -- General configuration -----------------------------------------------------
2121

mypy.ini

Lines changed: 0 additions & 11 deletions
This file was deleted.

pylintrc

Lines changed: 0 additions & 23 deletions
This file was deleted.

pyproject.toml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
[tool.bumpversion]
2+
current_version = "2.3.1"
3+
commit = true
4+
tag = true
5+
tag_name = "v{new_version}"
6+
7+
[[tool.bumpversion.files]]
8+
filename = "setup.py"
9+
10+
[[tool.bumpversion.files]]
11+
filename = "w3lib/__init__.py"
12+
13+
[[tool.bumpversion.files]]
14+
filename = "docs/conf.py"
15+
16+
[tool.coverage.run]
17+
branch = true
18+
include = ["w3lib/*"]
19+
20+
[tool.coverage.report]
21+
exclude_also = [
22+
"if TYPE_CHECKING:",
23+
]
24+
25+
[tool.mypy]
26+
check_untyped_defs = true
27+
28+
[[tool.mypy.overrides]]
29+
# All non-tests functions must be typed.
30+
module = "w3lib.*"
31+
disallow_untyped_defs = true
32+
33+
[[tool.mypy.overrides]]
34+
# Allow test functions to be untyped
35+
module = "tests.*"
36+
disallow_untyped_defs = false
37+
38+
[tool.pylint.MASTER]
39+
persistent = "no"
40+
41+
[tool.pylint."MESSAGES CONTROL"]
42+
enable = [
43+
"useless-suppression",
44+
]
45+
disable = [
46+
"fixme",
47+
"import-error",
48+
"import-outside-toplevel",
49+
"invalid-name",
50+
"line-too-long",
51+
"missing-class-docstring",
52+
"missing-function-docstring",
53+
"missing-module-docstring",
54+
"raise-missing-from",
55+
"redefined-builtin",
56+
"redefined-outer-name",
57+
"too-many-arguments",
58+
"too-many-branches",
59+
"too-many-lines",
60+
"too-many-positional-arguments",
61+
"too-many-public-methods",
62+
"unused-argument",
63+
"unused-variable",
64+
]
65+
66+
[tool.ruff.lint]
67+
extend-select = [
68+
# flake8-bugbear
69+
"B",
70+
# flake8-comprehensions
71+
"C4",
72+
# pydocstyle
73+
"D",
74+
# flake8-future-annotations
75+
"FA",
76+
# flynt
77+
"FLY",
78+
# refurb
79+
"FURB",
80+
# isort
81+
"I",
82+
# flake8-implicit-str-concat
83+
"ISC",
84+
# flake8-logging
85+
"LOG",
86+
# Perflint
87+
"PERF",
88+
# pygrep-hooks
89+
"PGH",
90+
# flake8-pie
91+
"PIE",
92+
# pylint
93+
"PL",
94+
# flake8-use-pathlib
95+
"PTH",
96+
# flake8-pyi
97+
"PYI",
98+
# flake8-quotes
99+
"Q",
100+
# flake8-return
101+
"RET",
102+
# flake8-raise
103+
"RSE",
104+
# Ruff-specific rules
105+
"RUF",
106+
# flake8-bandit
107+
"S",
108+
# flake8-simplify
109+
"SIM",
110+
# flake8-slots
111+
"SLOT",
112+
# flake8-debugger
113+
"T10",
114+
# flake8-type-checking
115+
"TC",
116+
# pyupgrade
117+
"UP",
118+
# pycodestyle warnings
119+
"W",
120+
# flake8-2020
121+
"YTT",
122+
]
123+
ignore = [
124+
# Within an `except` clause, raise exceptions with `raise ... from`
125+
"B904",
126+
# Missing docstring in public module
127+
"D100",
128+
# Missing docstring in public class
129+
"D101",
130+
# Missing docstring in public method
131+
"D102",
132+
# Missing docstring in public function
133+
"D103",
134+
# Missing docstring in public package
135+
"D104",
136+
# Missing docstring in magic method
137+
"D105",
138+
# Missing docstring in public nested class
139+
"D106",
140+
# Missing docstring in __init__
141+
"D107",
142+
# One-line docstring should fit on one line with quotes
143+
"D200",
144+
# No blank lines allowed after function docstring
145+
"D202",
146+
# 1 blank line required between summary line and description
147+
"D205",
148+
# Multi-line docstring closing quotes should be on a separate line
149+
"D209",
150+
# First line should end with a period
151+
"D400",
152+
# First line should be in imperative mood; try rephrasing
153+
"D401",
154+
# First line should not be the function's "signature"
155+
"D402",
156+
# First word of the first line should be properly capitalized
157+
"D403",
158+
# No blank lines allowed between a section header and its content
159+
"D412",
160+
# Too many return statements
161+
"PLR0911",
162+
# Too many branches
163+
"PLR0912",
164+
# Too many arguments in function definition
165+
"PLR0913",
166+
# Too many statements
167+
"PLR0915",
168+
# Magic value used in comparison
169+
"PLR2004",
170+
# String contains ambiguous {}.
171+
"RUF001",
172+
# Docstring contains ambiguous {}.
173+
"RUF002",
174+
# Comment contains ambiguous {}.
175+
"RUF003",
176+
# Mutable class attributes should be annotated with `typing.ClassVar`
177+
"RUF012",
178+
# Use of `assert` detected
179+
"S101",
180+
]
181+
182+
[tool.ruff.lint.pydocstyle]
183+
convention = "pep257"

pytest.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
from setuptools import find_packages, setup
1+
from pathlib import Path
22

3-
with open("README.rst", encoding="utf-8") as f:
4-
long_description = f.read()
3+
from setuptools import find_packages, setup
54

65
setup(
76
name="w3lib",
87
version="2.3.1",
98
license="BSD",
109
description="Library of web-related functions",
11-
long_description=long_description,
10+
long_description=Path("README.rst").read_text(encoding="utf-8"),
1211
long_description_content_type="text/x-rst",
1312
author="Scrapy project",
1413
author_email="info@scrapy.org",

tests/test_encoding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RequestEncodingTests(unittest.TestCase):
3333

3434
def test_bom(self):
3535
# cjk water character in unicode
36-
water_unicode = "\u6C34"
36+
water_unicode = "\u6c34"
3737
# BOM + water character encoded
3838
utf16be = b"\xfe\xff\x6c\x34"
3939
utf16le = b"\xff\xfe\x34\x6c"
@@ -273,8 +273,8 @@ def test_python_crash(self):
273273

274274
random.seed(42)
275275
buf = BytesIO()
276-
for i in range(150000):
277-
buf.write(bytes([random.randint(0, 255)]))
276+
for _ in range(150000):
277+
buf.write(bytes([random.randint(0, 255)])) # noqa: S311
278278
to_unicode(buf.getvalue(), "utf-16-le")
279279
to_unicode(buf.getvalue(), "utf-16-be")
280280
to_unicode(buf.getvalue(), "utf-32-le")

tests/test_html.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test_missing_semicolon(self):
8484
("&#x41h", "Ah"),
8585
("&#65!", "A!"),
8686
("&#65x", "Ax"),
87-
("&sup3!", "\u00B3!"),
88-
("&Aacute!", "\u00C1!"),
87+
("&sup3!", "\u00b3!"),
88+
("&Aacute!", "\u00c1!"),
8989
("&#9731!", "\u2603!"),
9090
("&#153", "\u2122"),
9191
("&#x99", "\u2122"),
@@ -325,7 +325,6 @@ def test_with_escape_chars(self):
325325

326326

327327
class UnquoteMarkupTest(unittest.TestCase):
328-
329328
sample_txt1 = """<node1>hi, this is sample text with entities: &amp; &copy;
330329
<![CDATA[although this is inside a cdata! &amp; &quot;]]></node1>"""
331330
sample_txt2 = (

0 commit comments

Comments
 (0)