Skip to content

Commit 51bc1e5

Browse files
authored
chore: merge count into master (#2897)
* Create count_sourcelines.py * fix: fix source lines script
1 parent 8f903aa commit 51bc1e5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

count_sourcelines.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# prints recursive count of lines of python source code from current directory
2+
# includes an ignore_list. also prints total sloc
3+
4+
import os
5+
cur_path = os.getcwd()
6+
ignore_set = set(["__init__.py", "count_sourcelines.py"])
7+
8+
loc_list = []
9+
10+
for py_dir, _, py_files in os.walk(cur_path):
11+
for py_file in py_files:
12+
if py_file.endswith(".py") and py_file not in ignore_set:
13+
total_path = os.path.join(py_dir, py_file)
14+
try:
15+
# Open the file with UTF-8 encoding
16+
with open(total_path, "r", encoding="utf-8") as file:
17+
loc_list.append((len(file.read().splitlines()),
18+
total_path.split(cur_path)[1]))
19+
except UnicodeDecodeError as e:
20+
print(f"Skipping file {total_path} due to encoding error: {e}")
21+
22+
for line_number_count, filename in loc_list:
23+
print("%05d lines in %s" % (line_number_count, filename))
24+
25+
print("\nTotal: %s lines (%s)" % (sum([x[0] for x in loc_list]), cur_path))

0 commit comments

Comments
 (0)