Skip to content

Commit c55dd7b

Browse files
authored
Migrate from Flake8 & Autopep8 to Ruff (#133)
1 parent dcb005b commit c55dd7b

File tree

81 files changed

+2797
-1985
lines changed

Some content is hidden

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

81 files changed

+2797
-1985
lines changed

.flake8

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__pycache__
22
.mypy_cache
33
.pytest_cache
4+
.ruff_cache
45

56
.venv
67
.direnv

.isort.cfg

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

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Changelog
22
=========
33

4-
[1.3.1](../../releases/tag/v1.3.1) - Unreleased
4+
[1.4.0](../../releases/tag/v1.4.0) - Unreleased
55
-----------------------------------------------
66

7-
...
7+
### Internal changes
8+
9+
- Migrate from Autopep8 and Flake8 to Ruff
810

911
[1.3.0](../../releases/tag/v1.3.0) - 2023-11-15
1012
-----------------------------------------------

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ To install this package and its development dependencies, run `make install-dev`
2424

2525
## Formatting
2626

27-
We use `autopep8` and `isort` to automatically format the code to a common format. To run the formatting, just run `make format`.
27+
We use `ruff` to automatically format the code to a common format. To run the formatting, just run `make format`.
2828

2929
## Linting, type-checking and unit testing
3030

31-
We use `flake8` for linting, `mypy` for type checking and `pytest` for unit testing. To run these tools, just run `make check-code`.
31+
We use `ruff` for linting, `mypy` for type checking and `pytest` for unit testing. To run these tools, just run `make check-code`.
3232

3333
## Integration tests
3434

Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
.PHONY: clean install-dev build publish twine-check lint unit-tests integration-tests type-check check-code format check-version-availability check-changelog-entry build-api-reference
22

3+
DIRS_WITH_CODE = src tests scripts
4+
35
# This is default for local testing, but GitHub workflows override it to a higher value in CI
46
INTEGRATION_TESTS_CONCURRENCY = 1
57

68
clean:
79
rm -rf build dist .mypy_cache .pytest_cache src/*.egg-info __pycache__
810

911
install-dev:
10-
python -m pip install --upgrade pip
12+
python3 -m pip install --upgrade pip
1113
pip install --no-cache-dir -e ".[dev,scrapy]"
1214
pre-commit install
1315

1416
build:
15-
python -m build
17+
python3 -m build
1618

1719
publish:
18-
python -m twine upload dist/*
20+
python3 -m twine upload dist/*
1921

2022
twine-check:
21-
python -m twine check dist/*
23+
python3 -m twine check dist/*
2224

2325
lint:
24-
python3 -m flake8
26+
python3 -m ruff check $(DIRS_WITH_CODE)
2527

2628
unit-tests:
2729
python3 -m pytest -n auto -ra tests/unit
@@ -30,13 +32,13 @@ integration-tests:
3032
python3 -m pytest -n $(INTEGRATION_TESTS_CONCURRENCY) -ra tests/integration
3133

3234
type-check:
33-
python3 -m mypy
35+
python3 -m mypy $(DIRS_WITH_CODE)
3436

3537
check-code: lint type-check unit-tests
3638

3739
format:
38-
python3 -m isort src tests
39-
python3 -m autopep8 --in-place --recursive src tests
40+
python3 -m ruff check --fix $(DIRS_WITH_CODE)
41+
python3 -m ruff format $(DIRS_WITH_CODE)
4042

4143
check-version-availability:
4244
python3 scripts/check_version_availability.py

pyproject.toml

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
[project]
22
name = "apify"
3-
version = "1.3.1"
3+
version = "1.4.0"
44
description = "Apify SDK for Python"
55
readme = "README.md"
6-
license = {text = "Apache Software License"}
7-
authors = [
8-
{name = "Apify Technologies s.r.o.", email = "[email protected]"},
9-
]
6+
license = { text = "Apache Software License" }
7+
authors = [{ name = "Apify Technologies s.r.o.", email = "[email protected]" }]
108
keywords = ["apify", "sdk", "actor", "scraping", "automation"]
119

1210
classifiers = [
@@ -26,8 +24,8 @@ requires-python = ">=3.8"
2624
dependencies = [
2725
"aiofiles >= 22.1.0",
2826
"aioshutil >= 1.0",
29-
"apify-client ~= 1.5.0",
30-
"apify-shared ~= 1.0.4",
27+
"apify-client ~= 1.6.0",
28+
"apify-shared ~= 1.1.0",
3129
"colorama >= 0.4.6",
3230
"cryptography >= 39.0.0",
3331
"httpx >= 0.24.1",
@@ -40,25 +38,9 @@ dependencies = [
4038

4139
[project.optional-dependencies]
4240
dev = [
43-
"autopep8 ~= 2.0.4",
4441
"build ~= 1.0.3",
4542
"filelock ~= 3.12.4",
46-
"flake8 ~= 6.1.0",
47-
"flake8-bugbear ~= 23.9.16",
48-
"flake8-commas ~= 2.1.0; python_version < '3.12'",
49-
"flake8-comprehensions ~= 3.14.0",
50-
"flake8-datetimez ~= 20.10.0",
51-
"flake8-docstrings ~= 1.7.0",
52-
"flake8-encodings ~= 0.5.0",
53-
"flake8-isort ~= 6.1.0",
54-
"flake8-noqa ~= 1.3.1; python_version < '3.12'",
55-
"flake8-pytest-style ~= 1.7.2",
56-
"flake8-quotes ~= 3.3.2; python_version < '3.12'",
57-
"flake8-simplify ~= 0.21.0",
58-
"flake8-unused-arguments ~= 0.0.13",
59-
"isort ~= 5.12.0",
60-
"mypy ~= 1.5.1",
61-
"pep8-naming ~= 0.13.3",
43+
"mypy ~= 1.7.1",
6244
"pre-commit ~= 3.4.0",
6345
"pydoc-markdown ~= 4.8.2",
6446
"pytest ~= 7.4.2",
@@ -67,6 +49,7 @@ dev = [
6749
"pytest-timeout ~= 2.2.0",
6850
"pytest-xdist ~= 3.3.1",
6951
"respx ~= 0.20.1",
52+
"ruff ~= 0.1.6",
7053
"twine ~= 4.0.2",
7154
"types-aiofiles ~= 23.2.0.0",
7255
"types-colorama ~= 0.4.15.11",
@@ -94,3 +77,72 @@ include = ["apify*"]
9477

9578
[tool.setuptools.package-data]
9679
apify = ["py.typed"]
80+
81+
[tool.ruff]
82+
line-length = 150
83+
select = ["ALL"]
84+
ignore = [
85+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {filename}
86+
"BLE001", # Do not catch blind exception
87+
"C901", # `{name}` is too complex
88+
"COM812", # This rule may cause conflicts when used with the formatter
89+
"D100", # Missing docstring in public module
90+
"D104", # Missing docstring in public package
91+
"EM", # flake8-errmsg
92+
"G004", # Logging statement uses f-string
93+
"ISC001", # This rule may cause conflicts when used with the formatter
94+
"FIX", # flake8-fixme
95+
"PGH003", # Use specific rule codes when ignoring type issues
96+
"PLR0911", # Too many return statements
97+
"PLR0913", # Too many arguments in function definition
98+
"PLR0915", # Too many statements
99+
"PTH", # flake8-use-pathlib
100+
"PYI034", # `__aenter__` methods in classes like `{name}` usually return `self` at runtime
101+
"PYI036", # The second argument in `__aexit__` should be annotated with `object` or `BaseException | None`
102+
"S102", # Use of `exec` detected
103+
"S105", # Possible hardcoded password assigned to
104+
"S106", # Possible hardcoded password assigned to argument: "{name}"
105+
"S301", # `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue
106+
"S303", # Use of insecure MD2, MD4, MD5, or SHA1 hash function
107+
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
108+
"TD002", # Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...
109+
"TID252", # Relative imports from parent modules are bannedRuff
110+
"TRY003", # Avoid specifying long messages outside the exception class
111+
112+
# TODO: Remove this once the following issue is fixed
113+
# https://github.com/apify/apify-sdk-python/issues/150
114+
"SLF001", # Private member accessed: `{name}`
115+
]
116+
117+
[tool.ruff.format]
118+
quote-style = "single"
119+
indent-style = "space"
120+
121+
[tool.ruff.lint.per-file-ignores]
122+
"**/__init__.py" = [
123+
"F401", # Unused imports
124+
]
125+
"**/{scripts}/*" = [
126+
"D", # Everything from the pydocstyle
127+
"INP001", # File {filename} is part of an implicit namespace package, add an __init__.py
128+
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
129+
"T20", # flake8-print
130+
]
131+
"**/{tests}/*" = [
132+
"D", # Everything from the pydocstyle
133+
"INP001", # File {filename} is part of an implicit namespace package, add an __init__.py
134+
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
135+
"S101", # Use of assert detected
136+
"T20", # flake8-print
137+
"TRY301", # Abstract `raise` to an inner function
138+
]
139+
140+
[tool.ruff.lint.flake8-quotes]
141+
docstring-quotes = "double"
142+
inline-quotes = "single"
143+
144+
[tool.ruff.lint.isort]
145+
known-first-party = ["apify", "apify_client", "apify_shared"]
146+
147+
[tool.ruff.lint.pydocstyle]
148+
convention = "google"

scripts/check_version_availability.py

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
25
from utils import get_current_package_version, get_published_package_versions
36

47
# Checks whether the current package version number was not already used in a published release.

scripts/check_version_in_changelog.py

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
import re
46

57
from utils import REPO_ROOT, get_current_package_version
@@ -16,7 +18,7 @@
1618
with open(CHANGELOG_PATH, encoding='utf-8') as changelog_file:
1719
for line in changelog_file:
1820
# The heading for the changelog entry for the given version can start with either the version number, or the version number in a link
19-
if re.match(fr'\[?{current_package_version}([\] ]|$)', line):
21+
if re.match(rf'\[?{current_package_version}([\] ]|$)', line):
2022
break
2123
else:
2224
raise RuntimeError(f'There is no entry in the changelog for the current package version ({current_package_version})')

scripts/print_current_package_version.py

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
from utils import get_current_package_version
46

57
# Print the current package version from the pyproject.toml file to stdout

0 commit comments

Comments
 (0)