Created
March 21, 2022 14:33
-
-
Save bblay/00dd15a8a0bd82f453ff1912b8221707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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