forked from aws-samples/s3pathlib-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_code.py
More file actions
51 lines (42 loc) · 1.16 KB
/
Copy pathcount_code.py
File metadata and controls
51 lines (42 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
import typing as T
import json
import subprocess
from pathlib_mate import Path
dir_project_root = Path.dir_here(__file__).absolute()
def cloc(path: T.Union[Path, T.List[Path]]) -> dict:
if isinstance(path, list):
cloc_list_file.write_text("\n".join([str(p) for p in path]))
args = [
"cloc",
f"--list-file={cloc_list_file}",
"--json",
]
else:
args = [
"cloc",
f"{path}",
"--json",
]
result = subprocess.run(args, capture_output=True)
data = json.loads(result.stdout.decode("utf-8"))
del data["header"]
return data
def count_code(title, path: T.Union[Path, T.List[Path]]):
data = cloc(path)
print(f"-------------------- {title} --------------------")
print(json.dumps(data, indent=4))
if __name__ == "__main__":
cloc_list_file = dir_project_root.joinpath(".cloc-list-file")
count_code(
"source code",
[
dir_project_root.joinpath("s3pathlib"),
],
)
count_code(
"test code",
[
dir_project_root.joinpath("tests"),
],
)