Skip to content

Commit d184f51

Browse files
authored
Migrate to ruff. (#80)
1 parent ac51c3e commit d184f51

27 files changed

+397
-322
lines changed

.bumpversion.cfg

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

.coveragerc

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

.pre-commit-config.yaml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
repos:
2-
- repo: https://github.com/PyCQA/isort
3-
rev: 5.13.2
4-
hooks:
5-
- id: isort
6-
- repo: https://github.com/psf/black
7-
rev: 24.10.0
8-
hooks:
9-
- id: black
10-
- repo: https://github.com/pycqa/flake8
11-
rev: 7.1.1
12-
hooks:
13-
- id: flake8
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.6
4+
hooks:
5+
- id: ruff
6+
args: [ --fix ]
7+
- id: ruff-format
148
- repo: https://github.com/adamchainz/blacken-docs
159
rev: 1.19.0
1610
hooks:
1711
- id: blacken-docs
1812
additional_dependencies:
19-
- black==24.10.0
13+
- black==25.1.0

docs/conf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
import os
1413
import sys
1514
from pathlib import Path
1615

17-
sys.path.insert(0, os.path.abspath("../"))
18-
19-
2016
# -- Project information -----------------------------------------------------
2117

2218
project = "python-zyte-api"

pyproject.toml

Lines changed: 154 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,155 @@
1-
[tool.isort]
2-
profile = "black"
3-
multi_line_output = 3
1+
[tool.bumpversion]
2+
current_version = "0.6.0"
3+
commit = true
4+
tag = true
5+
tag_name = "{new_version}"
46

5-
[tool.black]
6-
target-version = ["py39", "py310", "py311", "py312", "py313"]
7+
[[tool.bumpversion.files]]
8+
filename = "setup.py"
9+
10+
[[tool.bumpversion.files]]
11+
filename = "zyte_api/__version__.py"
12+
13+
[[tool.bumpversion.files]]
14+
filename = "docs/conf.py"
15+
16+
[tool.coverage.run]
17+
branch = true
18+
19+
[tool.coverage.report]
20+
exclude_also = [
21+
"if TYPE_CHECKING:",
22+
]
23+
24+
[tool.pytest.ini_options]
25+
filterwarnings = [
26+
"ignore:The zyte_api\\.aio module is deprecated:DeprecationWarning"
27+
]
28+
29+
[tool.ruff.lint]
30+
extend-select = [
31+
# flake8-bugbear
32+
"B",
33+
# flake8-comprehensions
34+
"C4",
35+
# pydocstyle
36+
"D",
37+
# flake8-future-annotations
38+
"FA",
39+
# flynt
40+
"FLY",
41+
# refurb
42+
"FURB",
43+
# isort
44+
"I",
45+
# flake8-implicit-str-concat
46+
"ISC",
47+
# flake8-logging
48+
"LOG",
49+
# Perflint
50+
"PERF",
51+
# pygrep-hooks
52+
"PGH",
53+
# flake8-pie
54+
"PIE",
55+
# pylint
56+
"PL",
57+
# flake8-pytest-style
58+
"PT",
59+
# flake8-use-pathlib
60+
"PTH",
61+
# flake8-pyi
62+
"PYI",
63+
# flake8-quotes
64+
"Q",
65+
# flake8-return
66+
"RET",
67+
# flake8-raise
68+
"RSE",
69+
# Ruff-specific rules
70+
"RUF",
71+
# flake8-bandit
72+
"S",
73+
# flake8-simplify
74+
"SIM",
75+
# flake8-slots
76+
"SLOT",
77+
# flake8-debugger
78+
"T10",
79+
# flake8-type-checking
80+
"TC",
81+
# pyupgrade
82+
"UP",
83+
# pycodestyle warnings
84+
"W",
85+
# flake8-2020
86+
"YTT",
87+
]
88+
ignore = [
89+
# Missing docstring in public module
90+
"D100",
91+
# Missing docstring in public class
92+
"D101",
93+
# Missing docstring in public method
94+
"D102",
95+
# Missing docstring in public function
96+
"D103",
97+
# Missing docstring in public package
98+
"D104",
99+
# Missing docstring in magic method
100+
"D105",
101+
# Missing docstring in __init__
102+
"D107",
103+
# One-line docstring should fit on one line with quotes
104+
"D200",
105+
# No blank lines allowed after function docstring
106+
"D202",
107+
# 1 blank line required between summary line and description
108+
"D205",
109+
# Multi-line docstring closing quotes should be on a separate line
110+
"D209",
111+
# First line should end with a period
112+
"D400",
113+
# First line should be in imperative mood; try rephrasing
114+
"D401",
115+
# First line should not be the function's "signature"
116+
"D402",
117+
# `try`-`except` within a loop incurs performance overhead
118+
"PERF203",
119+
# Too many return statements
120+
"PLR0911",
121+
# Too many branches
122+
"PLR0912",
123+
# Too many arguments in function definition
124+
"PLR0913",
125+
# Too many statements
126+
"PLR0915",
127+
# Magic value used in comparison
128+
"PLR2004",
129+
# String contains ambiguous {}.
130+
"RUF001",
131+
# Docstring contains ambiguous {}.
132+
"RUF002",
133+
# Comment contains ambiguous {}.
134+
"RUF003",
135+
# Mutable class attributes should be annotated with `typing.ClassVar`
136+
"RUF012",
137+
# Use of `assert` detected
138+
"S101",
139+
]
140+
141+
[tool.ruff.lint.per-file-ignores]
142+
"zyte_api/__init__.py" = ["F401"]
143+
"zyte_api/aio/errors.py" = ["F401"]
144+
"zyte_api/aio/retry.py" = ["F401"]
145+
"tests/*" = ["S"]
146+
"docs/**" = ["B006"]
147+
# Skip PEP 604 suggestions for files with attr classes
148+
"zyte_api/errors.py" = ["UP007"]
149+
"zyte_api/stats.py" = ["UP007"]
150+
151+
[tool.ruff.lint.flake8-type-checking]
152+
runtime-evaluated-decorators = ["attr.s"]
153+
154+
[tool.ruff.lint.pydocstyle]
155+
convention = "pep257"

pytest.ini

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

setup.cfg

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

setup.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
import os
1+
from pathlib import Path
22

33
from setuptools import find_packages, setup
44

5-
6-
def get_version():
7-
about = {}
8-
here = os.path.abspath(os.path.dirname(__file__))
9-
with open(os.path.join(here, "zyte_api/__version__.py")) as f:
10-
exec(f.read(), about)
11-
return about["__version__"]
12-
13-
145
setup(
156
name="zyte-api",
16-
version=get_version(),
7+
version="0.6.0",
178
description="Python interface to Zyte API",
18-
long_description=open("README.rst").read(),
9+
long_description=Path("README.rst").read_text(encoding="utf-8"),
1910
long_description_content_type="text/x-rst",
2011
author="Zyte Group Ltd",
2112
author_email="[email protected]",

tests/mockserver.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from base64 import b64encode
77
from importlib import import_module
88
from subprocess import PIPE, Popen
9-
from typing import Any, Dict
9+
from typing import Any
1010
from urllib.parse import urlparse
1111

1212
from twisted.internet import reactor
@@ -119,7 +119,7 @@ def render_POST(self, request):
119119
request.setResponseCode(500)
120120
return b'["foo"]'
121121

122-
response_data: Dict[str, Any] = {
122+
response_data: dict[str, Any] = {
123123
"url": url,
124124
}
125125

@@ -137,11 +137,11 @@ def render_POST(self, request):
137137
class MockServer:
138138
def __init__(self, resource=None, port=None):
139139
resource = resource or DefaultResource
140-
self.resource = "{}.{}".format(resource.__module__, resource.__name__)
140+
self.resource = f"{resource.__module__}.{resource.__name__}"
141141
self.proc = None
142142
self.host = socket.gethostbyname(socket.gethostname())
143143
self.port = port or get_ephemeral_port()
144-
self.root_url = "http://%s:%d" % (self.host, self.port)
144+
self.root_url = f"http://{self.host}:{self.port}"
145145

146146
def __enter__(self):
147147
self.proc = Popen(
@@ -183,11 +183,7 @@ def main():
183183

184184
def print_listening():
185185
host = http_port.getHost()
186-
print(
187-
"Mock server {} running at http://{}:{}".format(
188-
resource, host.host, host.port
189-
)
190-
)
186+
print(f"Mock server {resource} running at http://{host.host}:{host.port}")
191187

192188
# Typing issue: https://github.com/twisted/twisted/issues/9909
193189
reactor.callWhenRunning(print_listening) # type: ignore[attr-defined]

0 commit comments

Comments
 (0)