Simplify count-lines-of-code

This commit is contained in:
Kovid Goyal
2023-09-24 15:44:40 +05:30
parent 45bfeeef21
commit f16e9500f1

View File

@@ -2,20 +2,16 @@
import subprocess import subprocess
ignored = [] ls_files = subprocess.check_output([ 'git', 'ls-files']).decode('utf-8')
for line in subprocess.check_output(['git', 'status', '--ignored', '--porcelain']).decode().splitlines(): all_files = set(ls_files.splitlines())
if line.startswith('!! '): all_files.discard('')
ignored.append(line[3:])
files_to_exclude = '\n'.join(ignored)
cp = subprocess.run(['git', 'check-attr', 'linguist-generated', '--stdin'], cp = subprocess.run(['git', 'check-attr', 'linguist-generated', '--stdin'],
check=True, stdout=subprocess.PIPE, input=subprocess.check_output([ 'git', 'ls-files'])) check=True, stdout=subprocess.PIPE, input='\n'.join(all_files).encode('utf-8'))
for line in cp.stdout.decode().splitlines(): for line in cp.stdout.decode().splitlines():
if line.endswith(' true'): if line.endswith(' true'):
files_to_exclude += '\n' + line.split(':')[0] fname = line.split(':', 1)[0]
all_files.discard(fname)
p = subprocess.Popen([ all_files -= {'nerd-fonts-glyphs.txt', 'rowcolumn-diacritics.txt'}
'cloc', '--exclude-list-file', '/dev/stdin', 'kitty', 'kittens', 'tools', 'kitty_tests', 'docs', cp = subprocess.run(['cloc', '--list-file', '-'], input='\n'.join(all_files).encode())
], stdin=subprocess.PIPE) raise SystemExit(cp.returncode)
p.communicate(files_to_exclude.encode('utf-8'))
raise SystemExit(p.wait())