From 30fd28d9f0898dfd0579a665696daaa501ab71a7 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Thu, 22 Dec 2022 11:56:01 +0000 Subject: [PATCH] scripts: compliance: move isfile() check in get_files() Git normally only works on files, but can include directories if there's any submodule in the repository. This is currently checked in filter_py(), move the check into get_files() so it does not have to be copied around. Signed-off-by: Fabio Baltieri --- scripts/ci/check_compliance.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 1e29e0bc32..94f018dcc9 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -59,6 +59,10 @@ def get_files(filter=None, paths=None): paths_arg = ('--', *paths) if paths else () out = git('diff', '--name-only', *filter_arg, COMMIT_RANGE, *paths_arg) files = out.splitlines() + for file in list(files): + if not os.path.isfile(os.path.join(GIT_TOP, file)): + # Drop submodule directories from the list. + files.remove(file) return files class FmtdFailure(Failure): @@ -856,13 +860,8 @@ def filter_py(root, fnames): # Uses the python-magic library, so that we can detect Python # files that don't end in .py as well. python-magic is a frontend # to libmagic, which is also used by 'file'. - # - # The extra os.path.isfile() is necessary because git includes - # submodule directories in its output. - return [fname for fname in fnames - if os.path.isfile(os.path.join(root, fname)) and - (fname.endswith(".py") or + if (fname.endswith(".py") or magic.from_file(os.path.join(root, fname), mime=True) == "text/x-python")]