Skip to content

Commit 8a4790c

Browse files
Merge pull request #1787 from VWS-Python/switch-to-ruff
Switch from flake8/isort to ruff
2 parents 2f8280c + 66968c5 commit 8a4790c

17 files changed

+99
-125
lines changed

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@ lint: \
1010
black \
1111
check-manifest \
1212
doc8 \
13-
flake8 \
14-
isort \
1513
linkcheck \
1614
mypy \
15+
ruff \
1716
pip-extra-reqs \
1817
pip-missing-reqs \
1918
pyroma \
2019
spelling \
2120
vulture \
22-
pylint \
23-
pydocstyle \
21+
pylint
2422

2523
.PHONY: fix-lint
2624
fix-lint: \
27-
add-trailing-comma \
28-
autoflake \
2925
fix-black \
30-
fix-isort
26+
fix-ruff
3127

3228
.PHONY: docs
3329
docs:

docs/source/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Documentation."""

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
source_suffix = ".rst"
2727
master_doc = "index"
2828

29-
year = datetime.datetime.now().year
29+
year = datetime.datetime.now(tz=datetime.UTC).year
3030
project_copyright = f"{year}, {author}"
3131

3232
# The version info for the project you're documenting, acts as replacement for

lint.mk

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ check-manifest:
2222
doc8:
2323
doc8 .
2424

25-
.PHONY: flake8
26-
flake8:
27-
flake8 .
25+
.PHONY: ruff
26+
ruff:
27+
ruff .
2828

29-
.PHONY: isort
30-
isort:
31-
isort --check-only .
32-
33-
.PHONY: fix-isort
34-
fix-isort:
35-
isort .
29+
.PHONY: fix-ruff
30+
fix-ruff:
31+
ruff --fix .
3632

3733
.PHONY: pip-extra-reqs
3834
pip-extra-reqs:
@@ -61,22 +57,3 @@ linkcheck:
6157
.PHONY: spelling
6258
spelling:
6359
$(MAKE) -C docs/ spelling SPHINXOPTS=$(SPHINXOPTS)
64-
65-
.PHONY: autoflake
66-
autoflake:
67-
autoflake \
68-
--in-place \
69-
--recursive \
70-
--remove-all-unused-imports \
71-
--remove-unused-variables \
72-
--expand-star-imports \
73-
--exclude _vendor,release \
74-
.
75-
76-
.PHONY: pydocstyle
77-
pydocstyle:
78-
pydocstyle
79-
80-
.PHONY: add-trailing-comma
81-
add-trailing-comma:
82-
add-trailing-comma $$(find . -type f -name '*.py') --exit-zero-even-if-changed

pyproject.toml

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@
4848
'too-many-return-statements',
4949
'too-many-lines',
5050
'locally-disabled',
51-
# Let flake8 handle long lines
51+
# Let ruff handle long lines
5252
'line-too-long',
53-
# Let flake8 handle unused imports
53+
# Let ruff handle unused imports
5454
'unused-import',
55-
# Let isort deal with sorting
55+
# Let ruff deal with sorting
5656
'ungrouped-imports',
5757
# We don't need everything to be documented because of mypy
5858
'missing-type-doc',
5959
'missing-return-type-doc',
6060
# Too difficult to please
6161
'duplicate-code',
62-
# Let isort handle imports
62+
# Let ruff handle imports
6363
'wrong-import-order',
6464
# mypy does not want untyped parameters.
6565
'useless-type-doc',
@@ -88,11 +88,6 @@
8888

8989
line-length = 79
9090

91-
[tool.isort]
92-
93-
multi_line_output = 3
94-
include_trailing_comma = true
95-
9691
[tool.coverage.run]
9792

9893
branch = true
@@ -106,16 +101,7 @@ log_cli = true
106101

107102
ignore = [
108103
"*.enc",
109-
".appveyor.yml",
110-
".coveragerc",
111-
".isort.cfg",
112-
".markdownlint.json",
113-
".pydocstyle",
114-
".remarkrc",
115-
".readthedocs.yml",
116104
"readthedocs.yaml",
117-
".style.yapf",
118-
".travis.yml",
119105
"CHANGELOG.rst",
120106
"CODE_OF_CONDUCT.rst",
121107
"CONTRIBUTING.rst",
@@ -128,9 +114,6 @@ ignore = [
128114
"docs",
129115
"docs/**",
130116
".git_archival.txt",
131-
"mypy.ini",
132-
"pylintrc",
133-
"pytest.ini",
134117
"spelling_private_dict.txt",
135118
"tests",
136119
"tests-pylintrc",
@@ -164,23 +147,50 @@ module = [
164147

165148
ignore_missing_imports = true
166149

167-
[tool.pydocstyle]
168-
# We do not have summary lines, care about "mood", or need sections with
169-
# dash underlined titles.
170-
ignore = [
171-
'D200',
172-
'D205',
173-
'D400',
174-
'D415',
175-
'D202',
176-
'D203',
177-
'D212',
178-
'D401',
179-
'D406',
180-
'D407',
181-
'D413',
182-
]
183-
184150
[build-system]
185151
requires = ["setuptools", "pip", "wheel"]
186152
build-backend = "setuptools.build_meta"
153+
154+
[tool.ruff]
155+
select = ["ALL"]
156+
157+
ignore = [
158+
# We do not annotate the type of 'self'.
159+
"ANN101",
160+
# We are happy to manage our own "complexity".
161+
"C901",
162+
# Allow our chosen docstring line-style - no one-line summary.
163+
"D200",
164+
"D203",
165+
"D205",
166+
"D212",
167+
"D213",
168+
# Allow backslashes in a docstring.
169+
# See https://click.palletsprojects.com/en/8.0.x/documentation/#preventing-rewrapping.
170+
"D301",
171+
# It is too much work to make every docstring imperative.
172+
"D401",
173+
# We ignore some docstyle errors which do not apply to Google style
174+
# docstrings.
175+
"D406",
176+
"D407",
177+
# We have an existing interface to support and so we do not want to change
178+
# exception names.
179+
"N818",
180+
# Ignore "too-many-*" errors as they seem to get in the way more than
181+
# helping.
182+
"PLR0912",
183+
"PLR0913",
184+
# Allow 'assert' as we use it for tests.
185+
"S101",
186+
# Allow imports which are only used for type checking to be outside type
187+
# checking blocks.
188+
"TCH002",
189+
"TCH003",
190+
]
191+
192+
[tool.ruff.per-file-ignores]
193+
"tests/test_*.py" = [
194+
# Do not require tests to have a one-line summary.
195+
"D205",
196+
]

readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
build:
44
os: ubuntu-20.04
55
tools:
6-
python: "3.9"
6+
python: "3.11"
77

88
python:
99
install:

requirements/dev-requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ Sphinx-Substitution-Extensions==2022.2.16
44
Sphinx==6.1.3
55
VWS-Python-Mock==2021.12.27.3
66
VWS-Test-Fixtures==2022.1.3
7-
add-trailing-comma==2.4.0
8-
autoflake==2.0.1
97
black==23.1.0
108
check-manifest==0.49
119
doc8==1.1.1
1210
dodgy==0.2.1 # Look for uploaded secrets
13-
flake8==6.0.0 # Lint
1411
freezegun==1.2.2
1512
furo==2022.12.7
16-
isort==5.12.0 # Lint imports
1713
mypy==1.0.0 # Type checking
1814
pip_check_reqs==2.4.3
1915
pydocstyle==6.3.0 # Lint docstrings
@@ -22,6 +18,7 @@ pylint==2.15.5 # Lint
2218
pyroma==4.1 # Packaging best practices checker
2319
pytest-cov==4.0.0 # Measure code coverage
2420
pytest==7.2.1 # Test runners
21+
ruff==0.0.247
2522
sphinx-autodoc-typehints==1.22
2623
sphinx-prompt==1.5.0
2724
sphinxcontrib-spelling==7.7.0

setup.cfg

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[flake8]
2-
exclude=./.eggs,
3-
./build/,
4-
51
[bdist_wheel]
62
universal = 1
73

spelling_private_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ todo
8787
travis
8888
txt
8989
unmocked
90+
untyped
9091
url
9192
usefixtures
9293
validators

src/vws/query.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def query(
9292
9393
Returns:
9494
An ordered list of target details of matching targets.
95-
""" # noqa: E501
95+
"""
9696
image_content = image.getvalue()
9797
body = {
9898
"image": ("image.jpeg", image_content, "image/jpeg"),
@@ -108,7 +108,7 @@ def query(
108108
(
109109
content,
110110
content_type_header,
111-
) = encode_multipart_formdata( # type:ignore
111+
) = encode_multipart_formdata( # type:ignore[no-untyped-call]
112112
fields=body,
113113
)
114114
method = "POST"
@@ -166,8 +166,9 @@ def query(
166166
target_data_dict = item["target_data"]
167167
metadata = target_data_dict["application_metadata"]
168168
timestamp_string = target_data_dict["target_timestamp"]
169-
target_timestamp = datetime.datetime.utcfromtimestamp(
169+
target_timestamp = datetime.datetime.fromtimestamp(
170170
timestamp_string,
171+
tz=datetime.UTC,
171172
)
172173
target_data = TargetData(
173174
name=target_data_dict["name"],

0 commit comments

Comments
 (0)