Download s3pathlib/count_code.py from Dorothydu/gitrepo_top_sample_50: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/s3pathlib/count_code.py
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_top_sample_50/s3pathlib/count_code.py
-
curl -L -o count_code.py https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/s3pathlib/count_code.py
1.19 kB
| # -*- 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"), | |
| ], | |
| ) | |