Skip to content

Commit 766605f

Browse files
committed
Configure pylint and improve code quality
1 parent 1bc02cc commit 766605f

File tree

7 files changed

+31
-23
lines changed

7 files changed

+31
-23
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
pip --cache-dir=.pip install pylint
2525
pip --cache-dir=.pip install -r requirements.txt
2626
- name: Run Pylint
27-
run: pylint tests 2>&1 | tee pylint.txt
27+
run: pylint startup tests f3.py kernel_remover.py maintenance.py modem.py utils.py 2>&1 | tee pylint.txt
2828
working-directory: ${{ github.workspace }}
2929
- name: Upload results
3030
uses: actions/upload-artifact@v2

kernel_remover.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def main():
1212
running = os.uname().release
1313

14-
process = subprocess.run(["dpkg", "--list", "linux-image-*"], stdout=subprocess.PIPE)
14+
process = subprocess.run(["dpkg", "--list", "linux-image-*"], stdout=subprocess.PIPE, check=True)
1515
dpkg_output = process.stdout.decode("utf-8")
1616

1717
kernels = []
@@ -65,11 +65,11 @@ def main():
6565
continue_str = input() # nosec
6666
if continue_str == "y":
6767
print("Removing old kernels")
68-
subprocess.run(["apt-get", "purge"] + purge_these)
68+
subprocess.run(["apt-get", "purge"] + purge_these, check=True)
6969
print("Old kernels removed. Updating.")
70-
subprocess.run(["apt-get", "update"])
71-
subprocess.run(["apt-get", "dist-upgrade"])
72-
subprocess.run(["apt-get", "autoremove"])
70+
subprocess.run(["apt-get", "update"], check=True)
71+
subprocess.run(["apt-get", "dist-upgrade"], check=True)
72+
subprocess.run(["apt-get", "autoremove"], check=True)
7373
print("Update complete")
7474

7575

maintenance.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ def apt() -> None:
165165
apt_ret = run(["apt-get", "dist-upgrade", "-y"], check=False)
166166
if apt_ret == 0:
167167
break
168-
elif apt_ret == 100:
169-
pass
170-
else:
168+
if apt_ret != 100:
171169
raise ValueError(f"Got unknown APT return code: {apt_ret}")
172170
print("Waiting for APT lock to be freed")
173171
time.sleep(APT_WAIT_TIME)
@@ -257,7 +255,7 @@ def main():
257255
parser.add_argument("--firefox", help="Deep-clean Firefox", action="store_true")
258256
parser.add_argument("--thunderbird", help="Deep-clean Thunderbird", action="store_true")
259257
args = parser.parse_args()
260-
logger.info(f"Args: {args}")
258+
logger.info("Args: %s", args)
261259

262260
if args.deep:
263261
print("Deep scan has been selected. Some processes may take a long time.")

modem.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919

2020
def read_pin(path: str) -> str:
21-
with open(path) as f:
22-
pin = f.read().rstrip()
21+
with open(path) as file:
22+
pin = file.read().rstrip()
2323
if not pin.isnumeric():
2424
raise ValueError("PIN should be numeric")
2525
return pin
@@ -38,8 +38,8 @@ def modem_number() -> int:
3838
modem_path = rows[row_ind].strip("\t").split()[0]
3939
try:
4040
number = int(modem_path.split("/")[-1])
41-
except ValueError:
42-
raise ValueError("Invalid modem path")
41+
except ValueError as e:
42+
raise ValueError("Invalid modem path") from e
4343
return number
4444

4545

@@ -116,7 +116,8 @@ def send_pin(modem: int, pin: str) -> None:
116116

117117
def connect(bearer: int):
118118
subprocess.run(
119-
["mmcli", "-b", str(bearer), "--connect"]
119+
["mmcli", "-b", str(bearer), "--connect"],
120+
check=True
120121
)
121122

122123

pylintrc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
extension-pkg-whitelist=
77

88
# Specify a score threshold to be exceeded before program exits with error.
9-
fail-under=10.0
9+
fail-under=9
1010

1111
# Add files or directories to the blacklist. They should be base names, not
1212
# paths.
@@ -138,7 +138,12 @@ disable=print-statement,
138138
xreadlines-attribute,
139139
deprecated-sys-function,
140140
exception-escape,
141-
comprehension-escape
141+
comprehension-escape,
142+
# Custom additions
143+
missing-class-docstring,
144+
missing-function-docstring,
145+
missing-module-docstring,
146+
too-few-public-methods
142147

143148
# Enable the message, report, category or checker with the given id(s). You can
144149
# either give multiple identifier separated by comma (,) or put this option
@@ -211,7 +216,7 @@ indent-after-paren=4
211216
indent-string=' '
212217

213218
# Maximum number of characters on a single line.
214-
max-line-length=100
219+
max-line-length=120
215220

216221
# Maximum number of lines in a module.
217222
max-module-lines=1000
@@ -407,7 +412,9 @@ good-names=i,
407412
k,
408413
ex,
409414
Run,
410-
_
415+
_,
416+
# Custom additions
417+
e
411418

412419
# Good variable names regexes, separated by a comma. If names match any regex,
413420
# they will always be accepted

startup/agx-startup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
To enable this script, run startup-enabler.sh
88
"""
9+
# pylint: disable=invalid-name
910

1011
import enum
1112
import glob
@@ -232,7 +233,7 @@ class ALPM_LevelOptions(enum.Enum):
232233
"/sys/bus/pci/devices/0000:20:00.2",
233234
"/sys/bus/pci/devices/0000:00:08.0",
234235
"/sys/bus/pci/devices/0000:60:00.2",
235-
236+
236237
# PCIe
237238
"/sys/bus/pci/devices/0000:40:07.0",
238239
"/sys/bus/pci/devices/0000:61:00.0",
@@ -469,7 +470,7 @@ def custom_commands() -> None:
469470
return
470471

471472
for command in CUSTOM_COMMANDS[board]:
472-
subprocess.run(command)
473+
subprocess.run(command, check=True)
473474

474475

475476
def disable_wakeups() -> None:
@@ -498,7 +499,7 @@ def hdparm() -> None:
498499
drive_path = os.path.join("/dev/disk/by-id", drive)
499500

500501
for param, value in params.items():
501-
subprocess.run(["hdparm", param, str(value), drive_path])
502+
subprocess.run(["hdparm", param, str(value), drive_path], check=True)
502503

503504

504505
def power_control() -> None:

utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ def run(
6767
:param check: whether to check the return code and raise an error accordingly
6868
:param get_output: whether to extract output to Python
6969
:param print_output: print command output to console
70+
:param stderr: whether to capture stderr output as well
7071
:return: return code of the command
7172
"""
72-
logger.info(f"Running {command}")
73+
logger.info("Running %s", command)
7374
kwargs = {}
7475
if stderr:
7576
kwargs["stderr"] = sp.PIPE

0 commit comments

Comments
 (0)