Skip to content

Commit 0b3c734

Browse files
authored
Migrate from Flake8 & Autopep8 to Ruff (#14)
1 parent ecc842f commit 0b3c734

18 files changed

+204
-150
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,8 +1,10 @@
11
# Changelog
22

3-
## [1.0.5](../../releases/tag/v1.0.5) - Unreleased
3+
## [1.1.0](../../releases/tag/v1.1.0) - Unreleased
44

5-
...
5+
### Internal changes
6+
7+
- Migrate from Autopep8 and Flake8 to Ruff
68

79
## [1.0.4](../../releases/tag/v1.0.4) - 2023-10-18
810

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
## Release process
3434

Makefile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
.PHONY: clean install-dev build publish twine-check lint unit-tests type-check check-code format check-version-availability check-changelog-entry
22

3+
DIRS_WITH_CODE = src tests scripts
4+
35
clean:
4-
rm -rf build dist .mypy_cache .pytest_cache src/*.egg-info __pycache__
6+
rm -rf build dist .mypy_cache .pytest_cache .ruff_cache src/*.egg-info __pycache__
57

68
install-dev:
7-
python -m pip install --upgrade pip
9+
python3 -m pip install --upgrade pip
810
pip install --no-cache-dir -e ".[dev]"
911
pre-commit install
1012

1113
build:
12-
python -m build
14+
python3 -m build
1315

1416
publish:
15-
python -m twine upload dist/*
17+
python3 -m twine upload dist/*
1618

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

2022
lint:
21-
python3 -m flake8
23+
python3 -m ruff check $(DIRS_WITH_CODE)
2224

2325
unit-tests:
2426
python3 -m pytest -n auto -ra tests/unit
2527

2628
type-check:
27-
python3 -m mypy
29+
python3 -m mypy $(DIRS_WITH_CODE)
2830

2931
check-code: lint type-check unit-tests
3032

3133
format:
32-
python3 -m isort src tests
33-
python3 -m autopep8 --in-place --recursive src tests
34+
python3 -m ruff check --fix $(DIRS_WITH_CODE)
35+
python3 -m ruff format $(DIRS_WITH_CODE)
3436

3537
check-version-availability:
36-
python3 scripts/check_version_availability.py
38+
python scripts/check_version_availability.py
3739

3840
check-changelog-entry:
39-
python3 scripts/check_version_in_changelog.py
41+
python scripts/check_version_in_changelog.py

pyproject.toml

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,13 @@ license = { text = "Apache Software License" }
1919
name = "apify_shared"
2020
readme = "README.md"
2121
requires-python = ">=3.8"
22-
version = "1.0.5"
22+
version = "1.1.0"
2323

2424
[project.optional-dependencies]
2525
dev = [
26-
"autopep8 ~= 2.0.4",
2726
"build ~= 1.0.3",
2827
"filelock ~= 3.12.4",
29-
"flake8 ~= 6.1.0",
30-
"flake8-bugbear ~= 23.9.16",
31-
"flake8-commas ~= 2.1.0; python_version < '3.12'",
32-
"flake8-comprehensions ~= 3.14.0",
33-
"flake8-datetimez ~= 20.10.0",
34-
"flake8-docstrings ~= 1.7.0",
35-
"flake8-encodings ~= 0.5.0",
36-
"flake8-isort ~= 6.1.0",
37-
"flake8-noqa ~= 1.3.1; python_version < '3.12'",
38-
"flake8-pytest-style ~= 1.7.2",
39-
"flake8-quotes ~= 3.3.2; python_version < '3.12'",
40-
"flake8-simplify ~= 0.21.0",
41-
"flake8-unused-arguments ~= 0.0.13",
42-
"isort ~= 5.12.0",
4328
"mypy ~= 1.5.1",
44-
"pep8-naming ~= 0.13.3",
4529
"pre-commit ~= 3.4.0",
4630
"pydoc-markdown ~= 4.8.2",
4731
"pytest ~= 7.4.2",
@@ -50,6 +34,7 @@ dev = [
5034
"pytest-timeout ~= 2.2.0",
5135
"pytest-xdist ~= 3.3.1",
5236
"respx ~= 0.20.1",
37+
"ruff ~= 0.1.5",
5338
"twine ~= 4.0.2",
5439
]
5540

@@ -69,3 +54,57 @@ where = ["src"]
6954

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

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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515

1616
with open(CHANGELOG_PATH, encoding='utf-8') as changelog_file:
1717
for line in changelog_file:
18-
# 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):
18+
# The heading for the changelog entry for the given version can start with either the version number,
19+
# or the version number in a link
20+
if re.match(rf'(## )\[?{current_package_version}([\] ]|$)', line):
2021
break
2122
else:
22-
raise RuntimeError(f'There is no entry in the changelog for the current package version ({current_package_version})')
23+
raise RuntimeError(
24+
f'There is no entry in the changelog for the current package version ({current_package_version})'
25+
)

scripts/print_current_package_version.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)