CI: deviceinfo: add more strict linting (MR 3454)
pmbootstrap and postmarketos-mkinitfs don't support multiple lines in these files, and the complexity is not worth implementing there. Let's keep the format dead-simple and enforce it across all files. While at it, enforce that comments stat with '# ' and make sure each line has quotations (we had some without). Related: discussion in postmarketos-mkinitfs MR 21
This commit is contained in:
parent
d28d2e4a96
commit
ff24bce15d
1 changed files with 21 additions and 3 deletions
|
@ -3,9 +3,10 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import pytest
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import pytest
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
import add_pmbootstrap_to_import_path
|
import add_pmbootstrap_to_import_path
|
||||||
import pmb.parse
|
import pmb.parse
|
||||||
|
@ -31,6 +32,8 @@ def test_deviceinfo(args):
|
||||||
# Iterate over all devices
|
# Iterate over all devices
|
||||||
last_exception = None
|
last_exception = None
|
||||||
count = 0
|
count = 0
|
||||||
|
pattern = re.compile("^deviceinfo_[a-zA-Z0-9_]*=\".*\"$")
|
||||||
|
|
||||||
for folder in glob.glob(args.aports + "/device/*/device-*"):
|
for folder in glob.glob(args.aports + "/device/*/device-*"):
|
||||||
device = folder[len(args.aports):].split("-", 1)[1]
|
device = folder[len(args.aports):].split("-", 1)[1]
|
||||||
|
|
||||||
|
@ -39,11 +42,26 @@ def test_deviceinfo(args):
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# variable can not be empty
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
# Require space after # for comments
|
||||||
|
if line.startswith("#") and not line.startswith("# "):
|
||||||
|
raise RuntimeError("Comment style: please change '#' to"
|
||||||
|
f" '# ': {line}")
|
||||||
|
|
||||||
|
# Skip empty lines and comments
|
||||||
|
if not line or line.startswith("# "):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Variable can not be empty
|
||||||
if '=""' in line:
|
if '=""' in line:
|
||||||
raise RuntimeError("Please remove the empty variable: " + line)
|
raise RuntimeError("Please remove the empty variable: " + line)
|
||||||
|
|
||||||
|
# Check line against regex (can't use multiple lines etc.)
|
||||||
|
if not pattern.match(line) or line.endswith("\\\""):
|
||||||
|
raise RuntimeError("Line looks invalid, maybe missing"
|
||||||
|
" quotes/multi-line string/comment next"
|
||||||
|
f" to line instead of above? {line}")
|
||||||
|
|
||||||
# Successful deviceinfo parsing / obsolete options
|
# Successful deviceinfo parsing / obsolete options
|
||||||
info = pmb.parse.deviceinfo(args, device)
|
info = pmb.parse.deviceinfo(args, device)
|
||||||
deviceinfo_obsolete(info)
|
deviceinfo_obsolete(info)
|
||||||
|
|
Loading…
Reference in a new issue