Skip to content

Commit

Permalink
checks: use linguist to detect file types
Browse files Browse the repository at this point in the history
This commit also allows to skip the generated files checks by adding the
file to the .gitattributes file

Signed-off-by: Alessandro Comodi <[email protected]>
  • Loading branch information
acomodi committed May 21, 2021
1 parent fab6b84 commit e62d888
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Linguist - vendored override

third_party/* linguist-vendored

# Linguist - generated override

checks/tests/license/test-missing-spdx-generated.v linguist-generated
10 changes: 10 additions & 0 deletions checks/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
ca-certificates \
git \
make \
cmake \
pkg-config \
libicu-dev \
zlib1g-dev \
libcurl4-openssl-dev \
ruby-dev \
libssl-dev \
build-essential \
&& gem install github-linguist \
&& apt-get autoclean && apt-get clean && apt-get -y autoremove \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*
Expand Down
15 changes: 13 additions & 2 deletions checks/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import re
import sys
import tempfile
import subprocess
import json


__path__ = pathlib.Path(__file__).resolve().parent
Expand Down Expand Up @@ -417,6 +419,15 @@ def main(args):
logging.debug('Starting search in: %s', root_dir)

errors = {}

json_data = subprocess.check_output("github-linguist --json", shell=True).decode('utf8')
files_data = json.loads(json_data)

ftypes = {}
for ftype, fpaths in files_data.items():
for fpath in fpaths:
ftypes[fpath] = ftype

for root, dirs, files in os.walk(root_dir):
rpath = pathlib.Path(root).resolve()
fdebug(rpath, 'Searching')
Expand Down Expand Up @@ -463,9 +474,9 @@ def main(args):
fwarn(fpath, 'Skipping nonfile')
continue

ftype = detect_file_type(fpath)
ftype = ftypes.get(os.path.relpath(fpath, root_dir), None)
if ftype is None:
finfo(fpath, 'Skipping unknown file type')
finfo(fpath, 'Skipping generated or unknown file')
continue

ferrors = []
Expand Down
5 changes: 5 additions & 0 deletions checks/tests/license/test-missing-spdx-generated.v

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e62d888

Please sign in to comment.