Skip to content

Commit dfd9b9c

Browse files
authored
Migrate from Flake8 & Autopep8 to Ruff (#161)
1 parent f726af9 commit dfd9b9c

Some content is hidden

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

59 files changed

+1908
-1640
lines changed

.flake8

Lines changed: 0 additions & 29 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.5.1](../../releases/tag/v1.5.1) - Unreleased
4+
[1.6.0](../../releases/tag/v1.6.0) - Unreleased
55
-----------------------------------------------
66

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

911
[1.5.0](../../releases/tag/v1.5.0) - 2023-10-18
1012
-----------------------------------------------

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Environment
44

5-
For local development, it is required to have Python 3.8 installed.
5+
For local development, it is required to have Python 3.8 (or a later version) installed.
66

77
It is recommended to set up a virtual environment while developing this package to isolate your development environment,
88
however, due to the many varied ways Python can be installed and virtual environments can be set up,
@@ -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-async-docstrings fix-async-docstrings 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]"
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 check-async-docstrings 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-async-docstrings:
4244
python3 scripts/check_async_docstrings.py

pyproject.toml

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
[project]
22
name = "apify_client"
3-
version = "1.5.1"
3+
version = "1.6.0"
44
description = "Apify API client for Python"
55
readme = "README.md"
6-
license = {text = "Apache Software License"}
7-
authors = [
8-
{name = "Apify Technologies s.r.o.", email = "support@apify.com"},
9-
]
6+
license = { text = "Apache Software License" }
7+
authors = [{ name = "Apify Technologies s.r.o.", email = "support@apify.com" }]
108
keywords = ["apify", "api", "client", "scraping", "automation"]
119

1210
classifiers = [
@@ -24,30 +22,14 @@ classifiers = [
2422

2523
requires-python = ">=3.8"
2624
dependencies = [
27-
"apify-shared ~= 1.0.1",
28-
"httpx >= 0.24.1",
25+
"apify-shared ~= 1.1.0",
26+
"httpx ~= 0.25.1",
2927
]
3028

3129
[project.optional-dependencies]
3230
dev = [
33-
"autopep8 ~= 2.0.4",
3431
"build ~= 1.0.3",
35-
"flake8 ~= 6.1.0",
36-
"flake8-bugbear ~= 23.9.16",
37-
"flake8-commas ~= 2.1.0; python_version < '3.12'",
38-
"flake8-comprehensions ~= 3.14.0",
39-
"flake8-datetimez ~= 20.10.0",
40-
"flake8-docstrings ~= 1.7.0",
41-
"flake8-encodings ~= 0.5.0",
42-
"flake8-isort ~= 6.1.0",
43-
"flake8-noqa ~= 1.3.1; python_version < '3.12'",
44-
"flake8-pytest-style ~= 1.7.2",
45-
"flake8-quotes ~= 3.3.2; python_version < '3.12'",
46-
"flake8-simplify ~= 0.21.0",
47-
"flake8-unused-arguments ~= 0.0.13",
48-
"isort ~= 5.12.0",
49-
"mypy ~= 1.5.1",
50-
"pep8-naming ~= 0.13.3",
32+
"mypy ~= 1.7.0",
5133
"pre-commit ~= 3.4.0",
5234
"pydoc-markdown ~= 4.8.2",
5335
"pytest ~= 7.4.2",
@@ -56,6 +38,7 @@ dev = [
5638
"pytest-timeout ~= 2.2.0",
5739
"pytest-xdist ~= 3.3.1",
5840
"redbaron ~= 0.9.2",
41+
"ruff ~= 0.1.5",
5942
"twine ~= 4.0.2",
6043
]
6144

@@ -77,3 +60,56 @@ include = ["apify_client*"]
7760

7861
[tool.setuptools.package-data]
7962
apify_client = ["py.typed"]
63+
64+
[tool.ruff]
65+
line-length = 150
66+
select = ["ALL"]
67+
ignore = [
68+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {filename}
69+
"BLE001", # Do not catch blind exception
70+
"COM812", # This rule may cause conflicts when used with the formatter
71+
"D100", # Missing docstring in public module
72+
"D104", # Missing docstring in public package
73+
"EM", # flake8-errmsg
74+
"ISC001", # This rule may cause conflicts when used with the formatter
75+
"FIX", # flake8-fixme
76+
"PGH003", # Use specific rule codes when ignoring type issues
77+
"PLR0913", # Too many arguments in function definition
78+
"PTH123", # `open()` should be replaced by `Path.open()`
79+
"S102", # Use of `exec` detected
80+
"S105", # Possible hardcoded password assigned to
81+
"TID252", # Relative imports from parent modules are bannedRuff
82+
"TRY003", # Avoid specifying long messages outside the exception class
83+
]
84+
85+
[tool.ruff.format]
86+
quote-style = "single"
87+
indent-style = "space"
88+
89+
[tool.ruff.lint.per-file-ignores]
90+
"**/__init__.py" = [
91+
"F401", # Unused imports
92+
]
93+
"**/{scripts}/*" = [
94+
"D", # Everything from the pydocstyle
95+
"INP001", # File {filename} is part of an implicit namespace package, add an __init__.py
96+
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
97+
"T20", # flake8-print
98+
]
99+
"**/{tests}/*" = [
100+
"D", # Everything from the pydocstyle
101+
"INP001", # File {filename} is part of an implicit namespace package, add an __init__.py
102+
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
103+
"T20", # flake8-print
104+
"S101", # Use of assert detected
105+
]
106+
107+
[tool.ruff.lint.flake8-quotes]
108+
docstring-quotes = "double"
109+
inline-quotes = "single"
110+
111+
[tool.ruff.lint.isort]
112+
known-first-party = ["apify", "apify_client", "apify_shared"]
113+
114+
[tool.ruff.lint.pydocstyle]
115+
convention = "google"

scripts/check_async_docstrings.py

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
import re
24
import sys
35
from pathlib import Path
@@ -12,7 +14,7 @@
1214

1315
# Go through every Python file in that directory
1416
for client_source_path in clients_path.glob('**/*.py'):
15-
with open(client_source_path, 'r', encoding='utf-8') as source_file:
17+
with open(client_source_path, encoding='utf-8') as source_file:
1618
# Read the source file and parse the code using Red Baron
1719
red = RedBaron(source_code=source_file.read())
1820

scripts/check_version_availability.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
23
from utils import get_current_package_version, get_published_package_versions
34

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

scripts/check_version_in_changelog.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
with open(CHANGELOG_PATH, encoding='utf-8') as changelog_file:
1717
for line in changelog_file:
1818
# 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):
19+
if re.match(rf'\[?{current_package_version}([\] ]|$)', line):
2020
break
2121
else:
2222
raise RuntimeError(f'There is no entry in the changelog for the current package version ({current_package_version})')

0 commit comments

Comments
 (0)