mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-08 08:30:47 -09:00
Makefile: merge check-flake8 into check-package
Teach check-package to detect python files by type and check them using flake8. Do not use subprocess to call 'python3 -m flake8' in order to avoid too many spawned shells, which in its turn would slow down the check for multiple files. (make check-package takes twice the time using a shell for each flake8 call, when compared of importing the main application) Expand the runtime test and the unit tests for check-package. Remove check-flake8 from the makefile and also from the GitLab CI because the exact same checks become part of check-package. Suggested-by: Arnout Vandecappelle <arnout@mind.be> Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com> [Arnout: add a comment to x-python to explain its purpose] Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
This commit is contained in:
committed by
Arnout Vandecappelle
parent
60fdaf56fe
commit
9df6503ed0
@@ -14,6 +14,7 @@ import checkpackagelib.lib_config
|
||||
import checkpackagelib.lib_hash
|
||||
import checkpackagelib.lib_mk
|
||||
import checkpackagelib.lib_patch
|
||||
import checkpackagelib.lib_python
|
||||
import checkpackagelib.lib_shellscript
|
||||
import checkpackagelib.lib_sysv
|
||||
|
||||
@@ -100,6 +101,8 @@ def get_lib_from_filetype(fname):
|
||||
filetype = get_filetype(fname)
|
||||
if filetype == "text/x-shellscript":
|
||||
return checkpackagelib.lib_shellscript
|
||||
if filetype in ["text/x-python", "text/x-script.python"]:
|
||||
return checkpackagelib.lib_python
|
||||
return None
|
||||
|
||||
|
||||
|
||||
1
utils/checkpackagelib/lib_python.py
Normal file
1
utils/checkpackagelib/lib_python.py
Normal file
@@ -0,0 +1 @@
|
||||
from checkpackagelib.tool import Flake8 # noqa: F401
|
||||
@@ -66,6 +66,34 @@ def test_NotExecutable_hint(testname, hint, filename, permissions, string, expec
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Flake8 = [
|
||||
('empty',
|
||||
'empty.py',
|
||||
'',
|
||||
[]),
|
||||
('W391',
|
||||
'blank-line.py',
|
||||
'\n',
|
||||
["dir/blank-line.py:0: run 'flake8' and fix the warnings",
|
||||
"dir/blank-line.py:1:1: W391 blank line at end of file"]),
|
||||
('more than one warning',
|
||||
'file',
|
||||
'import os\n'
|
||||
'import re\n'
|
||||
'\n',
|
||||
["dir/file:0: run 'flake8' and fix the warnings",
|
||||
"dir/file:1:1: F401 'os' imported but unused\n"
|
||||
"dir/file:2:1: F401 're' imported but unused\n"
|
||||
'dir/file:3:1: W391 blank line at end of file']),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Flake8)
|
||||
def test_Flake8(testname, filename, string, expected):
|
||||
warnings = check_file(m.Flake8, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Shellcheck = [
|
||||
('missing shebang',
|
||||
'empty.sh',
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import flake8.main.application
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
from checkpackagelib.base import _Tool
|
||||
|
||||
|
||||
@@ -14,6 +16,19 @@ class NotExecutable(_Tool):
|
||||
return ["{}:0: This file does not need to be executable{}".format(self.filename, self.hint())]
|
||||
|
||||
|
||||
class Flake8(_Tool):
|
||||
def run(self):
|
||||
with tempfile.NamedTemporaryFile() as output:
|
||||
app = flake8.main.application.Application()
|
||||
app.run(['--output-file={}'.format(output.name), self.filename])
|
||||
stdout = output.readlines()
|
||||
processed_output = [str(line.decode().rstrip()) for line in stdout if line]
|
||||
if len(stdout) == 0:
|
||||
return
|
||||
return ["{}:0: run 'flake8' and fix the warnings".format(self.filename),
|
||||
'\n'.join(processed_output)]
|
||||
|
||||
|
||||
class Shellcheck(_Tool):
|
||||
def run(self):
|
||||
cmd = ['shellcheck', self.filename]
|
||||
|
||||
Reference in New Issue
Block a user