test/pylint: select files via git-ls-tree
We currently run pylint on all files we find in the checkout. This is particularly annoying when we have osbuild-stores in the checkout, which then contain lots of python files in their stored trees. Change the pylint test to use `git ls-tree` to find all files in the index and then only run pylint against the subset that we are interested in.
This commit is contained in:
parent
faaa6c1a6b
commit
4a6ee7081b
1 changed files with 29 additions and 9 deletions
|
|
@ -2,6 +2,7 @@
|
|||
# Run `pylint` on all python sources.
|
||||
#
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
|
|
@ -17,13 +18,32 @@ class TestPylint(test.TestBase, unittest.TestCase):
|
|||
# modules we have.
|
||||
#
|
||||
|
||||
path = self.locate_test_checkout()
|
||||
checkout = self.locate_test_checkout()
|
||||
|
||||
subprocess.run(f"find {path} -type f -name '*.py' | xargs pylint",
|
||||
shell=True, check=True)
|
||||
subprocess.run("pylint"
|
||||
+ f" {path}/assemblers/*"
|
||||
+ f" {path}/runners/*"
|
||||
+ f" {path}/sources/*"
|
||||
+ f" {path}/stages/*",
|
||||
shell=True, check=True)
|
||||
# Fetch list of checked-in files from git.
|
||||
cwd = os.getcwd()
|
||||
os.chdir(checkout)
|
||||
files = subprocess.check_output(
|
||||
[
|
||||
"git",
|
||||
"ls-tree",
|
||||
"-rz",
|
||||
"--full-tree",
|
||||
"--name-only",
|
||||
"HEAD",
|
||||
]
|
||||
).decode()
|
||||
os.chdir(cwd)
|
||||
|
||||
# File list is separated by NULs, so split into array.
|
||||
files = files.split('\x00')
|
||||
|
||||
# Filter out all our python files (i.e., all modules and files ending in *.py)
|
||||
modules = ("assemblers/", "runners/", "sources/", "stages/")
|
||||
files = filter(lambda p: p.endswith(".py") or p.startswith(modules), files)
|
||||
|
||||
# Append the checkout-path so all paths are absolute.
|
||||
files = map(lambda p: os.path.join(checkout, p), files)
|
||||
|
||||
# Run pylint on all files.
|
||||
subprocess.run(["pylint"] + list(files), check=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue