Skip to content

Commit 66c8920

Browse files
authored
chore: add make format, improve make lint_python3 (#269)
* chore: more lint fixes * chore: add `make format`, improve `make lint_python3`
1 parent b009aa4 commit 66c8920

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

Makefile

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ documentation:
66
pandoc --from=markdown --to=rst --output=docs/README.rst README.md && cd docs && make html
77

88
clean:
9-
rm -rf build/ dist/ # Cleanup build dir
9+
rm -rf dist/ # Cleanup build dir
1010

1111
setup:
1212
brew install pandoc sphinx-doc uv
@@ -25,19 +25,36 @@ release_production: documentation
2525
lint_markdown:
2626
mdl -r ~MD013,~MD029,~MD033 README.md
2727

28+
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
33+
uv run isort --line-length 88 --skip-gitignore adbe
34+
uv run isort --line-length 88 --skip-gitignore tests
35+
2836
lint_python3:
29-
# E0602 is due to undefined variable unicode which is defined only for Python 2
30-
# W0511 is fixme due to TODOs in the code.
31-
# adbe/adbe.py:756:8: W0601: Global variable 'screen_record_file_path_on_device' undefined at the module level (global-variable-undefined)
32-
# adbe/adbe.py:764:8: W0601: Global variable 'screen_record_file_path_on_device' undefined at the module level (global-variable-undefined)
33-
# adbe/adbe.py:752:4: W0621: Redefining name 'screen_record_file_path_on_device' from outer scope (line 759) (redefined-outer-name)
34-
# C0111: Missing function docstring (missing-docstring)
37+
uv run -- autoflake --check-diff -r --quiet --remove-all-unused-imports --remove-unused-variables adbe
38+
# Fail if there are Python syntax errors or undefined names
39+
uv run -- flake8 adbe --count --select=E9,F63,F7,F82 --show-source --statistics
40+
# W503 has been deprecated in favor of W504 - https://www.flake8rules.com/rules/W503.html
41+
uv run -- flake8 adbe --count --show-source --statistics --max-line-length=88 --ignore=E501,W503
42+
# Config file is specified for brevity
43+
uv run ruff check --config pyproject.toml adbe
44+
# Same line length as Black
45+
uv run isort --check --diff --line-length 88 --skip-gitignore .
46+
# E0602 is due to undefined variable unicode which is defined only for Python 2
47+
# W0511 is fixme due to TODOs in the code.
48+
# adbe/adbe.py:756:8: W0601: Global variable 'screen_record_file_path_on_device' undefined at the module level (global-variable-undefined)
49+
# adbe/adbe.py:764:8: W0601: Global variable 'screen_record_file_path_on_device' undefined at the module level (global-variable-undefined)
50+
# adbe/adbe.py:752:4: W0621: Redefining name 'screen_record_file_path_on_device' from outer scope (line 759) (redefined-outer-name)
51+
# C0111: Missing function docstring (missing-docstring)
3552
uv run -- pylint --disable=C0103,C0111,C0209,W1514 release.py
3653
uv run -- pylint adbe/*.py tests/*.py --disable=R0123,R0911,R0912,R0914,R0915,R1705,R1710,C0103,C0111,C0209,C0301,C0302,C1801,W0511,W0621,W0601,W0602,W0603
37-
uv run -- flake8 adbe --count --ignore=F401,E126,E501,W504 --show-source --statistics
54+
uv run -- flake8 adbe --count --ignore=F401,E126,E501,W503 --show-source --statistics
3855
# Default complexity limit is 10
3956
# Default line length limit is 127
40-
uv run -- flake8 adbe --count --exit-zero --ignore=F401,E126,E501,W504 --max-complexity=13 --max-line-length=127 --statistics
57+
uv run -- flake8 adbe --count --exit-zero --ignore=F401,E126,E501,W503 --max-complexity=13 --max-line-length=127 --statistics
4158

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

adbe/adb_enhanced.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ def _get_device_serials() -> [str]:
441441
if "unauthorized" in device_info:
442442
device_info = ' '.join(device_info.split()[1:])
443443
print_error(
444-
('Unlock Device "%s" and give USB debugging access to ' +
445-
'this PC/Laptop by unlocking and reconnecting ' +
446-
'the device. More info about this device: "%s"\n') % (
444+
('Unlock Device "%s" and give USB debugging access to '
445+
+ 'this PC/Laptop by unlocking and reconnecting '
446+
+ 'the device. More info about this device: "%s"\n') % (
447447
device_serial, device_info))
448448
else:
449449
device_serials.append(device_serial)
@@ -626,8 +626,8 @@ def dump_screenrecord(filepath):
626626

627627
# I have tested that on API 23 and above this works. Till Api 22, on emulator, it does not.
628628
if api_version < 23 and _is_emulator():
629-
print_error_and_exit("screenrecord is not supported on emulator below API 23\n" +
630-
"Source: https://issuetracker.google.com/issues/36982354")
629+
print_error_and_exit("screenrecord is not supported on emulator below API 23\n"
630+
+ "Source: https://issuetracker.google.com/issues/36982354")
631631

632632
original_sigint_handler = None
633633

@@ -1514,10 +1514,10 @@ def _get_permissions_info_above_api_23(app_info_dump: str):
15141514
elif app_info_dump.find(denied_pattern) >= 0:
15151515
runtime_denied_permissions.append(permission)
15161516
runtime_not_granted_permissions = list(filter(
1517-
lambda p: p not in runtime_granted_permissions and
1518-
p not in runtime_denied_permissions and
1519-
p not in install_time_granted_permissions and
1520-
p not in install_time_denied_permissions, requested_permissions))
1517+
lambda p: p not in runtime_granted_permissions
1518+
and p not in runtime_denied_permissions
1519+
and p not in install_time_granted_permissions
1520+
and p not in install_time_denied_permissions, requested_permissions))
15211521

15221522
permissions_info_msg = ''
15231523
permissions_info_msg += '\nPermissions:\n\n'
@@ -1917,9 +1917,9 @@ def print_notifications():
19171917
notification_actions = []
19181918
action_strings = re.findall(r"actions=\{(.*?)\n\}", output_for_this_notification, re.MULTILINE | re.DOTALL)
19191919
if len(action_strings) > 0 and (
1920-
i + 1 >= len(notification_records) or
1921-
output_for_this_notification.find(action_strings[0]) >
1922-
output_for_this_notification.find(notification_records[i + 1])):
1920+
i + 1 >= len(notification_records)
1921+
or output_for_this_notification.find(action_strings[0])
1922+
> output_for_this_notification.find(notification_records[i + 1])):
19231923
for actions in action_strings[0].split('\n'):
19241924
notification_actions += re.findall(r"\".*?\"", actions)
19251925

adbe/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ def _using_python2():
360360

361361

362362
def _fail_with_python2_warning():
363-
msg = ('You are using Python 2\nADB-enhanced no longer supports Python 2.\n' +
364-
'Install Python 3 and then re-install this tool using\n' +
365-
'\"sudo pip uninstall adb-enhanced && sudo pip3 install adb-enhanced\"')
363+
msg = ('You are using Python 2\nADB-enhanced no longer supports Python 2.\n'
364+
+ 'Install Python 3 and then re-install this tool using\n'
365+
+ '\"sudo pip uninstall adb-enhanced && sudo pip3 install adb-enhanced\"')
366366
print_error_and_exit(msg)
367367

368368

tests/adbe_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import functools
2+
import os
23
import re
34
import subprocess
45
import sys
5-
import os
66
import time
7+
78
import pytest
89

910
_SETTINGS_CMD_VERSION = 19

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
34
def pytest_addoption(parser):
45
parser.addoption("--testpythoninstallation", action="store")
56

0 commit comments

Comments
 (0)