Count source files up to 4 dirs deep, excluding vendor/node_modules/etc.
(repo_dir)
| 725 | |
| 726 | |
| 727 | def count_source_files(repo_dir): |
| 728 | """Count source files up to 4 dirs deep, excluding vendor/node_modules/etc.""" |
| 729 | src_count = 0 |
| 730 | exts = {".go", ".py", ".java", ".kt", ".rs", ".ts", ".js", ".scala", |
| 731 | ".c", ".h", ".agc"} |
| 732 | excluded = {"vendor", "node_modules", ".git", "quality"} |
| 733 | |
| 734 | def walk(base, current_depth, max_depth): |
| 735 | nonlocal src_count |
| 736 | try: |
| 737 | for entry in os.scandir(base): |
| 738 | name = entry.name |
| 739 | if entry.is_dir(follow_symlinks=False): |
| 740 | if current_depth < max_depth and name not in excluded: |
| 741 | walk(entry.path, current_depth + 1, max_depth) |
| 742 | elif entry.is_file(follow_symlinks=False): |
| 743 | dot = name.rfind(".") |
| 744 | if dot >= 0 and name[dot:] in exts: |
| 745 | src_count += 1 |
| 746 | except (OSError, PermissionError): |
| 747 | pass |
| 748 | |
| 749 | walk(str(repo_dir), 1, 4) |
| 750 | return src_count |
| 751 | |
| 752 | |
| 753 | # --- Section checks --- |
no test coverage detected