Skip to content

Commit

Permalink
feat: add count.py because LOC is cool
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelmis committed Sep 20, 2022
1 parent 1058e81 commit e74c84c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pathlib import Path
from typing import Union, List


def count_lines(directory: Union[str, List[str]]):
"""Count Python LOC in a given directory."""
if isinstance(directory, str):
directories = [directory]
else:
directories = directory

total_lines: int = 0
print("{:>10} |{:>10} | {:<20}".format("ADDED", "TOTAL", "FILE"))
print("{:->11}|{:->11}|{:->20}".format("", "", ""))
for directory in directories:
for path in Path(directory).rglob("*.py"):
with open(path.absolute(), "r") as f:
newlines = f.readlines()
newlines = len(newlines)
total_lines += newlines
print(
"{:>10} |{:>10} | {:<20}".format(newlines, total_lines, str(path))
)


count_lines(["./suggestions", "./tests"])

0 comments on commit e74c84c

Please sign in to comment.