Skip to content

Instantly share code, notes, and snippets.

@bblay
Created March 21, 2022 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bblay/00dd15a8a0bd82f453ff1912b8221707 to your computer and use it in GitHub Desktop.
Save bblay/00dd15a8a0bd82f453ff1912b8221707 to your computer and use it in GitHub Desktop.
import glob
import os
from argparse import ArgumentParser
import matplotlib.pyplot as plt
if __name__ == '__main__':
arg_parser = ArgumentParser(description='produce a line length histogram for a source folder')
arg_parser.add_argument('source')
args = arg_parser.parse_args()
line_lengths = []
for path in glob.glob(os.path.join(args.source, '**'), recursive=True):
if path.endswith('.py'):
line_lengths.extend([len(line) for line in open(path)])
above_80 = len(list(filter(lambda i: i>80, line_lengths)))
above_100 = len(list(filter(lambda i: i>100, line_lengths)))
plt.hist(line_lengths, bins=range(0, 150, 10))
plt.title(f'line lengths in {args.source}\n{above_80} > 80, {above_100} > 100')
plt.savefig(os.path.join(args.source, 'lin_lengths.png'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment