Last active
January 16, 2019 15:23
-
-
Save tweakimp/2f41ba8b5ce863b8c17b1d388657bc94 to your computer and use it in GitHub Desktop.
code statistics
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 | |
total_code_lines = 0 | |
total_blank_lines = 0 | |
total_comment_lines = 0 | |
total_functions = 0 | |
total_async_functions = 0 | |
total_classes = 0 | |
file_count = 0 | |
path = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), "name"))) # "name" for project folder name | |
include = ["name", "\\name\\"] # "name" for filename, "\\name\\" for folders | |
for filename in glob.glob(f"{path}/**/*.py", recursive=True): | |
if any([string in filename for string in include]): | |
file_count += 1 | |
with open(filename) as file: | |
for line in file: | |
# Count code occurences | |
if "async " in line: | |
total_async_functions += 1 | |
elif "def " in line: | |
total_functions += 1 | |
elif "class " in line: | |
total_classes += 1 | |
# Count kind of line | |
if "#" in line or '"""' in line: | |
total_comment_lines += 1 | |
elif line.strip(): | |
total_code_lines += 1 | |
else: | |
total_blank_lines += 1 | |
all_lines = total_code_lines + total_blank_lines + total_comment_lines | |
print(f"{'Files:':<16}{file_count:>5}") | |
print(f"{'Lines:':<16}{all_lines:>5}") | |
print(f"{'Code Lines:':<16}{total_code_lines:>5} ({round(total_code_lines*100 / all_lines):>2}%)") | |
print(f"{'Comments:':<16}{total_comment_lines:>5} ({round(total_comment_lines*100 / all_lines):>2}%)") | |
print(f"{'Blank Lines:':<16}{total_blank_lines:>5} ({round(total_blank_lines*100 / all_lines):>2}%)") | |
print(f"{'Classes:':<16}{total_classes:>5}") | |
print(f"{'Functions:':<16}{total_functions:>5}") | |
print(f"{'Async Functions:':<16}{total_async_functions:>5}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment