Skip to content

Commit 997f6c8

Browse files
authored
chore: migrate fully to ruff (#313)
- Eliminate `flake8`, `autopep8` and `pylint` - `ruff` is faster
1 parent a2674cf commit 997f6c8

File tree

4 files changed

+263
-348
lines changed

4 files changed

+263
-348
lines changed

Makefile

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,10 @@ lint_markdown:
2626
mdl -r ~MD013,~MD029,~MD033 README.md
2727

2828
format:
29-
uv run autoflake --in-place -r --remove-all-unused-imports --remove-unused-variables adbe
30-
# See full error code list at https://pypi.org/project/autopep8/#features
31-
uv run autopep8 --recursive --in-place --select W292,W293,W391,W504,E121,E122,E123,E126,E128,E129,E131,E202,E225,E226,E241,E301,E302,E303,E704,E731 adbe
32-
uv run ruff check --config pyproject.toml --fix adbe tests
29+
uv run ruff check --config pyproject.toml --fix --unsafe-fixes --preview adbe tests
3330

3431
lint_python:
35-
uv run -- autoflake --check-diff -r --quiet --remove-all-unused-imports --remove-unused-variables adbe
36-
# Fail if there are Python syntax errors or undefined names
37-
uv run -- flake8 adbe --count --select=E9,F63,F7,F82 --show-source --statistics
38-
# W503 has been deprecated in favor of W504 - https://www.flake8rules.com/rules/W503.html
39-
uv run -- flake8 adbe --count --show-source --statistics --max-line-length=88 --ignore=E501,W503
40-
# Config file is specified for brevity
41-
uv run ruff check --config pyproject.toml adbe
42-
# E0602 is due to undefined variable unicode which is defined only for Python 2
43-
# W0511 is fixme due to TODOs in the code.
44-
# C0111: Missing function docstring (missing-docstring)
45-
uv run -- pylint --disable=C0103,C0111,C0209,W1514 release.py
46-
uv run -- pylint adbe/*.py tests/*.py --disable=R0123,R0911,R0912,R0914,R0915,R1705,R1710,C0103,C0111,C0209,C0301,C0302,C1801,W0511,W0602,W0603
47-
uv run -- flake8 adbe --count --ignore=F401,E126,E501,W503 --show-source --statistics
48-
# Default complexity limit is 10
49-
# Default line length limit is 127
50-
uv run -- flake8 adbe --count --exit-zero --ignore=F401,E126,E501,W503 --max-complexity=13 --max-line-length=127 --statistics
32+
uv run ruff check --preview --config pyproject.toml adbe tests
5133

5234
# To run a single test, for example, test_file_move3, try this
5335
# python3 -m pytest -v tests/adbe_tests.py -k test_file_move3

adbe/adb_enhanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ def _perform_xapk_install(file_path: str) -> None:
16941694
# Unzip the xapk file
16951695
with tempfile.TemporaryDirectory() as temp_dir:
16961696
print_verbose(f"Unzipping {file_path} to {temp_dir}")
1697-
with zipfile.ZipFile(file_path, 'r') as zip_ref:
1697+
with zipfile.ZipFile(file_path, "r") as zip_ref:
16981698
zip_ref.extractall(temp_dir)
16991699

17001700
result = execute_adb_command2(f"install-multiple -r {temp_dir}/*.apk")

pyproject.toml

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,102 @@ readme = "README.md"
1515
license = "Apache-2.0"
1616
requires-python = ">=3.10"
1717
dependencies = [
18-
"docopt>=0.6.2",
19-
"psutil>=7.0.0",
18+
"docopt==0.6.2",
19+
"psutil==7.0.0",
2020
]
2121

2222
[project.scripts]
2323
adbe = "adbe.main:main"
2424

2525
[dependency-groups]
2626
dev = [
27-
"autoflake>=2.3.1",
28-
"autopep8>=2.3.2",
29-
"flake8>=7.2.0",
30-
"pylint>=3.3.6",
31-
"pytest>=8.3.5",
32-
"ruff>=0.11.4",
33-
"setuptools>=78.1.0",
34-
"types-docopt>=0.6.11.20241107",
35-
"types-psutil>=7.0.0.20250401",
36-
"twine>=6.1.0",
37-
"wheel>=0.45.1",
27+
"pytest==8.3.5",
28+
"ruff==0.11.4",
29+
"setuptools==78.1.0",
30+
"types-docopt==0.6.11.20241107",
31+
"types-psutil==7.0.0.20250401",
32+
"twine==6.1.0",
33+
"wheel==0.45.1",
3834
]
3935

36+
[tool.ruff]
37+
# Same as Black.
38+
line-length = 170
39+
40+
4041
[tool.ruff.lint]
42+
# Enable the pycodestyle (`E`) and Pyflakes (`F`) rules by default.
43+
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
44+
# McCabe complexity (`C901`) by default.
45+
select = ["C", "W", "E", "F"]
46+
ignore = [
47+
"ANN401", # https://docs.astral.sh/ruff/rules/any-type/ is not avoidable
48+
"PLR2004", # https://docs.astral.sh/ruff/rules/magic-value-comparison/ - too much work to fix this
49+
"S101", # False positive in test code
50+
"T201", # https://docs.astral.sh/ruff/rules/print/ is unavoidable for a CLI tool
51+
52+
# subprocess is required for CLI
53+
"S105", # false positive in this case
54+
"S404", # https://docs.astral.sh/ruff/rules/suspicious-subprocess-import/
55+
"S602", # https://docs.astral.sh/ruff/rules/subprocess-popen-with-shell-equals-true/
56+
"S607", # https://docs.astral.sh/ruff/rules/start-process-with-partial-path/ is not a concern
57+
58+
]
59+
60+
# Allow autofix for all enabled rules (when `--fix`) is provided.
61+
fixable = ["ALL"]
62+
unfixable = []
63+
per-file-ignores = { }
64+
4165
extend-select = [
66+
"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
67+
"ANN", # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann - eventually enable this
68+
"ARG", # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg
69+
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async
70+
"B", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
71+
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
72+
"C90", # https://docs.astral.sh/ruff/rules/#mccabe-c90
73+
"COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com
74+
"DTZ", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
75+
"E", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
76+
"EXE", # https://docs.astral.sh/ruff/rules/#flake8-executable-exe
77+
"F", # https://docs.astral.sh/ruff/rules/#pyflakes-f
78+
"FAST", # https://docs.astral.sh/ruff/rules/#fastapi-fast
79+
# "FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt - eventually enable this
80+
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly
81+
"FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb
82+
"G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
4283
"I", # https://docs.astral.sh/ruff/rules/#isort-i
84+
"ICN", # https://docs.astral.sh/ruff/rules/#flake8-import-conventions-icn
85+
"INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
86+
"ISC", # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc
87+
"LOG", # https://docs.astral.sh/ruff/rules/#flake8-logging-log
88+
"N", # https://docs.astral.sh/ruff/rules/#pep8-naming-n
89+
"NPY", # https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy
90+
"PD", # https://docs.astral.sh/ruff/rules/#pandas-vet-pd
91+
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf
92+
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
93+
# "PL", # https://docs.astral.sh/ruff/rules/#pylint-pl - eventually enable this
94+
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
95+
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
96+
"PYI", # https://docs.astral.sh/ruff/rules/#flake8-pyi-pyi
97+
"Q", # https://docs.astral.sh/ruff/rules/#flake8-quotes-q
98+
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret
99+
"RSE", # https://docs.astral.sh/ruff/rules/#flake8-raise-rse
100+
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
101+
"S", # https://docs.astral.sh/ruff/rules/#flake8-bandit-s
102+
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
103+
"SLF", # https://docs.astral.sh/ruff/rules/#flake8-self-slf
104+
"SLOT", # https://docs.astral.sh/ruff/rules/#flake8-slots-slot
105+
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
106+
"T20", # https://docs.astral.sh/ruff/rules/#flake8-print-t20
107+
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up
108+
"W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
43109
]
110+
111+
[tool.ruff.lint.isort]
112+
combine-as-imports = true # Optional: combine 'as' imports on a single line
113+
114+
[tool.ruff.lint.mccabe]
115+
# Flag errors (`C901`) whenever the complexity level exceeds 12
116+
max-complexity = 12

0 commit comments

Comments
 (0)