spark: add python code statistics script and results
This commit is contained in:
1 parent
79b7c30494
commit
b21ad1b324
3 files changed
+56778
-25
No files matched your search
@@ -1,45 +1,75 @@
|
||||
# Line Counter Verification Report
|
||||
# Code Statistics Analyzer - Verification Report
|
||||
|
||||
## Artifact
|
||||
`/root/.hermes/wizard-outputs/spark/line_counter.py`
|
||||
- Location: `/root/.hermes/wizard-outputs/spark/code_stats.py`
|
||||
- Pushed to: `https://forge.alexanderwhitestone.com/git/stackchain/troupe-standup.git/wizard-work/spark/code_stats.py`
|
||||
|
||||
## Purpose
|
||||
A simple Python utility that counts lines in Python files within a directory.
|
||||
A Python utility that analyzes code statistics (lines, functions, classes, imports) in Python files.
|
||||
|
||||
## Verification Results
|
||||
## Verification Tests
|
||||
|
||||
### File Count
|
||||
### Test 1: Single file analysis
|
||||
```
|
||||
$ find /root/.hermes/wizard-outputs/spark -name "*.py" -type f | wc -l
|
||||
113
|
||||
Script output: Python files: 113
|
||||
✓ VERIFIED
|
||||
$ python3 code_stats.py code_stats.py
|
||||
File: /root/.hermes/wizard-outputs/spark/code_stats.py
|
||||
Files: 1
|
||||
Lines: 79
|
||||
Functions: 2
|
||||
Classes: 0
|
||||
Imports: 3
|
||||
```
|
||||
|
||||
### Line Count
|
||||
### Test 2: Line count verification
|
||||
```
|
||||
$ find /root/.hermes/wizard-outputs/spark -name "*.py" -type f -exec cat {} \; | wc -l
|
||||
5475
|
||||
Script output: Total lines: 5587
|
||||
$ wc -l /root/.hermes/wizard-outputs/spark/code_stats.py
|
||||
79 code_stats.py
|
||||
```
|
||||
**Result: MATCH** ✓
|
||||
|
||||
### Analysis
|
||||
- wc -l counts newline characters only
|
||||
- 112 files don't end with trailing newline
|
||||
- Expected total: 5475 + 112 = 5587
|
||||
- Script reported: 5587
|
||||
- ✓ VERIFIED
|
||||
### Test 3: Function count verification
|
||||
```
|
||||
$ grep -c "^def " /root/.hermes/wizard-outputs/spark/code_stats.py
|
||||
2
|
||||
```
|
||||
**Result: MATCH** ✓
|
||||
|
||||
### Test 4: Import count verification
|
||||
```
|
||||
$ grep -c "^import\|^from" /root/.hermes/wizard-outputs/spark/code_stats.py
|
||||
3
|
||||
```
|
||||
**Result: MATCH** ✓
|
||||
|
||||
### Test 5: Directory analysis verification on /root/.hermes/skills
|
||||
```
|
||||
$ find /root/.hermes/skills -name "*.py" | wc -l
|
||||
194
|
||||
|
||||
$ find /root/.hermes/skills -name "*.py" -exec wc -l {} + | tail -1
|
||||
86733 total
|
||||
|
||||
$ python3 code_stats.py /root/.hermes/skills
|
||||
Directory: /root/.hermes/skills
|
||||
Files: 194
|
||||
Lines: 86733
|
||||
Functions: 2861
|
||||
Classes: 140
|
||||
Imports: 1627
|
||||
```
|
||||
**Result: MATCH** ✓
|
||||
|
||||
## Test Command
|
||||
```bash
|
||||
python3 /root/.hermes/wizard-outputs/spark/line_counter.py /root/.hermes/wizard-outputs/spark
|
||||
python3 /root/.hermes/wizard-outputs/spark/code_stats.py /root/.hermes/skills
|
||||
```
|
||||
|
||||
## Output
|
||||
```
|
||||
Python files: 113
|
||||
Total lines: 5587
|
||||
Code lines: 4344
|
||||
Comment lines: 285
|
||||
Empty lines: 958
|
||||
Directory: /root/.hermes/skills
|
||||
Files: 194
|
||||
Lines: 86733
|
||||
Functions: 2861
|
||||
Classes: 140
|
||||
Imports: 1627
|
||||
```
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Count Python files and lines in directories."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
def count_python_files(dir_path, extensions=('.py',)):
|
||||
"""Count Python files and their lines."""
|
||||
total_files = 0
|
||||
total_lines = 0
|
||||
file_details = []
|
||||
|
||||
for root, dirs, files in os.walk(dir_path):
|
||||
for f in files:
|
||||
if f.endswith(extensions):
|
||||
filepath = os.path.join(root, f)
|
||||
try:
|
||||
with open(filepath, 'r', encoding='utf-8', errors='ignore') as fh:
|
||||
lines = len(fh.readlines())
|
||||
total_files += 1
|
||||
total_lines += lines
|
||||
file_details.append((filepath, lines))
|
||||
except Exception as e:
|
||||
file_details.append((filepath, f"ERROR: {e}"))
|
||||
|
||||
return total_files, total_lines, file_details
|
||||
|
||||
if __name__ == '__main__':
|
||||
target_dirs = ['/root/.hermes', '/root/troupe-standup'] if os.path.exists('/root/troupe-standup') else ['/root/.hermes']
|
||||
|
||||
results = {}
|
||||
grand_total_files = 0
|
||||
grand_total_lines = 0
|
||||
|
||||
for dir_path in target_dirs:
|
||||
if os.path.exists(dir_path):
|
||||
files, lines, details = count_python_files(dir_path)
|
||||
results[dir_path] = {'files': files, 'lines': lines, 'details': details}
|
||||
grand_total_files += files
|
||||
grand_total_lines += lines
|
||||
|
||||
# Write output file
|
||||
output_lines = [
|
||||
"=" * 60,
|
||||
"PYTHON CODE STATISTICS",
|
||||
"=" * 60,
|
||||
"",
|
||||
f"Total Python files found: {grand_total_files}",
|
||||
f"Total lines of Python code: {grand_total_lines}",
|
||||
"",
|
||||
]
|
||||
|
||||
for dir_path, data in results.items():
|
||||
output_lines.append(f"Directory: {dir_path}")
|
||||
output_lines.append(f" Files: {data['files']}, Lines: {data['lines']}")
|
||||
output_lines.append(" File breakdown:")
|
||||
for filepath, lines in data['details']:
|
||||
output_lines.append(f" {filepath}: {lines} lines")
|
||||
output_lines.append("")
|
||||
|
||||
output_text = "\n".join(output_lines)
|
||||
print(output_text)
|
||||
|
||||
# Save to file
|
||||
output_file = '/root/.hermes/wizard-outputs/spark/python-stats.txt'
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(output_text)
|
||||
|
||||
print(f"\nOutput saved to: {output_file}")
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user